FE-1586: Remember the canvas viewport per net - #9510
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
c08b2dd to
5903e85
Compare
5903e85 to
808cd87
Compare
808cd87 to
b163578
Compare
PR SummaryLow Risk Overview A new The React Flow canvas uses the saved viewport for Reviewed by Cursor Bugbot for commit e1e1f08. Bugbot is set up for automated code reviews on this repo. Configure here. |
There was a problem hiding this comment.
🟡 Changes recommended
Reload timing can lose a viewport, and numeric document IDs break recency-based eviction.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Persists each Petrinaut canvas viewport so nets reopen at their previous pan and zoom.
Changes:
- Adds per-net viewport storage with capped retention.
- Restores and records React Flow viewports.
- Adds tests, documentation, and a patch changeset.
File summaries
| File | Description |
|---|---|
.changeset/canvas-viewport-persistence.md |
Records the patch release. |
docs/drawing-a-net.md |
Documents viewport restoration. |
react/petrinaut-provider.tsx |
Mounts the viewport provider. |
react/state/canvas-viewport-context.ts |
Defines the viewport contract. |
react/state/canvas-viewport-provider.tsx |
Coordinates viewport persistence. |
react/state/user-settings-context.ts |
Adds viewport settings and action. |
react/state/user-settings-provider.tsx |
Updates persisted viewport state. |
react/state/user-settings-provider/remember-canvas-viewport.ts |
Implements capped retention. |
react/state/user-settings-provider/remember-canvas-viewport.test.ts |
Tests retention behavior. |
ui/views/SDCPN/canvas-renderer.ts |
Re-exports the shared viewport type. |
ui/views/SDCPN/renderers/react-flow/react-flow-canvas.tsx |
Restores and reports the viewport. |
ui/views/Editor/panels/SimulateView/experiments/create-experiment-drawer.test.tsx |
Updates the settings test fixture. |
Review details
- Files reviewed: 12/12 changed files
- Comments generated: 2
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit b163578. Configure here.
Review feedback read the replacement as reframing every net on first load. It does not: xyflow resolves a numeric padding to whole pixels a side and subtracts them from the container, which is the same fit as dividing the bounds by one plus the padding, to within that flooring.
Coalescing the writes left the last move in memory for 250 ms, so a reload in that window lost it, and the flush ran on every render rather than on unmount. Renderers report a settled viewport instead of each frame, so the write goes straight through and there is nothing pending to lose. The cap read recency off object key order, which JavaScript does not keep for keys that read as integers, so a saved viewport now carries a stamp and the cap evicts by it.
b163578 to
e1e1f08
Compare

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. The canvas starts from the saved viewport when one exists and reports its moves through one context, so a net reopens where it was left.
9510.mp4
Links
Changes
CanvasViewportContextexposessavedViewportandrememberViewportcanvasViewportsuser setting keeps the most recently saved netsCanvasViewporttype moves to the React layerReview fixes
Known issues
Test coverage
remember-canvas-viewport.test.ts:How to test