Skip to content

Toggling the right panel restyles the whole page when plugin or theme CSS uses :has() #6489

Closed

Description

@JackALaing

Summary

Opening or closing the right panel freezes the page before the panel starts moving. On wide windows a second, similar stall lands partway through the slide. Both come from core inserting or removing DOM nodes during the toggle: the thread header's right-panel button, and the thread table-of-contents rail. With plugin or theme CSS that uses :has(), each insertion or removal makes Chromium restyle the whole page. Expected: the panel starts moving within about one frame.

Versions and environment

  • main at c738623. The same code is in the current Nightly desktop app (Electron).
  • macOS, Apple Silicon. Measured in headless Chromium against a production build of the web app.
  • Unusual about the setup: about 35 plugin stylesheets plus a custom theme are loaded, together containing roughly 170 :has() rules. Core CSS alone does not show the stall.

Steps to reproduce

  1. Install plugins or a theme whose CSS contains :has() rules with a descendant or universal subject, for example [data-x]:has(> button[aria-label="..."]) > :not(...) or div:has(> div > button[aria-label="..."]) *. Any one such rule is enough.
  2. Open a thread with at least three user messages in a window at least 1440 px wide.
  3. Toggle the right panel with the header button or ⌘J several times.

Tried and did not reproduce: the same toggles with plugin stylesheets disabled (35–50 ms input-to-first-frame at 4× CPU throttling). Disabling the slide transition does not remove the up-front stall.

Expected vs actual

Expected: the panel starts moving within about one frame; no long frames during the slide.
Actual (4x CPU throttle, median of repeated toggles):
  input to first frame: 268–278 ms at 1024, 1440 and 1920 px
  longest frame during the slide at 1920 px: about 283 ms

