Skip to content

Let the browser hold the reader's place when the Threads panel takes its strip - #801

Merged
max-sixty merged 12 commits into
mainfrom
threads-panel-layout
Sep 18, 2026
Merged

max-sixty merged 12 commits into
mainfrom
threads-panel-layout

Conversation

@max-sixty

@max-sixty max-sixty commented Sep 18, 2026 •

Copy link
Copy Markdown
Owner

Opening the Threads panel moved the document a long way: on a page with a sidebar and a sidenote, at a 1728px window, the reader's paragraph travelled 382px left and 149px down in one gesture. The sideways move is the design — body yields the panel's strip and the page re-lays out as it would for a narrower window, which is what theme.css says it should do. The drop was a bug, and it was worse the narrower the window: 202px at 1560, 590px at 1024, and 1409px at 900, where the reading column itself gives up width and the document grows by 2277px.

The cause is one property. body { margin-right } was how the page yielded the strip, and margin is a scroll-anchoring suppression trigger — in the spec's list and in Chromium's — on the path from every anchor to the scroller. So the page switched off the one mechanism that was going to carry the reader across the reflow it was itself causing. Isolated on a live page: 200px of growth above the reader anchors normally; the same growth with body's margin changing in the same frame does not.

border-width is in neither list. body is already border-box, so a transparent border leaves the lf-shell container the same inline size it had — measured 1308 at a 1728px window, both spellings — every container query below reads what it read before, and the fixed panel paints over the strip the border reserves.

The column's 180ms glide was the second suppressor: it animated main's left, which Chrome flags, on every frame it ran, and it is what dropped the reader when the panel closed. Removing it means the column jumps sideways and keeps its words, which is the better half of that trade and what an editor with a side panel does.

What the hold rests on

The anchoring hold is real but it rests on an ordering, not a guarantee. main's left (through --lf-shift) and its width still change when the strip is taken, and both are on Chromium's suppression list. They escape it only because they are container-driven: the container-query recalc that moves them runs inside layout, after ScrollAnchor::NotifyBeforeLayout has already walked the anchor's ancestors. A shift set any other way would switch anchoring off again. The theme comment at the body strip says so, and TODO #28 records how to remove the dependency.

What this deletes

--lf-shell-motion-x — its registered property, the left expression in theme.css, the motion() call, shellMotion, and margin-layout.js's columnMoving branch.

The deferred repaint goes with them. moveContentFrame scheduled pageShifted() and layoutMarginRows() a frame later only because the column was in flight; with the column arriving in the layout pass that moves it, there is nothing to wait for, so scheduleShellRepaint, repaintShell and shellFrame are gone and the margin rows and page marks are placed in the gesture itself. moveContentFrame is now change(); pageShifted(); layoutMarginRows();. That also removes the frame a test could read across: panel_settled needs no wait beyond the panel's class, because there is no longer a pending frame behind it.

setPanel returned the animation and three modules passed it along; that plumbing goes too, with the gallery's ?.finish() and setThreads's return.

One thing arrives: shellRight() in geometry.js, because three callers read body's right edge to place margin rows and the response surface, and that edge is now the content box rather than the box body draws. The render gate's misplacedBoxes took body's padding off the room but not its border, which would have put the room's right edge at the window and let a widget standing in the strip go unreported; it takes both now. That reading was correct only because the gate renders at one viewport with no panel standing, which is a condition to rely on rather than a reading to keep. Across the runtime and theme the change is 109 insertions and 117 deletions against main; most of the insertions are the theme comment explaining why the strip has to be a border.

Measured

The reader's paragraph holds at 1920, 1800, 1728, 1650, 1560, 1496, 1440, 1366, 1280, 1152, 1024, 900 and 840 — Threads and the Asks tray, opening and closing, from the pointer and from the keyboard, with an exact round trip — and no JavaScript doing it.

This branch first added a hand-written carry that did the same job in 69 lines of JS, then deleted it once the border swap let the browser do it better. Its test, test_taking_the_panels_strip_leaves_the_reader_on_the_same_words, is kept. Passing with no runtime behind it is what makes it the right guard: it goes red the moment a property on the anchor's chain regresses to a trigger. A planted-fault control confirms it catches the regression — before the border swap and without the carry, the reader landed three paragraphs down.

The suite

