Fix table relayout racing the reading-width transition - #25
Open
jedrzejsieracki wants to merge 1 commit into
Open
Fix table relayout racing the reading-width transition#25jedrzejsieracki wants to merge 1 commit into
jedrzejsieracki wants to merge 1 commit into
Conversation
Signed-off-by: jedrzejsieracki <jedrzejsieracki@users.noreply.github.com>
Open
2 tasks
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.
Fix table relayout racing the reading-width transition
Problem
Tables settle into their "wide surface" layout (escaped from the text column,
horizontal scroll) based on the previous reading width rather than the
current one. The result is sticky, nondeterministic table layout after using
the reading-width control, the width presets, or after resizing the window:
the same width can leave a table wide or normal depending on which width it
came from, and the table expand/collapse button then starts from that stale
state.
Root cause
#preview-documentanimates column-width changes:but
previewmdSetLayoutrelaid out tables on the next animation frame:The rAF callback runs in the first frame of the 180 ms transition, so
articleContentWidth()reads the pre-animation width andlayoutTablebases the wide/normal decision on it. The
window.resizelistener calledenhanceTables()synchronously, which has the same problem (the column widthtransitions when the window is resized).
Evidence
Measured in the embedded web view while sweeping the reading width
480 → 720 → 1100 → 480 → 1100, probing the table state 50 ms and 550 ms after
each change (before this fix):
The wide/normal decision tracked the previous width every time.
Fix
Debounce the table relayout past the transition (240 ms), re-arming the timer
on every layout change, so the measurement always happens at the final column
width. During continuous changes (slider drags, window resizes) no intermediate
relayout happens at all; the table is laid out once, correctly, when the column
settles. Reduced-motion configurations are unaffected — with no transition the
timer simply relayouts after 240 ms.
previewmdSetLayoutand theresizelistener both route through the newscheduleTableRelayout().After the fix, all sweeps settle deterministically: 480 → wide, 720 → normal,
1100 → normal, and expand → collapse returns the table to the width-appropriate
state at every width (14/14 probes correct).
Testing on macOS
4 × 144 px = 576 px, close to the default column width — a good probe).
switch between the narrow/comfortable/wide/table presets. The table must
end up wide exactly when the column is too narrow for it, every time.
return the table to the width-appropriate layout.
Tests
testWideTableKeepsReadableColumnsAndExpandsIndependently(
EditorWebViewTests) exercises the initial layout, which stays synchronous(
enhanceTables()still runs inline duringpreviewmdRender); no testasserts the timing of
previewmdSetLayoutor window resizes.machinery that could not be validated here (this patch was authored and
verified on Linux against the bundled renderer in a WebKitGTK shell — the
measurement table above is from that harness).
swift testshould run onmacOS CI; happy to add a regression test as a follow-up if the maintainer
wants one.
Scope
Renderer-internal change (
Resources/Renderer/renderer.jsonly). No API orpayload changes; hosts drive the renderer exactly as before. Found while
building the experimental .NET port slice (
docs/PORTING.md); the bug is inthe shared renderer and affects the macOS app as well — large jumps (width
presets) reproduce it there.