fix: preserve graph layout on viewer refresh#803
Conversation
|
@mturac is attempting to deploy a commit to the rohitg00's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughUpdated the graph viewer to preserve node positions and velocities plus pan/zoom across graph re-initialization and window resize events. The simulation now snapshots prior layout and viewport, removes duplicate resize listeners, cancels any running RAF before restarting, reattaches a single resize handler, and restores previous node coordinates and viewport when nodes are recreated. ChangesGraph State Preservation Across Re-initialization
Sequence DiagramsequenceDiagram
participant Window
participant initGraph
participant graphSim
participant Canvas
Window->>initGraph: trigger (loadGraph / resize)
initGraph->>graphSim: capture previousLayout, previousPan/Zoom, cancel RAF
initGraph->>Window: remove old resize listener
initGraph->>Window: add resize listener (graphSim.resizeHandler)
initGraph->>graphSim: recreate nodes (reuse previous x/y/vx/vy when id matches)
graphSim->>Canvas: set panX/panY/zoom and node positions
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/viewer/index.html`:
- Around line 1818-1820: initGraph currently calls runSimulation()
unconditionally and can start a new rAF chain while a previous one is still
scheduled; fix by tracking the animation handle (e.g., a module-level variable
like rafId) and calling cancelAnimationFrame(rafId) (and setting rafId = null)
at the start of initGraph before calling runSimulation(), and ensure
runSimulation stores the returned requestAnimationFrame id into rafId each frame
so subsequent re-inits can cancel the pending frame.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: a321c945-7f2e-4754-b78c-1500d0196d50
📒 Files selected for processing (2)
src/viewer/index.htmltest/viewer-graph-cooldown.test.ts
Summary
Tests
Closes #691
Summary by CodeRabbit
Bug Fixes
Tests