The browser cases that read the old shell are reworked rather than patched. Two were built around the column's carry: they held the runtime's motion, asserted exactly one animation existed, and seeked it to check the column travelled monotonically without crossing a responsive posture mid-flight. The behaviour they protect is that the page never visits an intermediate posture, which now holds structurally, there being no motion left to inspect; so they assert the shell at its final width, the resident in its final float, nothing moving, and the strip taken as a border. Every reading of where the page ends now takes body's content box rather than the box it draws, which reaches the window, and SHELL_BOX and page_right beside panel_settled are the suite's one spelling of it. One of those readings had the bug the rest were being fixed for: ROOM_GEOMETRY subtracted body's padding but not its border, so with a panel open its right edge was the window, and test_render_pages' "the board does not pass the page" was holding with 420px of slack — it measures 1308 now rather than 1728.

Four waits read body.marginLeft as the Asks tray's room tell: two timed out, and two would have passed on any page, so they read borderLeftWidth. Seven waits on main's animations returned at once and did nothing, and are removed. test_suggestion_controls_stay_out_of_the_column no longer waits, under full motion, for rows to dock through a glide that is gone, and test_an_aim_tracks_an_equal_width_workspace_swap_every_frame sampled only while main animated, so it took one reading; it samples the swap's own task and four frames after it. test_closing_the_panel_lands_the_margin_where_the_column_lands reads in the task that closes the panel and walks each closing route — with the deferred repaint put back it reads the row at 886.5 against a rest of 1096.5, so it catches the regression. Its Escape arm rides its own keydown, registered after the dispatcher's boot listener so it lands in the closing task; a bounding_box after press is a second round trip with a frame in it, which is the frame the case refuses, and Escape is the one route walked with a real key.

Known and not addressed here

  • TODO Write a correction straight rather than offering it as a choice #28 — place the reading column with a grid track rather than left. Make body a three-track grid for column placement only, keeping the border strip so every lf-shell floor keeps its meaning, and give main grid-column: 2; width: 100% so its inset never changes. That removes the ordering dependency above and deletes --lf-shift, --lf-gutter, --lf-sidebar-edge and left, with the same layout at every width and the same sideways jump.
  • A larger grid was considered and decided against. It moved the panel's strip onto main's ledger and let both margin residents keep their strips beside it. That narrows the prose at every laptop width and reverses the floor test_the_sidebar_and_note_floor_is_their_sum pins, and the sideways jump it would have removed is half the strip plus the sidebar handing back its claim — a posture change the reader sees anyway.
  • COVERING asks about the panel, not the page. It is 2 × THREAD_PANEL_W; the page's floor is its reading column (720 + 2×24 = 768), so the panel should cover below a 1188px window rather than 841. Between those the panel stands beside a page that cannot hold a column: at 900 the column is 421px wide, main's left gutter is zero, and the margin markers are pinned against the panel with nothing reserved for them.
  • The margin projection's 900px floor is a media query while the strip grants are container queries, so the panel can withdraw a grant it can never restore the covering decision for. .lf-chrome hangs off body, and body's inline size does not depend on main's claims, so that pair can be a lf-shell container query — leaving exactly one question that asks the window.

This was written by Claude Code on behalf of max-sixty

max-sixty and others added 9 commits September 18, 2026 11:43
Opening the Threads panel or a tray narrows `body`, and the page answers the
narrower shell by handing margin postures back. That reflows the document under
the reader, who is not carried with it: on a page holding both a sidebar and a
sidenote, the paragraph in front of them fell 149px at a 1728px window, 203px at
1560, 228px at 1152, and 725px at 1024, where the reading column gives up width
as well and the document grows by 968px.

The browser would absorb all of it. Scroll anchoring works on these pages, but
the spec suppresses it for any frame in which a box on the anchor's ancestor
chain changes its margin or its width — which is exactly what taking the panel's
strip does to `body`. Confirmed by isolating the trigger: growing a block above
the reader carries them, and the same growth with `body`'s margin or `main`'s
width changing in the same frame does not.

`moveContentFrame` already reads `main`'s box before and after the change to
animate the column's horizontal travel. It now reads a flow anchor the same way
and restores the vertical displacement, which puts back what anchoring would
have done. Measured across 1920 to 840: every vertical jump goes to zero, in
both directions, from the pointer and from the keyboard, and a round trip
returns the reader to the exact scroll offset they started at.

The horizontal travel is unchanged; it is the design, and it is animated.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
test_covering_threads_keeps_the_reader_and_their_work_inside read the
document's scroll against a value taken before the panel had ever opened, so
what it actually asserted was that nothing writes the scroller. That is the
shape the code happened to have, not a behaviour: the point of each of those
three assertions is that a key, a wheel, or a close does not move the covered
document, and each now reads against where the document stood when its own
gesture started. Its fixture is a plain column, and at 1000px the panel's strip
squeezes that column and re-wraps it, which is why this one caught the carry.

