Repository navigation
Keep page layout stable during Leaf startup - #439
Conversation
leaf-agent
left a comment
There was a problem hiding this comment.
The new live-page gate reads as a root-relative URL, but on every deployment that scopes routes it matches only because the HTTP layer rewrites it. _ROOTED_PAGE_ROUTE matches a quoted /leaf.js anywhere in a served asset, so scope_page_routes turns the theme's script[type="module"][src="/leaf.js"] into [src="/_leaf-release/<release>/examples/leaf.js"] in the same pass that scope_document_routes rewrites the document's own src. That is why the catalog still reserves its banner — serving the built site and reading the page, getComputedStyle(document.body, '::before').height is 42px at /examples/ while the module tag there is src="/examples/leaf.js". The MCP delivery server's /p/<capability> pages depend on the same rewrite through the Handler's scope_page_routes call.
So the banner reserve, both workspace margins, the rail claim, and the thread margin on every published and MCP-delivered page now rest on a regex in http.py happening to rewrite a string literal inside a stylesheet, and nothing says so: not the theme's comment, not http.py, not a test. This is also the kind of coupling the repo normally pins — test_the_layer_sheets_spell_the_runtime_s_layout_numbers exists because "a stylesheet cannot read a constant", and this PR adds test_the_prepaint_shell_matches_the_runtime_s_saved_arrangements for the bootstrap/theme pair — while the theme/HTTP pair is the one left implicit. The new site cases don't cover it either: both assert only that the shell doesn't move, which also holds when the gate matches nothing and the shell sits at the wrong place the whole time.
Two ways out; which one is your call:
- State the fact rather than deriving it from a URL. The bootstrap already runs before paint and already writes root state, so
document.documentElement.dataset.lfLive = ""there, with the theme gating onhtml[data-lf-live], is the same gate with no dependency on route rewriting. The matched set is unchanged:supervised_documentinjects the bootstrap into every live document, and the bake removes everyscriptfrom a copy. - Keep the selector and make the dependency explicit — name
scope_page_routesin the theme comment as what keeps the selector and the document'ssrcin step, and pin it with a test that the vendored theme and the served document name the same path.
Smaller, same area: wrapping the thread-margin rule's left side in :where() drops that selector to specificity (0,0,1), which is exactly what main { --lf-thread-beside: 0 } earlier in the same sheet carries. The reserve wins on source order now where it previously won on specificity, so moving either block past the other silently reverts the claim.
I ran tests/test_render_startup.py, tests/test_interact_layer.py, tests/test_render_pages.py, tests/test_render_margin.py, tests/test_render_export.py and tests/test_render_navigation.py. The only failure — test_an_inline_thread_uses_surface_focus_until_its_reply_takes_over, timing out on .lf-margin-preview .lf-conversation-thread — reproduces identically at the merge base under the same selection and parallelism, so it is not this branch's.
Since #5049, a page that takes no theme keeps the browser's own tables and code blocks, so one wider than the window no longer scrolls inside its own box. Leaf's root rule `html[data-lf-live] { overflow-x: hidden }` (`browser/base.css`) then stopped the page itself scrolling sideways, and the far side couldn't be reached at all. This deletes the rule. A page wider than the window now pans sideways, as on the open web, and `page check --render` still refuses it (`page-scrolls`), so an agent still fixes the overflow before handing the page over. The rule came in when the root became Leaf's document scroller (26feec8), as what was left of the earlier `html { overflow: hidden }` from when `body` scrolled, and #439 carried it into the render-blocking theme. Neither commit gives a reason for the sideways clip. ## What changed - `browser/base.css`: the rule is gone. The root's comment now says the root scrolls on both axes and that the gate refuses a page wider than the window. - Five comments gave the clip as their reason and now give the sideways scroll and the gate's refusal: the body's `overflow-wrap` and the media `max-width` rules (`base.css`), the pin count's left placement (`annotation-theme.css`), the rail carrier's note on the document's sideways scroll (`margin-layout.js`), and the reading face's header (`reading.css`). The rules themselves stay, since each still keeps content inside its box. The `margin-layout.js` comment moves the kernel's input hash (`dist/kernel/kernel.json`). - `tests/journeys/test_plain_pages.py`: the dashboard's `clipped-out <table>` pin no longer occurs, because the root no longer clips the table, so it goes. The obstacle is renamed `sideways-refusal` and names only the gate's refusal. `page-scrolls` and `past-column` stay pinned. - `tests/browser/test_render_gate.py`: `test_a_page_wider_than_the_window_scrolls_sideways_to_its_far_side` serves a no-theme page holding a `nowrap` table at 390px and wheels over the table until its last column is in the window. With the rule restored, it fails: the wheel never moves the page. ## Behaviour that changed - A page wider than the window scrolls sideways by wheel and the arrow keys (measured below). Touch and trackpad panning use the same native root scroll and weren't driven. Where the platform draws classic scrollbars, such a page should show a horizontal bar at the window's foot; that wasn't captured. - The render gate now reads the root as a scroller on both axes. Content past the window's right edge is reported through `page-scrolls`, and no longer also as `clipped-out` by the root (the dashboard pin above) or, by the same reading of the root's overflow in `reachability.js`, as `clipped-control`. Content carried off the leading edge, which no scroll reaches, is still `clipped-out` (`test_the_render_gate_tells_what_a_column_loses_from_what_stands_beside_it` passes). ## Measured **A no-theme page with a wide table.** The plain `dashboard` fixture, initialized `--no-theme --no-packages` and served by `bin/leaf server start` under a fresh state home, read by `leaf-dev probe` with a journey that brings the table into the window, wheels 1000px sideways over it, then returns and presses ArrowRight twelve times. At 390×844 the last column stands at 419–563px and the page overflows by 173px in both versions. | engine | before: wheel / arrows | after: wheel / arrows | | --- | --- | --- | | Chromium | 0px / 0px | 173px / 173px | | Firefox | 0px / 0px | 173px / 173px | | WebKit | 0px / 0px | 173px / 0px | After a 173px scroll the last column stands at 246–390px, whole in the window. WebKit under Playwright doesn't scroll for synthetic arrow keys at all: ArrowUp doesn't move it vertically either, in either version. At 1440×900 nothing overflows in either version and nothing moves. **Leaf's own chrome.** `scrollWidth` counts overflow under `overflow-x: hidden` too, so the page's sideways overflow (the gate's `rootOverflow`) reads the same in both versions; any state above 0 would be one the user can now pan sideways. Across 48 `leaf-dev stills` states, each driven by its stills driver on a fresh page — the floating panel and the leaf's menu, margin cards and their replies, the thread view on a phone, Threads, the more menu, page search, the page map, the contents, capture, the phone margin, touch and narrow variants, and pages whose own tables and diagrams scroll sideways — the overflow was 0 in every state that completed: 47 in Chromium, 45 in Firefox and 46 in WebKit. `plan-card-beside` fails in its driver in all three engines, and `table-scrolled-phone` in Firefox; both fail the same way on `main` (checked in Chromium and Firefox respectively). `live-sample-embedded-phone` was read in Chromium only, since the feature gallery hung Firefox's run. Every margin row of `review-a-plan`, pointed at so it unfolds, at 20 window widths from 390 to 1640px (pins up to 900px, the rail from 1000px), also gave 0 in Chromium and Firefox. **Stills.** `leaf-dev stills` against the merge base for 16 of those states: in every one, the only computed-style difference is `html` `overflow-x: hidden -> auto`. Pixels are unchanged except in two states. `margin-gallery-phone` differed by an overlay scrollbar's fade and was unchanged on a rerun. `plan-thread-phone` differs on both runs: after the stills driver presses the stop thread's marker on a phone, the page stands 421px higher in one version than the other. That scroll comes from Playwright, not from the press. I ran the driver's sequence 25 times on `main` (3cbb347) and 25 on this branch, interleaved in one Chromium with the arm order alternating each round, alternating motion settings, and the host's load at 6–7. The page scrolled in 3 of 25 runs on `main` (12%) and 8 of 25 on the branch (32%), two-sided Fisher exact p = 0.17. In all 11 runs that scrolled, the page had moved before `pointerdown` reached it. Playwright's click scrolls its target into view first, and in each of those runs it read the marker's box at top 2470px, where the marker stood before the driver's scroll. The marker was painted at 281px, so Playwright scrolled 421px toward the stale box. A real tap does no scroll-into-view, and Leaf focuses the marker with `preventScroll`, so a user's tap scrolls the page in neither version. The stale box itself is already on `main`. In the same sequence without the press, the marker's box and `elementFromPoint` at the place it is painted lagged the scroll in 6 of 12 runs on `main` and 4 of 12 on the branch (p = 0.68), for 28–30 frames either way. During that half second, a press where the marker is painted doesn't reach it; whether the paint lags too wasn't checked. The rate at which Playwright's check lands in the lag does depend on the version in this harness: under reduced motion the branch scrolled in 11 of 32 click runs and `main` in none (p = 0.0003), while under normal motion it was 3 of 13 each. A test that clicks a margin marker on a phone right after an instant scroll may therefore meet Playwright's scroll more often on this branch. The lag is the defect to fix, and it belongs to its own change. Not measured: frames during motion, and a WebKit keyboard route. ## Checks - The new test passes, and fails with the rule restored. - `tests/browser/test_render_gate.py -k` over the no-theme breakout table, the root scrollport's sideways room, page overflow beside an authored scroller, the page edge and the too-wide table: 6 passed. - `tests/journeys/test_plain_pages.py`: 9 passed, 3 xfailed with the updated pins. In `tests/journeys/test_render_gate.py`, the page that scrolls sideways only between viewports, what a column loses, and a box its container clips away: passed. - `pnpm run check`, which includes the runtime's 750 tests and the kernel comparison: passed. `uv run pre-commit run --files` on the changed files: passed. > _This was written by Claude Code on behalf of max-sixty_
Leaf’s final page geometry was defined in the runtime-only chrome stylesheet, so authored HTML painted promptly but moved several seconds later when the module graph finished loading. Move the live shell’s banner, scrollbar, rail, and workspace geometry into the render-blocking theme, and let the inline bootstrap project a reader’s saved panel or tray dimensions before that theme paints.
At the catalog’s 1724×1036 viewport, the main box now stays at x=218, y=42, width=768 before JavaScript, through an artificial one-second runtime hold, and after presentation. The production-route measurement falls from roughly 0.094 CLS to 0.001; under 100 ms latency and 4 Mbps throttling, authored content paints around 0.8 seconds while Leaf completes in the background around 3.4 seconds.
The browser coverage holds startup at the module and state boundaries across desktop, compact, touch, saved-panel, saved-tray, catalog, and data-backed example cases. This stabilizes authored shell geometry; source-dependent content inside an otherwise empty data widget still takes space when its data arrives.