Skip to content

fix(app): stop restyling every timeline row when one changes height - #65692

Closed
Hona wants to merge 1 commit into
devfrom
fix-timeline-restyle
Closed

Hona wants to merge 1 commit into
devfrom
fix-timeline-restyle

Conversation

@Hona

@Hona Hona commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Every mounted timeline row was restyled on almost every frame while scrolling through history or streaming a reply, and on each focus change in the timeline. Two CSS rules caused it.

Discovery

Before (dev) This PR
  • One headless Chrome trace per side: 4 s of middle-button autoscroll up through unvisited history of a real session. This is noisy discovery evidence. The strobe blocks under Results are the measurement.
  • Chrome's invalidation tracking named the trigger: the inline height write on [data-timeline-virtual-content] scheduled a :has() invalidation on the scroll root, which invalidated its whole subtree.

Cause

flowchart TD
  A["A row is measured, or a reply grows"] --> B["The virtualizer writes the content height inline"]
  B --> C{"Does a selector read [style] inside :has()?"}
  C -- "yes: markdown.css" --> D["Chromium rechecks each :has() anchor above the write"]
  C -- "no" --> G["Only that element is restyled"]
  D --> E{"Does the anchor's rule style another element?"}
  E -- "yes: timeline focus ring" --> F["Everything inside the scroll root is restyled: every row"]
  E -- "no" --> H["Only the anchor is restyled"]
Loading
  • Trigger (feat(app): wrap long lines in timeline code blocks #64545): markdown.css matched :has(> pre:not([style*="background"])). With style inside a :has() argument, every inline style write in the document is a change that :has() can depend on.
  • Blast radius (fix(app): draw the whole timeline focus ring with rounded corners #65192): the timeline's focus ring was [data-slot="session-timeline-scroll"]:has(…) ~ [data-slot="session-timeline-visible"]::after. When the rule after :has() styles another element, Chromium invalidates the whole subtree of the anchor. Here the anchor is the scroll root.
  • The ring rule alone also restyled every row on each focus change in the timeline: a click, or the first key press after one.

Change

  • Code blocks: the wrapper of a highlighted pre records data-code-painted when it is built. The rule reads that attribute instead of style.

    /* before */
    [data-component="markdown-code"][data-code-kind="shell"]:has(> pre:not([style*="background"])) { … }
    /* after */
    [data-component="markdown-code"][data-code-kind="shell"]:not([data-code-painted]) { … }
  • Focus ring: the ring is the scroll root's own ::after, so :has() stays on the element that it styles. The box, colour, radius and stacking are the same.

    /* before */
    [data-slot="session-timeline-scroll"]:has(> .scroll-view__viewport:focus-visible)
      ~ [data-slot="session-timeline-visible"]::after { … }
    /* after */
    [data-slot="session-timeline-scroll"]:has(> .scroll-view__viewport:focus-visible)::after { … }
Focus ring before Focus ring, this PR
Standalone reproduction: elements restyled, counted from Chrome's UpdateLayoutTree events
<style>
  .code:has(> pre:not([style*="background"])) { --bg: 1 }                 /* markdown.css */
  .viewport:has(> .inset) { scroll-padding-top: 16px }                     /* index.css, unchanged */
  .root:has(> .viewport:focus-visible) ~ .visible::after { content: "" }   /* index.css, the focus ring */
  .card:has(.badge) * { outline-color: red }                               /* any :has() followed by a broad selector */
</style>
<div class="root">
  <div class="viewport" tabindex="0">
    <div class="inset"></div>
    <div class="content" style="height: 9000px"><!-- 120 rows, 1,680 elements --></div>
  </div>
</div>
<div class="visible"></div>
Rules content.style.height = … Focus change on the viewport
All four, as on dev 1,685 1,686
Code rule fixed only 1 1,686
Ring fixed only 3 3
Both fixed (this PR) 1 3
dev without the fourth rule 3 3
  • The fourth rule stands for the app's other :has() rules. Without one, a page does not show the problem.
  • Either fix alone stops the restyle on a height write. The code rule also stops Chromium from rechecking :has() on every inline style write.

Results

strobe compares stream.bench.ts "stream a reply" and timeline.bench.ts "scroll history" against origin/dev. Its block for each follows.


Added by the opencode bot (AI-generated).

Related: #54291

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I found nothing that should block this.

I ran the markdown and code-wrap component tests (62 passed) and the session-ui unit tests (204 passed), and tsc -b passed in app and session-ui. Checking the code:

  • pre.style.backgroundColor matches what [style*="background"] used to: the markdown sanitiser only keeps background-color in style.
  • Streamed and code-mode blocks never get the flag, so shell colours still apply to them.
  • The ring on the scroll root's ::after covers the same area as before. The root has no stacking context, so z-index: 40 still draws it above the header.

I couldn't reproduce the every-row restyle on the base with a standalone Chromium page using the old and new selectors: inline height writes cost the same on both. Focusing the viewport restyled 3 elements on the base and 1 with this change. So the evidence for the full win is still your traces and strobe results.

Public API: unchanged. These are app CSS and DOM changes only; data-code-painted is a new internal attribute.

Related: #54291

@Hona

Hona commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Superseded: dev now has both causes fixed.

@Hona Hona closed this Nov 23, 2026
@Hona
Hona deleted the fix-timeline-restyle branch November 23, 2026 03:54
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.

1 participant