Skip to content

[Bug]: ComposerBanner's + :has() variant makes banner changes restyle the whole page on every thread switch #13851

Closed

Description

@CaceresCallieri

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/web

Steps to reproduce

  1. Build main (measured at 95030dc674) and open the web app in Chromium with a populated sidebar.
  2. Record a DevTools Performance trace while switching between threads.
  3. Look at the "Recalculate Style" events during each switch.

The minimal reproduction below needs no T3 Code. Open it in Chromium, record a Performance trace, and click the button:

<!doctype html>
<style>
  /* ComposerBanner.tsx:114, as Tailwind compiles it */
  .X + :has([data-chat-composer-form]) [data-chat-composer-form] > [data-slot=composer-banner-attachment]:first-child [data-composer-banner-surface=attached]::before { border-radius: 0 }
  /* any group-has-* utility; its group does not even need to be on the page */
  :is(:where(.group\/surface):has([data-banner=attached]) *) { box-shadow: none }
</style>
<button id="toggle">toggle banner</button>
<div id="list"></div>
<div id="stack"><div id="banner" class="X">banner</div><div><form data-chat-composer-form><div data-slot="composer-banner-attachment"><div data-composer-banner-surface="attached"></div></div></form></div></div>
<script>
  document.getElementById("list").innerHTML = "<div><span>row</span></div>".repeat(1500);
  const stack = document.getElementById("stack");
  const banner = document.getElementById("banner");
  document.getElementById("toggle").onclick = () => (banner.isConnected ? banner.remove() : stack.prepend(banner));
</script>

Expected behavior

Adding or removing a banner restyles the banner's neighbourhood, as it does when either rule is present alone.

Actual behavior

The Tailwind arbitrary variant in apps/web/src/components/chat/ComposerBanner.tsx:114 compiles to a bare :has() after a sibling combinator:

.X + :has([data-chat-composer-form]) [data-chat-composer-form] > [data-slot=composer-banner-attachment]:first-child [data-composer-banner-surface=attached]::before

When a group-has-* utility is in the same stylesheet (main ships many), adding or removing a sibling in that area makes Chromium restyle almost the whole document. The reproduction above, 20 banner toggles, counted with the trace's UpdateLayoutTree.elementCount:

Stylesheet in the reproduction Elements restyled per banner toggle (of 3,013)
no :has() rules 1
group-has rule only 1
ComposerBanner rule only 6
both, as in the file above 2,861
both, with the suggested rewrite below 6

The group-has rule's group element is not on the page at all; the rule only has to be in the stylesheet.

A thread switch adds and removes these siblings, so every switch pays for it. Measured on a main build (95030dc674, default settings), 13 scripted thread switches in headless Chromium, three rounds each:

As shipped Only the two ComposerBanner rules rewritten
Recalcs touching ≥1,000 elements 17 1
Elements restyled 32.3k 12.4k (−62%)
Style recalculation time 315 ms 156 ms (−50%)
Main thread blocked in long tasks, rapid switching 728 ms 461 ms (−37%)
Click → next paint, p50 74 ms 59 ms
Keydown → next paint, p95 54–64 ms 25–26 ms

The element counts come from Chromium's own trace and do not depend on machine load; they repeated exactly across rounds.

Suggested fix: remove the :has(), which is redundant. The rest of the selector already requires a [data-chat-composer-form] descendant of that sibling, so + * matches the same elements:

-        "[&+:has([data-chat-composer-form])_[data-chat-composer-form]>[data-slot=composer-banner-attachment]:first-child_[data-composer-banner-surface=attached]]:before:rounded-none [&+:has([data-chat-composer-form])_[data-chat-composer-form]>[data-slot=composer-banner-attachment]:first-child_[data-composer-banner-surface=attached]]:before:border-t-0",
+        "[&+*_[data-chat-composer-form]>[data-slot=composer-banner-attachment]:first-child_[data-composer-banner-surface=attached]]:before:rounded-none [&+*_[data-chat-composer-form]>[data-slot=composer-banner-attachment]:first-child_[data-composer-banner-surface=attached]]:before:border-t-0",

Checked equivalence: computed ::before styles are identical for the old and new selector with the form host after the attachment, with no attachment before it, with the attachment not first, and with the form as the sibling itself. With the rewrite, the reproduction's banner toggle restyles 6 elements instead of 2,861.

Impact

Major degradation or frequent failure

Version or commit

