fix: keep folded sections aligned after window resize#210
Conversation
Replace the CSS grid 1fr/0fr fold animation with an explicit measured height. WebView failed to recompute the 1fr grid track after content reflow on resize or cross-display moves, leaving stale gaps or overlap. observeFoldLayout() watches each expanded .content-inner with a ResizeObserver, batches writes through one animation frame, and publishes the measured scrollHeight as --fold-content-height (innermost wrappers first so nested measurements stay consistent). The wrapper animates that explicit height, so expanded sections track their content and collapsed sections stay at height 0. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The height transition is meant only for fold/unfold. Because a resize also changes the measured height, the wrapper animated toward the new height over 0.25s while its content had already reflowed, leaving the next section overlapping the still-visible overflow on every resize. Suppress the transition around each measured write and force one layout to commit it, then restore the stylesheet transition so fold toggles still animate. Verified in a standalone harness: on resize the wrapper now matches its content instantly (97->97, 173->173 across widths) while the fold-toggle duration stays 0.25s. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1cb7996 to
4e07675
Compare
|
Why this only manifests on large, heavily-sectioned documents — supplementary analysis that may help review/testing. The defect itself is size-independent: with an animatable What scales with document size is the bug's exposure, via four conditions:
This is also why the fix is exposure-independent: Test suggestion: a large fixture (many 🤖 Generated with Claude Code |
Problem
After the window is resized (or moved between displays with different scale factors), expanded heading sections lose alignment with their content. Two visible forms:
Root cause: folding animates
grid-template-rows: 1fr ⇄ 0fron.foldable-content-wrapper. After content reflows (narrower window → paragraphs wrap taller), the WebView does not reliably recompute the1frtrack, so the wrapper's layout height goes stale relative to its rendered content, whileoverflow: visiblelets the content paint outside it.Fix
height: var(--fold-content-height)(collapsed:height: 0).src/lib/utils/foldLayout.ts—observeFoldLayout(root)attaches a singleResizeObserverto each expanded.content-inner, batches all writes into one animation frame, and measures innermost wrappers first so nested folds stay consistent.MarkdownViewerstarts observation after each preview render and disconnects before the preview HTML is replaced.Testing
scripts/foldLayout.test.ts(new) + wholescripts/*.test.tssuite passes;svelte-checkreports 0 errors/0 warnings.samples/fold-resize-regression.md.🤖 Generated with Claude Code