Repository navigation
Studio: let a settled thread skip the code blocks it is not showing - #9047
danielhanchen wants to merge 5 commits into
Conversation
The visual recordSame scene, same scroll offset, thread sitting still, on two builds of Studio: Quantified rather than eyeballed, because two screenshots that look alike is also what a broken
The last row is the attribution: nothing about the attribute, the signal component or the scoping There is no photograph of the flicker frame in here. The event is one frame; CPU throttling |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9223d06717
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| rootRef: RefObject<HTMLElement | null>; | ||
| settleMs?: number; | ||
| }): null { | ||
| const isRunning = useAuiState(({ thread }) => thread.isRunning); |
There was a problem hiding this comment.
Keep code blocks held while thread history loads
When opening a saved thread whose history takes longer than the two frames plus 900 ms to load, thread.isRunning remains false, so this signal marks the root settled before any messages mount. This is realistic because the history adapter awaits both stored messages and research state (runtime-provider.tsx:1302-1325), while the UI separately recognizes thread.isLoading (thread.tsx:1666-1669). Code blocks that arrive afterward therefore have no remembered size but immediately regain content-visibility: auto, causing off-screen blocks to use the 200 px fallback and shift the thread when reached. Treat loading as a building state and arm release only when both loading and running are false.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, and reproduced. The controller is only ever handed thread.isRunning (code-block-layout-signal.ts:38 and :64); thread.isLoading is never consulted, so a thread whose history mounts after the settle window arms release with nothing remembered. Measured with the seed delayed 3s past the window at 100K chars: 18 of 20 blocks sit at the 200 px placeholder on Chromium, 17 of 21 on WebKit, 19 of 20 on Firefox, scrollHeight 25,944 against 45,297, and sweeping the thread shifts content on 18 of 60 frames with a worst shift of 1984 px. The merge base shows 0 shift frames and the correct height in the identical scenario. Noting for the record that this branch is being recommended for closure on separate grounds, so the fix is being recorded here rather than applied: gate release on thread.isLoading, isResearchActive and isQueueRunning as well as isRunning, or re-arm on message-count change.
Verification before merge: recommending this branch be closedNot because it is wrong. Because its only real win is Chromium-only, is confined to one action, is removed entirely by #9051, and it costs measurable scroll roughness on WebKit and layout shift on Firefox. The mechanism, which is realAn earlier attempt at this measured nothing, and the reason turns out to be scope rather than a property of Why that does not justify mergingThat entire bucket is what #9051 removes. Chromium, 300K characters, medians with [min, max], n=12 per arm.
Stacked on #9051 this branch buys nothing on any axis. On the actions #9051 does not touch it is flat against base: scroll 0.99, re-open 0.94, delete 0.96, keystroke 1.00, which matches this PR's own claim that it does not speed up scrolling. The one consistently signed effect it has left when stacked is layout time going up, which is the cost of un-skipping a block on the way in. Cross engine, where it gets worseWebKit 26.5 shows no menu win at any size (0.89, 0.98, 0.89 at 25K, 100K, 300K) and a scroll regression whose spreads do not overlap at 25K or 100K:
That is the scroll roughness axis this branch was written against, moving the wrong way, on the engine Desktop ships on macOS and Linux. Playwright WebKit is a proxy for WKWebView and WebKitGTK, not those webviews. Firefox 153 does support What was verified as unaffectedAt rest on Chromium and WebKit the rendered output is identical: same body text hash, same A gap in the tests worth recordingReverting If it is kept anywayGate release on Absolute milliseconds are inflated: the box was under heavy concurrent load throughout. The tight A/B alternation is what makes the ratios usable, and the ratios are the argument. |
Two corrections and a piece of prior art that settles the WebKit questionFirst, a correction to how I described this changeI called this "applying content-visibility to code blocks". That is wrong, and the distinction matters for the argument. Streamdown already sets .aui-thread-root [data-streamdown="code-block"] {
content-visibility: visible !important;
contain-intrinsic-size: none !important;
}So this branch does not add the optimisation. It narrows an existing local override, letting the library's own default apply once the thread is settled, and stops clobbering That makes the honest framing "should we keep overriding upstream in the settled state", not "should we add a rendering change". It does not change the conclusion below, but the earlier wording overstated the novelty. Second, the prior art, which is about correctness rather than speedOpen WebUI shipped exactly this optimisation and then had to gate it off for WebKit: open-webui#26805, merged 2026-07-24, "fix: blank chat messages on Safari caused by content-visibility virtualization". Their description is the part that matters here:
That is not a performance regression, it is content that does not appear. It bears on us directly because Desktop ships two WebKit variants, WKWebView on macOS and WebKitGTK on Linux, and a code block that paints blank is a correctness failure rather than a trade. Of the three bugs they cite, only 283846 is resolved (fixed 2025-03-30, in 292919@main), which is consistent with find-in-page and select-all passing here on WebKit 26.5. 277573 and 281570 were not verified. And what was tested here is Playwright's WebKit, which is a proxy for WKWebView and WebKitGTK rather than either of them, so the engines Desktop actually embeds were not exercised at all. Taken with the WebKit scroll regression already measured (frames over 33 ms going 0 to 5 at 25K and 1 to 6 at 100K, non-overlapping spreads), and with the fact that the Chromium win is removed entirely by #9051, the recommendation to close stands and is stronger than it was. If it is kept, it should be gated off WebKit explicitly, the way Open WebUI ended up doing, in addition to the release-gate fix noted on the inline thread. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9125a139da
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| rootRef: RefObject<HTMLElement | null>; | ||
| settleMs?: number; | ||
| }): null { | ||
| const isRunning = useAuiState(({ thread }) => thread.isRunning); |
There was a problem hiding this comment.
Hold blocks while edited responses remount
When a user saves an edit to a completed assistant response, thread.tsx:6480 switches from the textarea back to MarkdownText, creating fresh code-block elements, and update-thread-message.ts:134 imports the edited repository while the thread remains non-running. Because this signal only observes thread.isRunning, a root that was already settled is never put back into building; in a long response, its newly mounted off-screen blocks therefore immediately use Streamdown's 200 px intrinsic fallback and the thread shrinks and grows again as those blocks are reached. Re-arm the layout hold for this non-streaming message remount path as well.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, and fixed in 8caa9dc.
Reproduced at frame level in Chromium 151 on a 2,169px code block that is in view, recording [frame, block.offsetHeight, top of the following element]:
released [0, 200, 301], [1, 2169, 2269.75], [2, 2169, 2269.75], ...
held [0, 2169, 2269.75], [1, 2169, 2269.75], ...
Released, the remounted block paints one frame at streamdown's 200px contain-intrinsic-size fallback and everything below it moves 1,969px and back. Held, frame 0 is already the real height and nothing moves. That is the same reload-style flicker the CSS comment in this change exists to kill, so it is in scope by this PR's own standard.
The mechanism is as you describe, with one correction to the citation: the switch is at thread.tsx:6921, not 6480 (6480 is inside ContinueMessageBarForLastMessage). The edit state is read at thread.tsx:6849 and the save is at 6870-6896. The two branches at 6921 are different element types, a div and a fragment, so React unmounts one subtree and mounts the other rather than reconciling in place, which guarantees the remount. code-block-layout-signal.ts:38 and update-thread-message.ts:134 are both accurate.
Why the fresh element has nothing to fall back on, per css-sizing-4 section 5.2: the last remembered size is used only 'if auto is specified and the element has a last remembered size', and a never-rendered element has none, so the length branch applies. css-contain-2 section 4.3 names the same case: 'only freshly-loaded tweets will be forced to rely on the 200px height estimate'.
The fix adds a remeasure() entry point to the controller and calls it from a useLayoutEffect keyed on the editing message id. useLayoutEffect rather than useEffect is load bearing: a passive effect runs after the browser has painted the commit that created those elements, and that paint is the flicker frame.
Two properties of remeasure() that the tests pin, because both are easy to get wrong: it is deliberately not idempotent, since two saves in a row are two remounts and each needs its own settle window; and it does not arm a release while a run is in flight, or a remount landing mid-stream would settle the thread inside the reply that is still writing into it.
Four cases added to the existing pure decision-module tests. Suite is 4122 pass, 0 fail.
One related case this does not cover, recorded rather than folded in: expanding a collapsed reasoning or tool section on a settled thread is the same remount shape, since components/ui/collapsible.tsx wraps Radix CollapsibleContent with no forceMount. The general fix is a MutationObserver on the thread root that watches for added code-block nodes while settled, and remeasure() is already the primitive it would call. Left for a follow-up because the expand path was not instrumented here.
Closing thisThe measurements above settle it, and the standing rule we are working to makes the call straightforward: we do not change what the user sees unless performance improves dramatically enough to justify it. This changes what the user sees on one engine and, once #9051 lands, improves nothing on any of them. Three findings, in the order that decides them. The Chromium win is not this branch's to claim. Stacked on #9051 it buys nothing on any axis: menu open and close 1.00, recalc 0.90, longest stall 0.94, scroll 0.94, re-open 0.99, delete 1.00. On the actions #9051 does not touch it is flat against base. The entire measured benefit lives in the bucket #9051 removes, and #9051 removes it more completely. On WebKit it moves the axis it was written against, the wrong way. Frames over 33 ms go 0 to 5 at 25K and 1 to 6 at 100K, with non-overlapping spreads, and there is no menu win at any size. That is the engine Desktop ships on macOS and Linux, through WKWebView and WebKitGTK. On Firefox it changes the layout. Each skipped block renders 24 px shorter, the thread 456 px shorter, and scrolling up shifts content on 36 of 60 frames against 0 on base. That is a visible difference at rest, not deferred work, and it is disqualifying on its own. The prior art is the part I would want kept if anything from this is revisited. Open WebUI shipped this same optimisation and then had to gate it off for WebKit in open-webui#26805, because Safari's Two things worth recording before this closes. The framing in the original description was wrong and I corrected it above: this does not add And a gap that is worth more than this PR: reverting Closing rather than reworking. The reasoning stays here so it survives the closure. |
index.css disables streamdown's content-visibility on every code block in the thread, unconditionally. The flicker it was added for is real: the code-block node is REPLACED when its fence closes, so the block that finishes streaming has no last remembered size and lays out at the 200px fallback for a frame. Measured on this tree, 1722px to 226px and back, once per fence. The reason given for making it unconditional is not real. The comment says the optimization is unnecessary because thread length is bounded, and threads run to 300K characters and 43,422 DOM nodes. So hold the override rather than keep it: while the thread is building, while a message part is running, and while a fence is still open. Release once the thread is quiet, by which point every block has been laid out at its real height at least once and `contain-intrinsic-size: auto` will skip it at that height rather than at the guess. Stop overriding `contain-intrinsic-size`. Clobbering it to `none` removes the `auto` keyword, and CSS Sizing 4 erases the last remembered size the moment that keyword goes, which is the measurement a release depends on. The scroll gesture this was written against does not move: of the 700ms it costs at 300K, layout and style are 13.5ms. The message action menu does, 3809ms to 963ms at 300K, and the attribution says why: 3180ms of style recalculation becomes 541ms.
9125a13 to
ad68bc9
Compare
|
Reopening this, because I closed it on a premise that turned out not to apply to what it actually does. I closed it alongside the block-list windowing idea, which measurement did contradict. This is a different mechanism: the Rebased onto current main. The NumbersMeasured on a real Studio at the 100K rung, 390,740 seeded characters, 4 repetitions with both arms interleaved inside one session, CPU-pinned, scored against a null control running under the same load.
Paired spread on the close figure is 1.0% against a detection floor of 0.6%, so the effect is roughly a hundred times the noise. It reproduces on three independent measurements: 89.0% at the fast tier, 87.4% against the raw branch head, 87.7% rebased. Different films, different sessions, different bases. One caveat I want on the recordMeasured against the raw branch head this PR also appeared to make the message menu 2.5x slower. It does not. The branch predated #8992, which took that menu from 1,077 ms to 52 ms, so the comparison was charging this branch for the absence of a fix that landed after it was cut. On the rebased build the menu difference disappears into the noise floor, while the reasoning pane result is unchanged. Worth knowing for anyone measuring a stale branch against current main. UI parity across the eighteen scripted actions shows no difference in what is rendered. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ad68bc922b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| .aui-thread-root:not([data-code-block-layout="settled"]) [data-streamdown="code-block"], | ||
| .aui-thread-root [data-status="running"] [data-streamdown="code-block"], | ||
| .aui-thread-root [data-streamdown="code-block"][data-incomplete] { | ||
| content-visibility: visible !important; |
There was a problem hiding this comment.
Re-measure blocks after typography or width changes
When a settled thread is resized across the 36rem container breakpoint (index.css:2454-2461) or the user changes the code-font size in Appearance settings (index.css:623-627), off-screen blocks remain skipped even though their real heights have changed. Their contain-intrinsic-size: auto value therefore continues using the size remembered before the style change, and each block can resize and shift the thread when the user later scrolls it into view; CodeBlockLayoutSignal cannot re-hold them because it observes only thread.isRunning. Re-enter the building/measurement state for geometry-affecting changes before allowing these blocks to skip again.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
The stale remembered size is real and I reproduced it, but nothing the user sees moves, so this is not a defect to fix here.
Reproduced, block above the viewport, thread settled:
rendered: 2030px scrollHeight 10030
skipped, remembered: 2030px scrollHeight 10030
skipped after font 14 -> 24: 2030px scrollHeight 10030 stale, no re-measure
rendered after the change: 6959px scrollHeight 14959 corrected on render
and the spec says it should behave that way. css-sizing-4 section 5.2.1 records a new size only at ResizeObserver delivery time and only for an element that 'does not have size containment'; a skipping element has size containment. css-contain-2 section 4.5: 'the skipped contents of an element never change their size'.
The reason this is a reject rather than a bug: the invariant this change maintains is that a block must have been laid out at its real height at least once before it may skip. Here it has been. The recorded value is simply the pre-change one, and the engine re-records automatically the next time the block stops skipping. That is the designed behaviour of contain-intrinsic-size: auto, not a hole in it. Contrast the sibling item on the edit remount, which throws the measurement away entirely and falls back to a 200px guess, a 91 percent error, on an element the user is looking at.
And no content moves. Same fixture, 4000px gaps, marker element measured before and after:
before the change: marker top 280.75 scrollTop 9889 block 2169 scrollHeight 14209
after the font change: marker top 280.75 scrollTop 9889 block 2169 scrollHeight 14209
after scrolling into it: marker top 3280.75 (280.75 + the 3000 scrolled) block 3719
The marker's viewport position is bit-identical across the change, and Chromium's scroll anchoring absorbed the full 1,550px when the block was scrolled into. The chat viewport does not opt out: grep for overflow-anchor across src returns only the hub catalog, the research panel and the debugging tab, never the thread viewport. What is left is a scrollbar thumb proportioned to the old typography, which css-contain-2 section 4.3 names as the known cost of the feature.
The width half of the item does not reach the state at all. index.css:2523 gives code blocks overflow-x: auto and pre stays unwrapped, so code-block height is independent of container width. The 36rem container query bites only by changing font-size, so it collapses into the case above rather than being a second one.
Finally the cost. Re-entering the building state for geometry-affecting changes means forcing content-visibility: visible on every block in the thread, a full re-layout of a 300K-character thread, on each commit of an Appearance slider and on window-resize frames, to correct a scrollbar the user cannot act on. That spends the thing this change was built to buy on a defect nobody sees.
Measured: CONFIRMEDProtocol: studiobench standard tier, 100K rung, 4 repetitions split into 2 shards, with an in-band null control running concurrently under the same load, scored through the three gates (per-metric detection floor = This clears all three gates.
UI parity is clean across 64 action pairs. What was measuredThe branch was measured rebased onto current main, not at its raw head. That matters: a raw head is compared against the main it was cut from, so the delta it reports includes every commit that has landed since the branch was cut. On a branch of this age that is not a small correction, and it is the difference between measuring this change and measuring branch age. Unrelated, but before mergeCI on this PR is currently red. The failure is an assertion in The |
Resolves the thread.tsx import conflict by keeping both sides: main's CompactionNotice and context-truncation imports alongside this branch's CodeBlockLayoutSignal. Also adds the /crypto-boot.js script to smoke-code-block-flicker.html. Main gained a repo-wide assertion in tests/crypto-uuid-boot.test.ts that every smoke page loads it before its module entry, and this branch's page predates that rule, which is what turned the Linux and Windows frontend jobs red.
Leaving the edit textarea on a completed reply swaps the whole message body back for its rendered parts, so React mounts a brand new element for every code block in that reply. The signal only watched thread.isRunning, so a thread that had already settled stayed settled, and those fresh elements have no last remembered size: Chromium lays them out at streamdown's 200px contain-intrinsic-size fallback for one frame. Measured in Chromium 151 on a 2,169px block that is in view. Released, it paints one frame at 200px and everything below it moves 1,969px and back. Held, it is 2,169px from the first frame and nothing moves. useLayoutEffect rather than useEffect is load bearing: the attribute has to be back on the root within the commit that created those elements. A passive effect runs after the browser has painted that commit, and that paint is the flicker frame. remeasure() is deliberately not idempotent, because two saves in a row are two remounts and each needs its own settle window, and it does not arm a release while a run is in flight, or a remount landing mid-stream would settle the thread inside the reply still writing into it.
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8caa9dc026
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| rootRef: RefObject<HTMLElement | null>; | ||
| settleMs?: number; | ||
| }): null { | ||
| const isRunning = useAuiState(({ thread }) => thread.isRunning); |
There was a problem hiding this comment.
Re-arm the hold when switching response branches
When the user clicks the existing branch picker in thread.tsx:7648-7682, assistant-ui can replace the displayed completed response with a sibling containing a different set of fenced blocks while thread.isRunning remains false and editingMessageId is unchanged. A root that is already settled therefore stays released, so newly introduced off-screen code-block elements have no remembered size and initially use Streamdown's 200px fallback, causing the same large layout shifts this change is intended to prevent when that branch is viewed or scrolled. Observe the selected branch/message revision and call remeasure() for this non-streaming remount as well.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, and it is broader than the branch picker. Two paths remount the same Streamdown subtree without going through editingMessageId: switching response branches, and expanding a settled reasoning pane. markdown-text.tsx:521 keys Streamdown on ${messageId}:${renderGeneration}, and each path changes one of those.
Measured on the real Thread with the real stylesheet, sampling offsetHeight and the top of the following element per frame:
| path | before | after |
|---|---|---|
| edit | clean | clean |
| branch | 1 frame at 226px instead of 1760px | clean |
| reasoning | 3 frames at 226px instead of 1760px | clean |
That is a 1534px collapse of the column and a snap back.
Rather than add a second useLayoutEffect per path I replaced the effect with a MutationObserver on the thread root, connected only while the controller is settled and disconnected before it reports. A MutationObserver callback is a microtask scheduled after the mutation, so whether it lands before the paint is an empirical question rather than one to reason about. I probed it against the real rule shape: it is frame-identical to a synchronous restore, and identical whether the mutation comes from a plain task, from inside a requestAnimationFrame callback, or from a microtask. That is why the layout effect could be removed rather than kept as a belt.
Termination has two independent reasons and the tests assert both: the disconnect happens before onRemount, and remeasure()'s only DOM effect is an attribute write on the observed root while the observer records childList only.
tests/studio/playwright_code_block_remount.py drives all three paths through the real components and gates on both directions, so it fails if the hold stops working and also if the fixture stops reproducing the collapse. npm test 4130 pass / 0 fail, 8 new.
|
Benchmarked at this head (
UI parity clean across 64 action pairs. Two earlier standard-tier sessions on a rebase of this The regression, stated up front rather than left to be found
It showed +8.9% (void), +20.7% and +28.8% across three sessions, and in the run above both shards Bounding it honestly:
So it is a small absolute cost on a rare action, bought in exchange for 840 ms -> 304 ms on a Method notesBoth numbers above come from the merged head, not from a raw branch head. Measuring a branch that The rung matters too. At the 10K rung every metric here reads as a null, including the -63.5%. The |
…path
The layout hold was armed from a useLayoutEffect keyed on editingMessageId,
so it only covered the edit round trip. Two other paths remount the same
Streamdown subtree and were left uncovered: switching response branches,
and expanding a settled reasoning pane. markdown-text.tsx keys Streamdown
on `${messageId}:${renderGeneration}`, and both paths change one of those.
Measured on the real Thread with the real stylesheet, sampling offsetHeight
and the top of the following element per frame:
path head with the watcher
edit clean clean
branch 1 frame at 226px instead of 1760px clean
reasoning 3 frames at 226px instead of 1760px clean
A 1534px collapse of the column, then a snap back.
Replaced the effect with a MutationObserver on the thread root, connected
only while the controller is settled and disconnected before it reports.
A MutationObserver callback is a microtask, so the question of whether it
lands before the paint is empirical, not a matter of reasoning: probed it
against the real rule shape and it is frame-identical to a synchronous
restore, from a plain task, from rAF and from a microtask alike. That is
why the layout effect could be removed rather than kept as a belt.
Termination has two independent reasons and the tests assert both: the
disconnect happens before onRemount, and remeasure()'s only DOM effect is
an attribute write on the observed root while the observer records
childList only.
New harness tests/studio/playwright_code_block_remount.py drives all three
paths through the real components and gates on both directions, so it
fails if the hold stops working and also if the fixture stops reproducing
the collapse.
npm test 4130 pass / 0 fail (8 new).
|
Pushed b77c5ef. The review's branch-picker item was right, and generalising it found a third path. The hold is now armed by a
|
|
@codex review |
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Closing this in favour of #9462, which reaches the same goal by a different mechanism and does not carry the costs this one does. The measurementBoth were measured at the 100K rung against a concurrent in-band null. #9462 wins on every metric except one:
The select-all regression replicated three separate times with both shards agreeing, and it has a known mechanism rather than being noise: Why that is disqualifying hereThree differences, and it is worth separating them because they are not the same kind of thing. The select-all cost is not a parity break. The selection contents, the clipboard payload and the character count are all unchanged; the spec keeps skipped content selectable. But it is a UX difference the user is on screen to pay: they press Ctrl+A and wait 28.8% longer. The off-screen exemption does not cover it. That exemption licenses not rendering what is not visible, and this is the bill for that licence coming due the moment someone performs a document-wide operation. A 1.82% on-screen pixel delta. 18,427 of 1,014,800 pixels differ. Find-in-page breaks on WKWebView below Safari 26 (webkit.org/b/283846): skipped content is not findable. That is a genuine parity break rather than a slowdown, and it lands on the macOS desktop app. A dramatic performance win can justify a deliberate UI difference, but only where the difference is necessary to obtain the win. #9462 gets a larger win on the same rung with none of these three: scroll height unchanged to the pixel, selected character count unchanged, and the text stays a live text node, so selection, clipboard and find-in-page are structurally unaffected. The two mechanisms do not composeThey would fight. The remount observer here fires on any added node matching It is also worth recording that the state machine and the remount observer are not a separable win. They never read, store or restore a height; the only height memory involved is the engine's own last remembered size, armed by leaving Two things in this PR's favour, for the recordI would rather these be on the thread than discovered later. #9462 is default-off. Its deferral sits behind #9462's win is contingent; this one's was not. Its own numbers rest on 55 of 56 fences never being reached. A reader who scrolls their whole history converges back on today's cost plus the observer overhead. Skipping an off-screen block does not have that property: it applies whenever the block is off screen, however much was read earlier. So "#9462 dominates" is true on the metrics and not yet true on what users actually get. It is still the right direction, because closing that gap from this side would cost the select-all regression, the rasterisation delta and the WebKit find-in-page break, which is the wrong trade. If the full-scroll case turns out to matter, the follow-up should be a mechanism that does not reintroduce those. This is not a CI judgementAll 35 red checks here are janitor cancellations, not failures. Sampled jobs return What survivesThe flicker harness, as its own no-behaviour-change PR. It runs against main unmodified and is the only executable proof that the existing |
|
The harness is now #9464, cut against main with no behaviour change: 20/20 green against the tree as it ships. |

What this changes
studio/frontend/src/index.cssdisables streamdown's rendering optimization on every code blockin the chat thread, forever:
The flicker it was added for is real and is reproduced below. The reason given for making it
unconditional is not: the comment says "the rendering optimization is unnecessary for chat content
(thread length is bounded)", and #9016 measured threads from 25K to 300K characters, 20 to 220
messages and 4,048 to 43,422 DOM nodes.
So the override is scoped rather than removed. It is held while the thread is building, while a
message part is running and while a fence is still open, and released once the thread is quiet.
Read the numbers before the description: this does not speed up scrolling. It was written
against the scroll roughness in #9016's table and that number does not move. What it does move is
the message action menu, by 4.0x at 300K characters, and the reason is in the attribution below.
The flicker, reproduced first
tests/studio/playwright_code_block_flicker.pymounts the realThread, streams a reply endingin code fences, and records every code block's rendered height on every frame.
Against streamdown's own defaults, that is the tree before the override existed, each fence does
this on the frame it closes, three times per reply, in all three repetitions:
226px is streamdown's inline
contain-intrinsic-size: auto 200pxfallback plus the wrapper'spadding and its language header. The cause is not the IntersectionObserver on its own: the
code-block DOM node is REPLACED when its fence closes.
StreamdownBlockContentreturns a bare<Block>while the fence is open and a<Block>wrapped in<div className="relative isolate">once
getCodeFencematches, and React reconciles a changed element type by unmounting andremounting. CSS Sizing 4 attaches the last remembered size to the element, and both Chromium and
WebKit clear it when the element is disconnected, so the block that finishes streaming is a new
element with nothing recorded and is laid out at the fallback until the engine decides it is
close enough to the viewport to render it.
Why the override must keep
contain-intrinsic-sizealoneThis is the part that makes releasing safe, and it is why the second declaration is deleted
rather than rescoped.
CSS Sizing 4 §5.2.1: the last remembered size is recorded whenever an element has the
autokeyword in
contain-intrinsic-sizeand is not skipping its contents, with no condition oncontent-visibility; and it is ERASED as soon as that keyword goes away. Overridingcontain-intrinsic-sizetononetherefore does not merely fail to help, it throws away themeasurement that a later release depends on.
Measured on Chromium 151.0.7922.34, WebKit 26.5 and Firefox 153.0, switching a column of rendered
off-screen elements from
content-visibility: visibletoauto:contain-intrinsic-size: auto 200pxcontain-intrinsic-size: noneSo a block that has been rendered once keeps its exact height when it starts skipping, and that
is what the hold guarantees for every block.
The simpler scopings, measured rather than assumed
Same fixture, same three repetitions, every variant applied as a stylesheet after the tree's own
so only the code-block rules differ.
collapsesis the flicker;sweep shiftis frames in whicha block's document-space top moved while scrolling from the bottom of the thread to the top,
which is the page moving under the user.
Chromium 151.0.7922.34 and WebKit 26.5, three repetitions each, per-repetition collapse counts
in brackets.
[data-status="running"]Worst single shift during the sweep is 933px on every variant that shifts at all, on both engines.
Two results decided the shape of the fix:
statusonlystill flickers. Scoping by the streaming status alone is the obvious CSS-onlyanswer and it does not work: the node replacement at fence close can land in the same commit
that flips the message out of its running status. Every Chromium repetition caught it and one
WebKit repetition in three did. That is what the settle window after the run ends is for, and
an intermittent failure is a worse thing to ship than a reliable one.
lastmessagetrades the flicker for a worse sweep. It survives finalization, since themessage being finalized is the last one, but it can never give an earlier message's blocks a
first render, so a freshly opened thread holds every off-screen block at the fallback and
scrolling back up moves 5,601px of content around.
What it costs and what it buys
tests/studio/playwright_heavy_thread.pyfrom #9016, unchanged, run against two worktrees thatdiffer only by this change. Five rounds, alternating which side goes first, three repetitions
inside each run, so each cell is the median of five medians. Chromium, vite dev server, on a
shared machine at a load average between 40 and 80: the ratios are the result, the milliseconds
are context.
The message action menu, open and close
The five per-round medians do not overlap at any size (300K: main 3695, 3836, 3917, 3809, 3534;
this change 971, 946, 1183, 963, 873).
Chromium's
Performance.getMetricssays exactly where it went, and it is one line:The Radix modal layer puts
document.bodyintopointer-events: nonewhile the menu is open, sostyle is invalidated for the whole thread twice for a three-item popover. A skipped subtree does
not take part in that, and the 300K thread holds 55 code blocks, all of which are eligible to be
skipped once it settles.
Scrolling, which is what this was written against, and which does not move
The attribution is the answer. Of the 700ms of task time the gesture costs at 300K, layout and
style are 13.5ms, under 2%. #9016 read the scroll as "the layout is already done at mount, so the
per-gesture cost is roughly per pixel", and that is right, but it is the reason there is nothing
here to win: the per-pixel cost is paint and raster of what is on screen, and skipping off-screen
content does not reduce it. What skipping does change is visible in the two rows that did move,
layout and style going UP, because a block entering the live region has to be rendered on the way
in. That is a real cost and it is 3ms per gesture at 300K.
Bottleneck 5 in #9016's table is therefore not addressed by this, and I do not think
content-visibilitycan address it. Whatever the 700ms is, it is not layout and not style.Everything else
What it looks like
Same scene, same scroll offset, thread sitting still, on two builds:
antialiasing on the long
deflines inside horizontally scrollable code blocks. Opened at 4xand at 10x: identical glyph shapes, identical positions, identical colours, different
antialiasing fringes.
content-visibilityforced back tovisibleis byte-identical to main,which attributes the whole difference to
content-visibility: autoand none of it to theattribute, the signal component or the scoping.
content-visibility: autoapplies layout, styleand paint containment whether or not the element is skipped, and that changes how Chromium
rasterizes text in a scrollable code block.
There is no photograph of the flicker frame itself in here, and that is a limitation rather than
an omission. The event is one frame; CPU throttling stretches the frame but a CDP screenshot still
captures the composited frame after the relevance update, so every attempt produced a picture of
the block already correct. The frame-level height log above is the evidence for it.
Trade-offs worth stating
find-in-page, tab order and the accessibility tree, and Chromium and Firefox implement that.
Safari shipped
content-visibility: autoin 18 with skipped content NOT findable and fixed itin Safari 26 (WebKit bug 283846). Unsloth Desktop on macOS is WKWebView, so on a system older
than Safari 26 a code block that is currently skipped will not be found by the browser's own
find. This is streamdown's default behaviour that the override had been suppressing.
Measured rather than reasoned: closing and re-opening all 8 tool result panes on a settled 100K
thread, three repetitions per side, produced 0 collapses and 0 placeholder frames on both sides.
The pane mounts where the user clicked, so the block is on screen and is rendered rather than
skipped.
checkVisibility({ contentVisibilityAuto: true })answeredtrue, and a child'sgetBoundingClientRect()came back at its full 800px, onboxes provably skipped at the 202px placeholder: reading layout out of skipped content forces the
engine to render it. The evidence that skipping is happening is the style-recalculation collapse
above, not a count.
Tests
studio/frontend/tests/code-block-layout-controller.test.ts, 9 tests over the release statemachine with an injected clock, and
tests/studio/test_code_block_flicker_contract.py, 22 testsover the flicker detector against hand-written frame logs including the ones it must NOT report,
plus the two rules this change rests on.
Every test was run against a deliberately broken tree, 26 mutations in all, and every mutation is
caught by at least one test and every test fails against at least one mutation. A few of the
pairings:
contain-intrinsic-size: noneput back on a thread code blocknpm test2945 passed,npm run typecheckclean,npm run buildclean, biome clean on the newsource files.
Notes for review
studio-frontend-ci.ymlis where the new smoke would go and Studio: measure where a heavy thread stalls, across engines and thread size #9016 is alreadyediting that file; this can be folded in when one of them lands.
tsconfig.app.jsongains one line in the same list Studio: measure where a heavy thread stalls, across engines and thread size #9016 adds one to, so those two will conflicttrivially on whichever merges second.