main @ 95030dc (rule introduced in #8693)

Environment

Linux, Chromium (headless, for the measurements) and the Electron desktop app. The effect is in Chromium's :has() invalidation, so every Chromium-based client is affected.

Logs or stack traces

The trace shows ScheduleStyleInvalidationTracking with changedPseudo: "has" walking every ancestor up to <html>, followed by StyleInvalidatorInvalidationTracking "Invalidation set invalidates subtree" with allDescendantsMightBeInvalid: true on each of them.

Screenshots, recordings, or supporting files

The reproduction above.

Workaround

None for users. Removing the two classes, or applying the suggested rewrite, removes the effect.

Activity

  1. juliusmarminge commented on Sep 26, 2026

    @juliusmarminge
    Member

    I checked this against current main (95030dc674) and could not reproduce the document-wide restyle.

    The class is still on Attachment in apps/web/src/components/chat/ComposerBanner.tsx (line 114), from the banner unification in #8693 (30175a8). Tailwind 4.3.3 emits it exactly as described:

    .\[\&\+\:has\(\[data-chat-composer-form\]\)_…\]\:before\:rounded-none + :has([data-chat-composer-form]) [data-chat-composer-form] > [data-slot=composer-banner-attachment]:first-child [data-composer-banner-surface=attached]::before

    group-has-data-[composer-banner-surface=attached]/composer-surface:shadow-none compiles to .…:is(:where(.group\/composer-surface):has([data-composer-banner-surface="attached"]) *). The :has() is redundant with the descendant [data-chat-composer-form] after it, so + * matches the same elements for the cases you listed (form inside the next sibling, no preceding attachment, attachment not :first-child, the form itself as the sibling, and a surface that is not attached). Thread switches do add and remove that sibling: ComposerBannerStack is rendered with key={activeThreadId} in ChatComposer.

    On Chrome 148.0.7778.96 headless, your minimal page (1,500 rows, both rules, one banner toggle) restyles 5 elements, not ~2,861. The trace schedules a class invalidation for .X and sets allDescendantsMightBeInvalid only on #stack. It does not walk ancestors to <html> with changedPseudo: "has". The same toggle with the + * rewrite is also 5 elements. Inserting a row with only the compiled group-has rule does not restyle the list. This desktop checkout is Electron 44.4.2, which is Chromium 152, newer than the Chrome I ran.

    I don't see another issue tracking this. Please add the Chromium version from the trace metadata (Browser / product). If that build is older than 148, the rewrite is still match-preserving and worth taking. On current Chrome these two rules do not restyle the document.

  2. added
    needs more info
    via-triage
    on Sep 26, 2026
  3. balwahidi commented on Sep 26, 2026

    @balwahidi

    Reproduces on Chrome/153.0.8010.53 and Edg/153.0.4234.48 (Windows 11, headless). The minimal page, unchanged, restyles 2,861 of 3,013 elements per toggle, and 6 with the + * rewrite, matching the table above. Real-app numbers and traces are in #13855.

  4. CaceresCallieri commented on Sep 26, 2026

    @CaceresCallieri
    Author

    Versions behind the numbers, all newer than 148:

    • Minimal page: Chrome 154.0.8037.57 (Linux, headless) — 2,861 of 3,013 per toggle.
    • In-app A/B on 95030dc674: Chromium 151.0.7922.173 (Linux, headless).
    • Original traces: the Electron 44.1.0 desktop app, Chrome/152.0.7977.65, showing changedPseudo: "has" up to <html>.

    With the 153 results in #13855, this looks like a change after 148 rather than an old-Chromium problem, and Electron 44 (Chromium 152) is affected. The rewrite in #13855 is match-preserving either way.

  5. SonyStone commented on Sep 30, 2026

    @SonyStone

    Adding a Windows reproduction of sidebar card/tooltip lag after switching threads. This appears related to this issue, but the two-selector rewrite only partly improves the hover case.

    Environment

    • T3 Code 0.0.44, source commit 0fcd5f90.
    • Windows, Microsoft Edge 154.0.4258.48, headed browser.
    • Bundled development build with T3CODE_BUNDLED_DEV=1; original CSS in the recording.
    • No CPU throttling or artificial delays. I originally noticed the symptom in the Windows desktop app too.

    Recording

    msedge_4AxJCV3fh2.mp4

    The recording uses an isolated, synthetic dataset: 16 projects, 240 threads and 2,048 messages, with about 10,000 DOM elements in the selected view. The large dataset makes the delay easier to see; the pointer moves while card highlights and tooltips lag behind it. No real conversations are included.

    Steps

    1. Open the current card-style sidebar with a populated thread list and a substantial conversation.
    2. Switch to another thread and back.
    3. Hover a card until its tooltip appears, then move between cards without clicking.

    The sequence matters: direct navigation/reload sometimes did not trigger the broad restyles; switching threads first did.

    A separate traced hover run on the same synthetic setup recorded a 660 ms maximum long task, a 137 ms maximum UpdateLayoutTree event, and up to 5,778 elements restyled in one event. These are development-build measurements, not production timing claims.

    Comparison with the suggested rewrite

    On a separate, smaller populated dataset, I compared the original code with only the two ComposerBanner variants changed from &+:has(...)_ to &+*_, as in #13855. Each run used the same 16 scripted hovers after switching threads. Two runs per variant:

    Metric Original, runs 1 / 2 Rewrite, runs 1 / 2
    Recalcs touching >1,000 elements 31 / 31 15 / 15
    Total UpdateLayoutTree time 1,026 / 937 ms 682 / 647 ms
    Maximum long task 227 / 120 ms 239 / 113 ms

    The rewrite reduced total style-recalculation time by about 32% across these runs, but broad restyles and visible hover stalls remained. The dev server was restarted between variants because Tailwind's hot updates retained removed selectors; both variants were tested after the same thread-switch sequence. Measurements used Chromium Tracing and PerformanceObserver, without CPU sampling.

    Posting here as additional evidence for the selector issue, while keeping the remaining hover-specific slowdown separate from any claim that #13855 should fix all of it.

  6. juliusmarminge commented on Oct 3, 2026

    @juliusmarminge
    Member

    Note

    Grok responding on behalf of Julius.

    Closing as fixed by #15265 (perf(web): DOM changes no longer restyle the whole page — same +:has([data-chat-composer-form]) → +* rewrite in ComposerBanner.tsx). GitHub did not auto-close because the merged PR had no Closes #13851.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs more infovia-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions