fix(web): restore full starfield view after zoom-out#220
Conversation
Zooming out from a focused sun left the field looking collapsed to one side — most suns/planets hidden, background dimmed. The camera actually recentred correctly to (0.5, 0.5, zoom 1); the bug was that the animation loop kept rendering in "focused mode" because it read a STALE focusedSunId. The params memo feeding the loop lags focus changes, so `props.focusedSunId` stayed set after React had already cleared focus on zoom-out. Read focus from a live ref instead (synced on every change, mirroring hoveredSunIdRef), so focus-mode rendering — dimmed background, vignette, and the planet filter that hid all but the focused sun's planets — clears on zoom-out. Verified headless: after zoom-out focus=null, camera=(0.5,0.5,1), and all 14 planets render again (was 2/14 while the stale focus persisted). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
Disabled knowledge base sources:
📝 WalkthroughWalkthrough
ChangesLive focusedSunId ref for animation loop
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
Symptom
After zooming into a focus-area sun and clicking Zoom Out, the starfield looked collapsed to one side — most suns hidden, planets missing, background dimmed, a vignette and the focused sun's orbit ring still showing. It stayed that way (not a transient).
Root cause
The camera was a red herring — instrumented telemetry shows it recenters perfectly to
(cx 0.5, cy 0.5, zoom 1)on zoom-out. The real bug: the animation render loop kept rendering in "focused mode" because it read a stalefocusedSunId.focusedSunIdis fed to the loop through theanimationParamsuseMemo, which lags focus changes — soprops.focusedSunIdstayed"…-sun"even after React had cleared focus (the Zoom Out button, gated onfocusedSunId, had already unmounted). Focus-mode rendering branches (if (props.focusedSunId)) therefore stayed active:Fix
Sync
focusedSunIdinto a live ref (focusedSunIdRef) on every change — mirroring the existinghoveredSunIdRefpattern in this same component — and have the loop read the ref instead of the memoised prop. Itsnull(= "no focus") is used directly; it only falls back to the prop if the ref is unwired (defensive). 3 files, +29/-8.Verification (headless, against the production build)
Clicking the real sun positions to trigger an actual zoom, then the DOM Zoom Out button:
Before the fix the loop reported
focus = "…-sun"and2/14planets after zoom-out (focus-mode stuck on); after the fix it'snulland14/14, and the screenshot shows the full centred starfield restored.Note on #219
PR #219 (camera-transform offset fade) was based on a misdiagnosis — the transform was never the cause. It's harmless (identity at the resting state) and left in place; can be reverted separately if desired.
Summary by CodeRabbit