The behaviour the carry adds gets its own case. A re-wrap moves every paragraph
by a different amount, so the test names which one the reader's place means —
the block under the top of the window, which is the block the platform's own
anchoring would hold — and checks it is the same block, at the same height,
after the strip is taken and again after it is returned. Without the carry the
reader lands three paragraphs down.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The page yielded the panel's strip with `body { margin-right }`. Margin is a
scroll-anchoring suppression trigger, in the spec's list and in Chromium's, and
body is on the path from every anchor to the scroller — so the page turned off
the one mechanism that was going to carry the reader across the reflow it was
causing. `border-width` is in neither list. Body is already `border-box`, so a
transparent border leaves the `lf-shell` container the same inline size it had
(measured: 1308 at a 1728px window, both spellings), every container query below
reads what it read before, and the fixed panel paints over the strip the border
reserves. The only difference is that the browser goes on anchoring.

The column's 180ms glide was the second suppressor. It animated `main`'s `left`,
which Chrome flags, on every frame it ran, and it is what dropped the reader when
the panel closed. The page jumps sideways now and keeps its words, which is the
better half of that trade and what an editor with a side panel does.

With both, the reader's paragraph holds at every width from 1920 to 840, Threads
and the Asks tray, opening and closing, with an exact round trip — and no
JavaScript doing it. So the carry from two commits ago goes, along with
`--lf-shell-motion-x`: its registered property, the `left` expression, the
`motion()` call, `shellMotion`, `repaintMovingShell`'s animation loop, and
`margin-layout.js`'s `columnMoving` branch. `moveContentFrame` is two lines.

Its test stays exactly as written. Passing with no runtime behind it is what
makes it the guard: it goes red the moment a property on the anchor's chain
regresses to a trigger.

`shellRight()` arrives in geometry.js because three callers read body's right
edge to place margin rows and the response surface, and that edge is now the
content box rather than the box body draws.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Three browser cases read the old shell directly. Two of them
(test_an_auxiliary_surface_lands_one_responsive_layout_and_carries_the_column_to_it)
were written around the column's carry: they held the runtime's motion, asserted
exactly one animation existed, and seeked it to check the column travelled
monotonically without crossing a responsive posture mid-flight. The behaviour they
were protecting is that the page never visits an intermediate posture, and that now
holds structurally rather than by inspection, there being no motion to inspect. So
the case asserts what is left: the shell at its final width, the resident in its
final float, nothing moving, and the strip taken as a border — which is the property
that keeps the reader's place, and worth a test of its own naming it.

The third read body's border box as the room the document has. That box now reaches
the window, the strip being a border, so it reads the content box.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Three places in the suite still described the shell the way it worked before the
strip became a border. `test_page_and_panel_scroll_in_separate_regions` read
body's drawn box for where the page ends, which is now the window, so it saw the
page and the panel overlapping. The other two are comments promising a glide that
this branch removed.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Four waits in test_render_widgets.py read `body.marginLeft` as the tell that the
Asks tray took, or gave back, its strip. The strip is a border now, so the two
waiting for a nonzero margin timed out and the two waiting for a zero one would
have passed on any page at all. They read `borderLeftWidth`.

test_suggestion_controls_stay_out_of_the_column also waited, under full motion
only, for the margin rows to dock for the length of the column's glide before
checking they came back. There is no glide, so there is no dock to wait for, and
both motion arms now go straight to the settled page. Its `room` read body's drawn
box, which reaches the window with the strip a border, so the check that a row
ends before the panel was passing with 420px to spare; it reads the content box.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Four passages still described the carry this branch deleted. The docstring of
test_taking_the_panels_strip_leaves_the_reader_on_the_same_words said the runtime
carries the reading place itself, which is now the opposite of what happens, and the
covering test's comment said moveContentFrame did. `panel_settled` waited out an
animation on `main` that no longer exists — nothing else animates `main` — so that
wait goes; `edge_settled` keeps the region's own arrival slide, which is still real,
and drops `main` from what it finishes.

The theme comment gains the one fact the next person needs before touching the
column. `main`'s `left` and `width` do change when the strip is taken, and both are
on Chromium's scroll-anchoring suppression list. They escape it only because they are
container-driven: the container-query recalc that moves them runs inside layout, after
`ScrollAnchor::NotifyBeforeLayout` has already walked the anchor's ancestors. A shift
set any other way would switch anchoring off again.

