Repository navigation
fix(web): resize the canvas on layout changes, not just window resize - #4
Merged
Merged
Conversation
Closing a lesson clipped the network diagram: the ring was drawn for the new, wider canvas area but the canvas bitmap kept its old narrow size, so the right side (EU-CENTRAL, US-EAST, the guide ring) was cut off. Cause: `resizeTo: el` looks like it observes the element, but Pixi's ResizePlugin only subscribes to the window `resize` event. The lesson panel mounting/unmounting flips `.main` between `340px 1fr 400px` and `1fr 400px`, which resizes `.canvas-host` without a window resize. Our own ResizeObserver recomputed the scene layout for the new width, so the wider diagram got clipped to the stale canvas. Fix: resize the renderer from the same observer, after the scene, so the frame `app.resize()` paints already uses the new layout. Also covers Alpenglow <-> Compare switches, where the surviving canvas halves without a remount. Only visible when the host grows by more than the 104px label margin in computeLayout, which is why the mode switches looked fine: the ring shrinks to fit the host, so a stale-but-larger canvas still contained it. e2e/canvas-resize.spec.ts asserts canvas width == host clientWidth after lesson open, lesson exit and both mode switches. Confirmed it fails without the fix (pre-existing canvas clipped at the panel-open step). bun run build (strict tsc) clean, bun run test 53/53, bun run e2e 5/5.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Opening the first lesson (One transaction, two protocols) and then exiting it left the network diagram clipped — the TowerBFT panel was cut down the right side, losing
EU-CENTRAL,US-EASTand the right arc of the guide ring.Cause
web/src/render/CanvasView.tsxpassesresizeTo: elto Pixi, which reads like "track this element", but Pixi'sResizePluginonly subscribes to the windowresizeevent:Opening/closing the lesson panel flips
.mainbetween340px 1fr 400pxand1fr 400px(styles/global.css:53,:73). That resizes.canvas-hostbut never fires a window resize, so the canvas bitmap kept its old, 340px-narrower size. Our ownResizeObservermeanwhile calledscene.resize(...), which recomputes node positions for the new, wider box (scene.ts:48→layout.ts:33) — so the diagram was laid out wider than the visible canvas and clipped.Fix
web/src/render/CanvasView.tsx:64— resize the renderer from the same observer, after the scene, so the frameapp.resize()paints already uses the new layout:Application.resize()is the documented manual trigger and reads the sameclientWidth/clientHeightoff the same element, so the layout and the bitmap can no longer drift.This also covers
Alpenglow ↔ Compareswitches, where the survivingCanvasViewkeeps its Reactkeyand its host halves without a remount.Why mode switches never looked broken
computeLayoutclamps the ring tomin(width/2 - 104, height/2 - 76), so a stale-but-larger canvas still contained the whole (smaller) ring. Clipping needs the host to grow by more than the 104px label margin — which only the 340px lesson panel does. That's why this showed up on lesson close and never on mode switches. The new test pins the size invariant for all three transitions so this can't silently regress.Test
New
web/e2e/canvas-resize.spec.tsassertscanvas.getBoundingClientRect().width === host.clientWidthfor every.canvas-hostafter lesson open, lesson exit, and both mode switches. No sim stepping, so it runs in ~3s.Confirmed it fails without the fix — the pre-existing canvas reports
ok: falseat the panel-open step, where the 340px column is stolen.Verification
bun run build(strict tsc, zero errors) ✅bun run test— 53/53 ✅bun run e2e— 5/5, including the 4 pre-existing specs ✅The two committed e2e screenshots were regenerated by the suite with 15 and 23 scattered pixels of particle noise (verified by pixel diff — no layout change, since the compare screenshot shrinks the ring to fit), so they are left untouched in this PR.
🤖 Generated with Claude Code