Skip to content

Read the margin preview's box after its placement lands - #627

Merged
max-sixty merged 2 commits into
mainfrom
fix/preview-placement-ordering
Sep 13, 2026
Merged

max-sixty merged 2 commits into
mainfrom
fix/preview-placement-ordering

Conversation

@leaf-agent

@leaf-agent leaf-agent commented Sep 12, 2026 •

Copy link
Copy Markdown
Collaborator

test_a_pane_comment_stays_in_its_reading_region and test_the_thread_card_survives_trays_and_authored_sidebars read the margin preview's box while the card can still be unplaced, so both fail intermittently in the nightly browser suite on a position the page never meant to show. I hit the first one once in a full test_render_controls.py tests/test_render_navigation.py run: assert 0 >= 119.953125, the card reported at x: 0, y: 0.

Opening the card calls resetThreadPreviewPosition, which clears data-lf-thread-placement and sets opacity: 0, and the position itself lands through a promise a frame later. Playwright counts a non-empty box as visible whatever its opacity, so expect(preview).to_be_visible() returns on the transparent card, and the geometry read that follows can beat the placement. What that read gets depends on whether the card has ever been placed: the navigation case opens it for the first time and reads the viewport origin, while the margin case reopens a card whose inline left/top survive the reset — the reset clears the attribute, opacity, and pointer-events only — so it reads the position the card held at the previous shell width. Both tests now wait for the placement attribute the runtime writes together with the position — the same ordering statement test_render_margin.py already uses before its own placed read. The sites that wait on focus inside the card are already ordered, because deferThreadPreviewFocus holds the focus behind the same promise.

The attribute says the card has a placement, not that it has its settled one: the runtime re-places on every lf-margin-layout event, so the pane card goes below (top 214) → above (top 128) → below (top 214) across the frames after the click at natural timing. Every one of those passes sits inside the pane body, and the margin case places once, so each test's assertions hold whichever pass the read lands on. The visible motion during those frames is a runtime question this change does not touch.

Reproduction and evidence

A frame-by-frame probe of the card between the popover showing and the placement landing, on main:

{'visible': True, 'placement': None,    'opacity': '0', 'top': 0,   'left': 0}
{'visible': True, 'placement': 'above', 'opacity': '1', 'top': 128, 'left': 32}
{'visible': True, 'placement': 'below', 'opacity': '1', 'top': 214, 'left': 32}

One frame is visible-but-unplaced, at exactly the origin the failure reported.

The margin case's own unplaced frame carries the previous open's position instead: reading its composition there gives cardLeft: 1112 against a settled 1128, which is the value that breaks cardLeft >= mainRight after resized_shell widens the shell to 1472.

Stalling the placement promise by 600ms in margin-projection.js turns the unplaced frame into the whole read window, which reproduces both failures on demand. The stall is in place from load, so the card is never positioned at all and the margin case reads the origin there rather than the stale position natural timing gives it:

  • before this change — 2 failed, assert 0 >= 119.953125 and assert 0 >= 1120;
  • after it — the margin case passes; the navigation case reads an intermediate placement, which the stall reaches through a collapsed window but which natural timing produces too, as the re-placement passes above show.

Without the stall both tests pass, and uv run pre-commit run --files tests/test_render_margin.py tests/test_render_navigation.py is clean.

Opening the thread card resets its placement and leaves it transparent at the
viewport origin until the asynchronous position arrives a frame later. A
transparent card still has a non-empty box, so `to_be_visible` returns while it
is unplaced, and two geometry reads take the origin instead of the position.

Both now wait for the `data-lf-thread-placement` attribute the runtime writes
with the position, which is the ordering statement the margin suite already
uses for the same read.

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both reads are ordered now and the two cases pass on this head. Two things about the mechanism the change records are off, and the next reader of these waits would act on them.

The card places more than once per open at natural timing, not only under the stall. The runtime re-places on every lf-margin-layout event, and a probe on this head shows the pane card going below (top 214) → above (top 128) → below (top 214) within about 30ms of the click, with nothing stalled. So data-lf-thread-placement says the card has a placement rather than its settled one, and the navigation read can return on the intermediate pass. Both passes fall inside the pane body here, so the assertion holds either way — but "the intermediate is an artifact of the stall" is the reading that would justify leaving the settled pass unpinned, and it isn't what the runtime does. The card moving below → above → below in the frames after it opens is a separate runtime question worth its own look.

The margin case fails on a stale position rather than on the origin. resetThreadPreviewPosition clears the placement attribute, opacity, and pointer-events, and leaves the inline left/top the previous open wrote. On that reopened card the pre-placement read is the position it held at 1440 — left 1112 against a settled 1128, which is what breaks cardLeft >= mainRight there. The origin read is the first-open shape, which is the navigation case. Suggestion inline.

Comment thread tests/test_render_margin.py Resolved
@max-sixty
max-sixty merged commit 86c71cd into main Sep 13, 2026
4 checks passed
@max-sixty
max-sixty deleted the fix/preview-placement-ordering branch September 13, 2026 03:42
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.

2 participants