TODO gains #28, the grid-track placement that would remove that dependency. The
larger grid discussed alongside it is not on the list: it moved the panel's strip onto
`main`'s ledger and let both margin residents keep their strips beside it, which
narrows the prose at every laptop width and reverses the floor
`test_the_sidebar_and_note_floor_is_their_sum` pins. The sideways jump it would have
removed is half the strip plus the sidebar handing back its claim, which is a posture
change the reader sees anyway.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The swap is the right shape — one property, and the carry comes out with it. Three things
the deletion left standing.

panel_settled no longer waits for anything

Its second wait is main.getAnimations() emptying, and the carry was the only thing that
ever put an animation there — this PR's own new case asserts
main.getAnimations().length + window.__lfHeld.length == 0 on the frame the panel opens.
So the helper now returns as soon as the panel class flips, while scheduleShellRepaint's
requestAnimationFrame still has pageShifted() and layoutMarginRows() ahead of it.
That is the half of the contract its first line states — "the page to finish making room
for it" — and 252 calls across 19 files read geometry behind it.

The suite is green: I ran tests/test_render_margin.py whole and the panel and shell cases
in test_render_controls.py and test_render_gate.py against this head, all passing. But
green here is the driver round trip happening to span a frame, which is the shape
tests/CLAUDE.md names under "State races are arrangements, not probabilities".
margins_laid_out already runs the pending layout, if panel_settled should now be
waiting on that instead.

tests/CLAUDE.md also states the removed mechanism twice, and is not in the diff:

  • "panel_settled waits for the requested panel class and then for the body's finite
    animations to empty."
  • "panel_settled and edge_settled finish the shell carry rather than waiting out a
    clock the test has stopped."

Four places still say the runtime carries the reader

9b6809a9 swept three of them, and skills/leaf/assets/CLAUDE.md gains the opposite rule
in this same PR ("nothing here may take that back"). Left standing:

  • The new guard's docstring, and the comment above covered_at — inline suggestions below.
  • skills/leaf/assets/runtime/chrome-layout.js, the comment introducing the layoutSizes
    observer: "because an auxiliary surface lands its final shell width before the column
    finishes moving there … moveContentFrame's frames keep page-attached paint with the
    carried column". Outside a hunk, so not suggestable inline.
  • tests/render_cases_interaction.py's HOLD_MOTION note ("final-page shell motion", "the
    shell carry panel_settled takes to its end"), and
    test_closing_the_panel_lands_the_margin_where_the_column_lands, whose docstring and
    __lfCarryEnd arrangement are built entirely on the carry. Its assertion still holds;
    nothing it arranges is doing work any more.

The new guard's docstring is the one that matters. It states the suppression this PR
removes and credits a runtime carry this PR deletes, on the case whose whole value is
passing with no runtime behind it — whoever it goes red on will go looking for the carry
first.

moveContentFrame's return value is still plumbed three modules deep

It returns undefined now, but thread-panel.js keeps const played = moveContentFrame(…)
and return played, interaction-gallery-frame.js keeps
commands.setPanel(false, { remember: false })?.finish() and hands setThreads's return to
the gallery, and interaction-gallery.js's track() still carries the if (!animation)
branch that catches it. Nothing breaks. But the gallery's open-threads step used to await
the column's carry before advancing and now advances immediately, which is an unstated
timing change in the recorded demo, and setPanel is left with a return value that is
always undefined.

Happy to push the prose corrections and the panel_settled change as one commit if you want
them.


Smaller: 63bf2213 makes a fourth hand-rolled copy of shellRight's arithmetic in the
suite (render_cases_layout.py, test_render_controls.py twice, now
test_render_widgets.py). The runtime got the primitive in this PR; a page_right(page)
beside panel_settled would give the suite the same one spelling.

Comment thread tests/test_render_controls.py Resolved
Comment thread tests/test_render_controls.py Resolved
max-sixty and others added 2 commits September 18, 2026 13:45
The review of this branch found a race. `moveContentFrame` deferred its repaint to
the next frame — the margin's rows and the page's marks, placed against the column —
and `panel_settled` had stopped waiting on anything past the panel's class once the
glide went. The old wait on `main`'s animations had spanned that frame only as a side
effect, so about 250 geometry reads following `panel_settled` were racing it.

The repaint was deferred only because the column used to be in flight. It now arrives
in the same layout pass as the state change, so the paint that follows it runs there
too, in the gesture, and there is no frame left to race. That fixes the producer rather
than the helper. `test_closing_the_panel_lands_the_margin_where_the_column_lands` now
takes its read in the very task that closes the panel, with no frame between, and walks
each closing route; with the repaint put back on a frame it reads the row at 886.5
against a rest of 1096.5.

