Skip to content

Remember the canvas viewport per document across net switches and reloads - #9510

Draft
kube wants to merge 1 commit into
claude/canvas-pixi-rendererfrom
claude/canvas-viewport-persistence
Draft

Remember the canvas viewport per document across net switches and reloads#9510
kube wants to merge 1 commit into
claude/canvas-pixi-rendererfrom
claude/canvas-viewport-persistence

Conversation

@kube

@kube kube commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

Before this PR, the canvas opened every net fitted to the screen. Switching to another net and back, or reloading the app, lost the position and zoom the user had set.

Remembers the viewport per net in the user settings. Both renderers start from the saved viewport when one exists and report their moves through one context, so a net reopens where it was left.

Links

Changes

  • CanvasViewportContext exposes savedViewport and rememberViewport

    CanvasViewportProvider sits inside UserSettingsProvider and keys everything by the current petriNetId.

  • Saves coalesce to one write 250 ms after the last move

    Pending saves flush when the document changes or the provider unmounts.

  • canvasViewports user setting keeps the most recently moved nets

    remember-canvas-viewport.ts caps the map at 50 nets, most recent first.
    Persisted with the other settings.

  • Both renderers read the saved viewport at mount and otherwise fit the net

    React Flow reports through onMoveEnd.
    Pixi subscribes to its viewport store.

  • CanvasViewport type moves to the React layer

    Renderer contract re-exports it.

Known issues

  • Viewports of deleted nets stay until the cap evicts them

Test coverage

  • remember-canvas-viewport.test.ts:

    Insertion order, replacement and the cap.

  • Headless Playwright script on both renderers:

    Pan and zoom, reload, restore, and a fresh fit for a second net.

How to test

  • Open Petrinaut preview on Vercel
  • Load example > SIR, zoom and pan
  • Reload
  • Expect same position and zoom
  • Load example > any other example
  • Expect fit to screen
  • Switch back to SIR
  • Expect previous position and zoom
  • Viewport controls > Settings > Renderer > Pixi, repeat

@vercel

vercel Bot commented Sep 2, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
hash Ready Ready Preview Sep 3, 2026 11:47pm UTC
petrinaut Ready Ready Preview Sep 3, 2026 11:47pm UTC
petrinaut-docs Ready Ready Preview Sep 3, 2026 11:47pm UTC
1 Skipped Deployment
Project Deployment Actions Updated
hashdotdesign-tokens Ignored Ignored Preview Sep 3, 2026 11:47pm UTC

Request Review

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

Labels

area/infra Relates to version control, CI, CD or IaC (area) area/libs Relates to first-party libraries/crates/packages (area) type/eng > frontend Owned by the @frontend team

Development

Successfully merging this pull request may close these issues.

1 participant