Skip to content

feat(shared): sync the app registry across tabs via BroadcastChannel (NEXT.md 3.5) - #131

Open
xcjs wants to merge 1 commit into
mainfrom
feat/multitab-sync
Open

xcjs wants to merge 1 commit into
mainfrom
feat/multitab-sync

Conversation

@xcjs

@xcjs xcjs commented Oct 8, 2026

Copy link
Copy Markdown
Owner

Closes #116

What

  • \�pp/features/shared/multitab-sync.ts: owns the \dominic:registry-sync\ BroadcastChannel. Registry mutations broadcast a plain-object snapshot via the existing \onRegistryChange\ API; receiving tabs apply it through the new \importApps()\ registry API, which persists and notifies exactly like a local mutation. Echoes are ignored by per-tab \instanceId; posting is wrapped so a broadcast failure can never break a mutation. Structured clone cannot serialize Vue reactive proxies — found by the new e2e — so snapshots are deep-stripped with \ oRaw\ + JSON round-trip.

  • egistry.ts: \importApps(metas)\ replaces in-memory registry state, persists, notifies (public API only; \�fs.ts\ untouched — Charles owns that seam in 1.1 Async VirtualFileSystem + driver registry (localStorage system, IndexedDB apps, migration) #105).
  • \�pp.vue: \startRegistrySync()\ once in \onMounted, SSR-safe.
  • ADR 0016 (accepted) records the decision and supersedes ADR 0003's deferral without editing that record; index updated.
  • \ ests/e2e/multitab-sync.spec.ts: install in tab A appears in tab B's taskbar without reload; uninstall in A removes it in B.

Scope match

Exactly the union of #116's ## Files\ as amended on the issue: app/features/shared/, app/features/apps/, app/features/os/** (read-only check), docs/adrs/, tests/e2e/, app/app.vue.

Not in scope

Window geometry/focus/workspace sync — per-tab shell state; NEXT.md 2.5 (#113) owns their persistence.

…(NEXT.md 3.5)

Adds multitab-sync.ts owning the dominic:registry-sync channel: registry
mutations broadcast a plain-object snapshot through the existing
onRegistryChange API, receiving tabs apply it via the new registry
importApps() (which persists + notifies like a local mutation). Echoes
are ignored by instance id; app source stays out of the channel (shared
localStorage VFS). Wired once in app.vue onMounted; SSR-safe.

Window geometry/focus/workspaces are per-tab shell state and are not
synced (NEXT.md 2.5 owns their persistence).

Recorded as ADR 0016 (accepted), superseding ADR 0003's deferral
without editing that record. e2e covers install and uninstall fan-out
across tabs.

Closes #116

@m-vawter m-vawter left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jumping in since the new spec is in my lane. I ran it merged into current main in a clean container. Your two specs pass, and a single install does show up in the other tab. But the sync never settles, and it loses installs:

  1. Echo loop. A tab ignores only its own instanceId. Importing a snapshot calls importApps(), which calls notify(). That fires this tab's onRegistryChange listener, which broadcasts the snapshot back. So two open tabs ping-pong forever. After one install with two tabs open, a third listener on dominic:registry-sync counted 1,863 messages in the first second and 6,914 after four, and every message rewrites registry.json. Fix: don't rebroadcast while applying a remote snapshot (a guard flag around importApps, or an origin argument on notify). Or broadcast only local mutations: registerApp and unregisterApp, not importApps.
  2. Installs get lost. Two tabs installing different apps at nearly the same moment ended with the tabs disagreeing and registry.json holding only one of the two, a different one on each run. Even two seconds apart, the persisted registry ended with just one app while both tabs still showed both, so a reload would drop one. The loop drives this: whichever snapshot arrives last overwrites. And because applyRemoteApps replaces the whole registry, a stale snapshot can delete an app the other tab just added. Its removed list is computed and then discarded (void removed). Merging by id with updatedAt, with deletes sent as explicit messages, would fix that.

Tests (my lane): please add two guards: the channel goes quiet after one install (for example, a listener counts no more than a few messages), and two tabs installing different apps both survive a reload. I'm happy to send probe code if useful.

Nits:

  • the comment says startRegistrySync returns a stop function, but it returns void;
  • the applyRemoteApps comment describes an entry-file check the code doesn't do.

P.S. The Phase 0 release notes are up as #133, a CHANGELOG.md. If you'd rather have a GitHub release, say so and I'll move them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3.5 Multi-tab sync via BroadcastChannel (ADR 0003 deferred item)

2 participants