The shell's private frame and its loop go with the deferral (`scheduleShellRepaint`,
`repaintShell`, `shellFrame`), and so does the dead plumbing behind them:
`moveContentFrame` returned nothing to `setPanel`, which returned it to the gallery,
which waited on it. The Threads replay no longer waits out a carry that does not exist,
so it is 180ms shorter, which is how long the product now takes.

Seven waits on `main`'s animations in the suite returned at once and did nothing — no
code animates `main` any more — and go. `edge_settled` keeps the region's own arrival
slide, which is still real.

The suite read the page's right edge four ways. `SHELL_BOX` and `page_right` beside
`panel_settled` are the one spelling now, read off the DOM rather than through
`shellRight`, so a test comparing it to a region's box compares two independent
readings. A fifth reading had the defect the others were being fixed for:
ROOM_GEOMETRY's `room` subtracted body's padding but not its border, so with a panel
open its right edge was the window and not the shell (1728 rather than 1308), and
test_render_pages' "the board does not pass the page" held with 420px of slack. It is a
content box now.

The rest is prose that still described the carry: tests/CLAUDE.md, the layout
observer's comment, the held-motion note, and an example in motion.js.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…otion

test_an_aim_tracks_an_equal_width_workspace_swap_every_frame sampled the aim's
offset from its target on every frame `main` was animating, which is no frames now:
swapping a left tray for a right panel moves the shell without changing its width,
and the column arrives in the layout pass that moves it. The trace came back one
reading long and the case failed on its own arrangement rather than on the aim.

What it is for survives the motion going. The aim is placed off a move that resizes
nothing, so it has to be re-placed from the swap itself, and it now has to be right in
the swap's own task. That is the first reading; four frames follow it, for a placement
that lands late or drifts once the page settles.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The Escape arm of test_closing_the_panel_lands_the_margin_where_the_column_lands does not hold the property the rest of the case is built on. The two click routes read the row inside the closing task, but Escape goes page.keyboard.press(...) then bounding_box() — two CDP round trips with frames free to run between them — so a repaint deferred to the next frame lands before the read and the assertion passes anyway.

Verified on this head by putting scheduleShellRepaint's requestAnimationFrame back in moveContentFrame: the toggle route fails at 886.5 against a rest of 1096.5, and the Escape arm on its own passes. The inline suggestion rides the read on the same keydown — the dispatcher's listener is a plain document.addEventListener("keydown", …) registered at boot and it never calls stopImmediatePropagation, so one added afterwards runs after it, in the closing task. With that in, the Escape arm fails at 886.5 too. It matters because Escape is the one route walked with a real key, so it is the arm that would catch a keyboard caller that reached the panel without going through moveContentFrame.

Separately, and not a blocker: render-checks/layout.js still derives the page's room as bodyBox.right - parseFloat(bodyStyle.paddingRight) — padding but not border, which is the defect ROOM_GEOMETRY was just fixed for. It holds today only on the condition its own comment states, that the gate "renders at one viewport with no panel open"; if a restored panel ever reaches it, roomRight becomes the window and a widget standing in the strip goes unreported. Happy to push that one alongside the test change if you want it.

Comment thread tests/test_render_margin.py Resolved
…gate's room

The Escape arm of test_closing_the_panel_lands_the_margin_where_the_column_lands
proved nothing. Pressing and then reading the row is two round trips with a frame
free between them, which is all a deferred repaint needs to land before the read, so
that arm passed whatever the runtime did. It is the one route walked with a real key,
and so the one that would catch a keyboard caller closing the panel without going
through moveContentFrame.

The read rides the press now: the dispatcher's listener is a plain document keydown
registered at boot that never stops propagation, so one registered after it runs after
it and inside the closing task. With the repaint put back on a frame the arm fails at
886.5 against a rest of 1096.5 — checked with the click routes skipped, since they
fail first and mask it, which is how the hole survived the first bug-back.

The render gate had the reading ROOM_GEOMETRY was just fixed for: `roomRight` took
body's padding off but not its border, so the room it measures a misplaced box against
ended at the window rather than at the page. It holds today only because the gate
renders at one viewport with no panel standing, which is a condition to rely on rather
than a reading to keep.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit 47ffde6 into main Sep 18, 2026
5 checks passed
@max-sixty
max-sixty deleted the threads-panel-layout branch September 18, 2026 22:46
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