Evidence

  • The header toggle is unmounted while the panel is open on desktop and mounted again on close:
    const showRightPanelToggle =
    secondaryPanelHost === null && (!isSecondaryPanelOpen || isCompactViewport);
    and
  • The table-of-contents rail is unmounted below 56 rem:
    setVisible(inlineSize >= TOC_MIN_VISIBLE_WIDTH_PX);
    and
    {tocVisible ? (
    <div className="relative">
    <button
    type="button"
    aria-label="Thread table of contents"
    aria-expanded={open}
    aria-controls={`thread-toc-panel-${threadId}`}
    onClick={() => setOpen(true)}
    className="no-scrollbar flex max-h-[calc(100vh-7rem)] w-8 cursor-pointer flex-col items-center gap-2 overflow-y-auto py-2"
    >
    <span
    aria-hidden
    className="flex w-full flex-col items-center gap-2"
    >
    {railItems.map((item) => (
    <span
    key={item.id}
    className={cn(
    "h-[3px] shrink-0 rounded-full transition-all duration-150",
    item.id === activeUserId
    ? "w-5 bg-foreground/30 group-hover/toc:bg-foreground/70"
    : "w-3 bg-foreground/5 group-hover/toc:bg-foreground/20",
    )}
    />
    ))}
    </span>
    </button>
    {open ? (
    <div
    id={`thread-toc-panel-${threadId}`}
    className="pointer-events-auto absolute right-full top-0 w-[18.25rem] max-w-[calc(100vw-3rem)] pr-1"
    >
    <div className="rounded-lg border border-border bg-popover p-1 shadow-lg">
    <div className="flex items-center gap-1 pb-1">
    {hasAgentMessages ? (
    <TocPanelTab
    label="Agent messages"
    active={activeTab === "agent"}
    onSelect={() => setTab("agent")}
    />
    ) : null}
    <TocPanelTab
    label="Your messages"
    active={activeTab === "user"}
    onSelect={() => setTab("user")}
    />
    </div>
    <div className="relative isolate">
    <div
    ref={scrollRef}
    className="max-h-64 overflow-y-auto overflow-x-hidden"
    >
    <div
    ref={topSentinelRef}
    aria-hidden
    className="h-px w-full"
    />
    <ul className="flex flex-col">
    {items.map((item) => {
    const active = item.id === activeId;
    const pending = item.id === pendingJumpId;
    return (
    <li key={item.id}>
    <button
    ref={(node) => {
    if (node) itemEls.current.set(item.id, node);
    else itemEls.current.delete(item.id);
    }}
    type="button"
    aria-busy={pending}
    onClick={() => {
    void handleSelect(item.id);
    }}
    className={cn(
    "flex w-full cursor-pointer rounded-md px-2 py-1.5 text-left transition-colors",
    active
    ? "bg-state-hover"
    : "hover:bg-state-hover",
    )}
    >
    <span
    className={cn(
    "text-xs leading-snug",
    active
    ? "text-foreground"
    : "text-muted-foreground",
    pending && "animate-pulse",
    )}
    >
    <TocItemPreview
    item={item}
    senderThreadMetadataById={
    senderThreadMetadataById
    }
    />
    </span>
    </button>
    </li>
    );
    })}
    </ul>
    <div
    ref={bottomSentinelRef}
    aria-hidden
    className="h-px w-full"
    />
    </div>
    {aboveOverflow ? (
    <div
    aria-hidden
    className="pointer-events-none absolute inset-x-0 top-0 z-10 h-8 bg-gradient-to-b from-popover/90 via-popover/60 to-transparent"
    />
    ) : null}
    {belowOverflow ? (
    <div
    aria-hidden
    className="pointer-events-none absolute inset-x-0 bottom-0 z-10 h-8 bg-gradient-to-t from-popover/90 via-popover/60 to-transparent"
    />
    ) : null}
    </div>
    </div>
    </div>
    ) : null}
    </div>
    ) : null}
    . Opening the panel on a window wider than about 1120 px shrinks the timeline across that breakpoint mid-transition, so the rail is removed (or, on close, inserted) during the animation.
  • A Chromium trace with invalidation tracking shows the toggle marking every ancestor "Affected by :has()" up to the app root, then invalidating whole subtrees ("allDescendantsMightBeInvalid"). The resulting forced style recalculation covers about 1,100–2,300 elements.
  • Replaying single mutations in the loaded page at 1× CPU: removing and reinserting the header button costs about 52 ms of forced style recalculation; toggling a hidden class on it costs 0.8 ms; toggling inert, aria-expanded or aria-pressed costs 0.4–0.9 ms. Removing every :has() rule brings the full toggle down to about 40 ms at 4× throttle; removing any single stylesheet's :has() rules does not.
  • Measurement method: production build served against a local server, headless Chromium, Emulation.setCPUThrottlingRate 4, requestAnimationFrame timestamps around a click on the visible toggle, and Chromium trace events for style recalculation.

What you ruled out

  • Not the slide animation: disabling the panel's flex transition leaves the up-front stall unchanged, and frames during the slide are about 17 ms when nothing mounts.
  • Not panel content: the panel stays mounted after the first open (the first open has an extra mount cost, not covered here).
  • Not a duplicate of Right panel polish: toggle jump, open/close reflow, tab-strip rough edges #435 (closed right-panel polish issue about layout jumps, not restyle cost).
  • Plugin and theme :has() rules make the cost large, but the trigger is core's mount and unmount. Rule-by-rule clean-up did not converge: many unrelated rules each re-create most of the cost.

Suggested priority and effort

Hits any user with :has()-heavy plugin or theme CSS on every right-panel toggle; there is no workaround short of removing that CSS. No data loss. Small change: keep both elements mounted and hide them.

Checks

  • I reproduced this on the latest release or on main, or I say above that I could not.
  • I searched open and closed issues for the same problem.

AGENT GENERATED

Activity

  1. added theissue type on Oct 28, 2026
  2. added
    ui
    partial-repro
    on Oct 28, 2026
  3. bb-slop-cop commented on Oct 28, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    AGENT GENERATED

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

    partial-reproperfui

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions