fix: Replace platform-wide broadcast_refresh with sync toast
Problem
Every time any account sync completed (triggered by a transaction add/update, a provider sync, a worker update, etc.), Family::SyncCompleteEvent#broadcast called family.broadcast_refresh.
This caused a full page reload for every connected family member, regardless of what they were currently doing. If a user was mid-form — e.g. adding a transaction, filling out import fields, editing a split — the page would silently reload and discard all their input.
broadcast_refresh was used because Current.user is nil in background jobs, making it impossible to render user-scoped HTML (net worth chart, balance sheet) server-side. Each client needed to re-request the page with their own session.
Fix
Instead of family.broadcast_refresh, Family::SyncCompleteEvent now appends a lightweight static toast to the existing #notification-tray via broadcast_append_to.
The toast contains no user-scoped data — it is plain static HTML — so the Current.user: nil constraint is no longer a problem. Each browser still re-requests the page on its own authenticated session, but only when it's safe to do so.
A new sync-toast Stimulus controller handles two cases:
| User state | Behaviour |
|---|---|
| Idle (no focused form) | Auto-reloads the page after 500 ms |
| Mid-form (form element focused) | Toast stays visible; user clicks "Refresh now" at their convenience |
The close button (×) lets the user dismiss the toast entirely if they don't want to refresh.
Files changed
app/models/family/sync_complete_event.rb— swapbroadcast_refresh→broadcast_append_toapp/views/shared/notifications/_sync_toast.html.erb— new toast partialapp/javascript/controllers/sync_toast_controller.js— new Stimulus controllerconfig/locales/defaults/en.yml—shared.sync_toast.*locale strings
Testing
- Open the app in two browser tabs.
- In one tab, start filling out the "Add transaction" form (do not submit).
- In the other tab (or via rails console), trigger a sync:
Account.first.sync_later - Expected: the first tab shows a "Your data has been updated — Refresh now" toast without reloading the page.
- Click "Refresh now" — page reloads with updated data.
- Repeat with the form tab idle (no focused input) — page should auto-reload after ~500 ms.
Summary by CodeRabbit
- New Features
- Added a sync toast notification that appears when data sync completes.
- The toast auto-refreshes the page after 2 seconds if you’re not actively editing forms or interacting with dialogs.
- You can manually refresh immediately or dismiss the toast via on-screen action buttons.