Add synchronized new-tab live preview - #2025
Conversation
✅ Deploy Preview for mermaidjs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Why: The existing full-screen link captures a static URL snapshot, so the diagram does not update while its author continues editing. This prevents a practical second-window or dual-monitor preview workflow. What: Rename the action to Open Live Preview and keep each opened view tab synchronized with its editor. Preserve the snapshot as a standalone fallback and exclude the private preview session from analytics URLs. How: Create a per-editor UUID and exchange serialized state through a BroadcastChannel request/state protocol. The view tab requests current state when it connects and applies updates through the existing state pipeline. Cover URL handling, messaging, analytics privacy, and real two-tab synchronization with unit and Playwright tests.
2bfb691 to
ccf33b8
Compare
|
Hi @sidharthv96, I've made this improvement the the live editor. Could you please review it? |
|
Thanks for this — a synchronized preview is a real upgrade over the static snapshot, and the per-editor-tab channel scoping is the right call. A few behavior problems worth fixing before merge, then smaller cleanups. Behavior issues1. Pan/zoom sync is the right behavior for presenting — but the coordinates need mappingSyncing the presenter's pan/zoom into the preview is what we want: zoom into a region in the editor and the audience view follows. One caveat with the current mechanism: the raw svg-pan-zoom 2. Unthrottled broadcastsThe 3. The view tab should skip persistence entirelyEvery broadcast the preview applies goes through 4.
|
|
@toransahu non AI review, really useful feature, need some tweaks mentioned above, and we could add some polish as follow up. |
|
Thanks a lot for the review and feedback @sidharthv96. I'll work on them and let you know. |
📑 Summary
Why
The current full-screen action opens a static URL snapshot. Once it is open, continuing to edit the diagram does not update that tab, which makes a second-window or dual-monitor preview workflow impractical.
What
/viewtab synchronized with its originating editor.📏 Design Decisions
How
Each editor tab creates a UUID-scoped
BroadcastChanneland publishes the existing serialized application state. A newly opened view tab uses a request/state handshake to get the latest state immediately, then applies subsequent messages through the existing deserialization and state replacement pipeline.The live session is added as a query parameter before the snapshot hash, so the URL remains a valid shareable snapshot. If
BroadcastChannelis unsupported or the source editor is unavailable, the view still renders that snapshot rather than failing.🧪 Testing
pnpm test:unit --run src/lib/util/livePreview.test.ts src/lib/util/stats.test.tspnpm test:e2e tests/livePreview.spec.tspnpm checkpnpm buildpnpm lint📋 Tasks
developbranch