Skip to content

Fix chart overflow at narrow widths and smooth playground typing - #2

Merged
elementmerc merged 2 commits into
mainfrom
feat/v0.1-scaffold
Jun 9, 2026
Merged

elementmerc merged 2 commits into
mainfrom
feat/v0.1-scaffold

Conversation

@elementmerc

Copy link
Copy Markdown
Owner

Follow-up to #1. Fixes the horizontal scrollbar that persisted on the playground preview and the sluggish feel.

Root cause

<alt-chart> is a custom element, so it is display: inline by default and reports clientWidth: 0. The runtime's host.clientWidth || 640 therefore always took the 640px fallback: every chart has been a fixed 640px since the start. A full-width article column hid it; the narrow playground pane (~330px) exposed it as a scrollbar across the whole preview.

Changes

  • Measure the block-level canvas container, not the inline host. Charts now size to the real available width everywhere. On resize they reconcile against the chart's own current width, and resize bursts (a window drag) are coalesced into one redraw per frame.
  • Skip redundant playground re-renders. An edit that does not change the rendered output no longer tears down and rebuilds every chart and diagram; the debounce is slightly longer. Typing on a graphics-heavy document stays smooth.
  • Regression guard. A new playground e2e loads the page in a narrow, short viewport (the exact condition that reproduced the bug) and asserts the preview never overflows horizontally, at load and after a resize.

No crate changes: chart sizing is a browser-runtime responsibility; the core only emits the component element and its accessible fallback table.

Verification

typecheck clean, eslint clean, 13 unit tests, build 45 KB, 15 e2e green (including the new overflow guard, which fails on the old code with a 284px overflow and passes on the fix).

The chart custom element is display:inline by default, so its clientWidth
is 0 and every chart fell back to a fixed 640px width. At a full-width
article that happened to fit; squeezed into the narrow playground pane it
overflowed and left a horizontal scrollbar across the preview. Measure
the block-level canvas container instead, reconcile against the chart's
own width on resize, and coalesce resize bursts into one redraw per frame
so a window drag no longer feels slow. A playground e2e asserts the
preview never overflows sideways, at load and after a resize.
Re-mounting tears down and rebuilds every chart and diagram, so an edit
that leaves the rendered output unchanged now skips the mount, and the
debounce is a touch longer. Typing on a graphics-heavy document stays
smooth.
@elementmerc
elementmerc merged commit 37e3b24 into main Jun 9, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant