Skip to content

fix: add same-user multi-tab sync leadership#1119

Open
hweihwang wants to merge 3 commits intomainfrom
fix/same-user-multi-tab-sync-leader
Open

fix: add same-user multi-tab sync leadership#1119
hweihwang wants to merge 3 commits intomainfrom
fix/same-user-multi-tab-sync-leader

Conversation

@hweihwang
Copy link
Copy Markdown
Contributor

@hweihwang hweihwang commented Apr 1, 2026

Summary

  • adds useLocalSyncLeader and useLocalSyncLeaderStore to coordinate one browser-local execution leader per (fileId, userId) using a stable tabId, BroadcastChannel signaling, and a short localStorage lease/heartbeat. Election only activates for normal board sessions when both fileId and the JWT user id are available.
  • threads passive follower state into the whiteboard config so same-user non-leader tabs resolve to effective read-only mode. App.tsx and the mutation-capable hooks/components now treat follower tabs as local viewers instead of editors.
  • updates useSync so authoritative outbound work only runs when isDedicatedSyncer && isLocalLeader: scheduled sync execution, Nextcloud persistence, websocket scene/image sync, cursor and viewport emission, and unload or visibility flushes. When leadership is yielded, throttled work is cancelled before the final flush.
  • updates useCollaboration so only the local leader answers targeted scene bootstrap and image requests. Follower tabs still stay connected for room state, broadcasts, and remote updates, but they do not emit duplicate same-user sync or responder traffic.
  • adds regression coverage for local leader election, lease expiry failover, per-file and per-user isolation, follower sync suppression, and follower bootstrap/image responder suppression without changing the websocket server’s per-user syncer semantics.
image

Signed-off-by: Hoang Pham <hoangmaths96@gmail.com>
Signed-off-by: Hoang Pham <hoangmaths96@gmail.com>
Signed-off-by: Hoang Pham <hoangmaths96@gmail.com>
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