Skip to content

fix(collab): two files open in one browser no longer mix - #259

Merged
ssowonny merged 1 commit into
mainfrom
fix/collab-broadcastchannel-crosstalk
Sep 23, 2026
Merged

ssowonny merged 1 commit into
mainfrom
fix/collab-broadcastchannel-crosstalk

Conversation

@ssowonny

Copy link
Copy Markdown
Contributor

TL;DR

  • Two different files open in two tabs of the same browser mixed into each other. Type in one, it appeared in the other.
  • y-websocket keys its cross-tab BroadcastChannel on serverUrl + "/" + roomname and nothing else. We passed "held" for every file, so every editor in one browser shared one channel and cross-applied Y.Doc updates.
  • Channel disabled (the hub is the single source of truth); room name now carries the path so it's keyed correctly regardless.
  • Gate verified both ways: fails on the old bundle with the exact symptom, passes with the fix.

The comment that was wrong was mine

It said the room argument was "decoration". That was true of the server — the hub derives the room from (project, path) after authorising the caller, and a caller who could name the room could join any project's document. It was not true of the browser, where the name is the entire identity of the document to the tab-to-tab channel. The comment now says both halves.

The test needed one specific thing to be honest

Two tabs in one BrowserContext. BroadcastChannel is per origin per profile; two Playwright contexts are two profiles and can't hear each other, so a test built on newContext() passes against the bug. The spec says so in its header, so the next person doesn't "fix" it into a vacuous one.

OLD bundle: ✘ text typed into alpha-….md appeared in beta-….md … two documents are sharing one channel
NEW bundle: ✓

Scope

One line of behaviour (disableBc: true + path-keyed room name), one spec, rebuilt static/. Nothing on the hub side.

🤖 Generated with Claude Code

y-websocket keys its cross-tab BroadcastChannel on serverUrl + "/" + roomname
and nothing else — the query params are not in it. The client passed one fixed
room name for every file with the path tucked into params, so every editor open
in the same browser shared one channel and applied each other's Y.Doc updates.
Two different files in two tabs mixed into each other.

The channel is disabled: the hub holds the document and is the one source of
truth, and a tab-to-tab side channel is a second path for the same bytes. The
room name carries the path anyway, so if the channel is ever re-enabled it is
keyed correctly.

The comment that said the room name was decoration was mine. It was decoration
to the server. It was the whole identity of the document to the browser.

Gate: two tabs in ONE context (BroadcastChannel is per profile, so two contexts
cannot reproduce it), two files, type in one, assert the other is untouched.
Run both ways: against the previous bundle it fails with "text typed into
alpha appeared in beta … two documents are sharing one channel"; with the fix
it passes.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@ssowonny
ssowonny force-pushed the fix/collab-broadcastchannel-crosstalk branch from 1189743 to 3bd3631 Compare September 23, 2026 06:32
@ssowonny
ssowonny merged commit c364397 into main Sep 23, 2026
4 checks passed
@ssowonny
ssowonny deleted the fix/collab-broadcastchannel-crosstalk branch September 23, 2026 06:42
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.

1 participant