The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
perf(desktop): composite-clean spinner strip, selection guard, swap-overlay ticker
Royalaid765e3a2f8afb
diff --git a/apps/desktop/src/app/chat/chat-swap-overlay.test.tsx b/apps/desktop/src/app/chat/chat-swap-overlay.test.tsxnew file mode 100644index 00000000000..958dedba3d6--- /dev/null+++ b/apps/desktop/src/app/chat/chat-swap-overlay.test.tsx@@ -0,0 +1,54 @@+// The overlay used to run its own 80ms setInterval + setState braille ticker —+// the same mechanism class (per-tick DOM mutation scheduling a style recalc)+// that GlyphSpinner was rewritten to remove. It now renders GlyphSpinner, so+// what needs pinning is that no timer comes back, that the label still survives+// the fade-out, and that the spinner stops animating once the swap is done.+import { cleanup, render, screen } from '@testing-library/react'+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'++import { ChatSwapOverlay } from './chat-swap-overlay'++afterEach(() => {+ cleanup()+})++describe('ChatSwapOverlay', () => {+ beforeEach(() => {+ vi.useFakeTimers()+ })++ afterEach(() => {+ vi.clearAllTimers()+ vi.useRealTimers()+ })++ it('animates the glyph without any timer', () => {+ const { container } = render(<ChatSwapOverlay profile="turqoise" />)++ expect(container.querySelector('.glyph-spinner__strip')).toBeTruthy()+ expect(vi.getTimerCount()).toBe(0)++ vi.advanceTimersByTime(5_000)++ expect(vi.getTimerCount()).toBe(0)+ })++ it('names the waking profile', () => {+ render(<ChatSwapOverlay profile="turqoise" />)++ expect(screen.getByText(/turqoise/)).toBeTruthy()+ })++ it('keeps the last profile name through the fade-out, with the glyph frozen', () => {+ const { container, rerender } = render(<ChatSwapOverlay profile="turqoise" />)++ expect(container.querySelector('.glyph-spinner')?.hasAttribute('data-paused')).toBe(false)++ rerender(<ChatSwapOverlay profile={null} />)++ // Label held so the overlay doesn't blank while it fades.+ expect(screen.getByText(/turqoise/)).toBeTruthy()+ // ...and the spinner stops, the way clearing the interval used to stop it.+ expect(container.querySelector('.glyph-spinner')?.getAttribute('data-paused')).toBe('true')+ })+})diff --git a/apps/desktop/src/app/chat/chat-swap-overlay.tsx b/apps/desktop/src/app/chat/chat-swap-overlay.tsxindex 9715dbc450e..0226a63d347 100644--- a/apps/desktop/src/app/chat/chat-swap-overlay.tsx+++ b/apps/desktop/src/app/chat/chat-swap-overlay.tsx@@ -1,17 +1,14 @@import { useEffect, useState } from 'react'+import { GlyphSpinner } from '@/components/ui/glyph-spinner'import { useI18n } from '@/i18n'import { cn } from '@/lib/utils'-// Braille spinner frames — reads as a tiny ASCII loader in monospace.-const FRAMES = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']-// Shown over the conversation while the live gateway swaps to another profile's// backend (lazily spawned). Keeps the last profile name through the fade-out so// the label doesn't blank. Purely visual — pointer-events-none.export function ChatSwapOverlay({ profile }: { profile: string | null }) {const { t } = useI18n()- const [frame, setFrame] = useState(0)const [label, setLabel] = useState<null | string>(profile)useEffect(() => {@@ -20,16 +17,6 @@ export function ChatSwapOverlay({ profile }: { profile: string | null }) {}}, [profile])- useEffect(() => {- if (!profile) {- return- }-- const id = window.setInterval(() => setFrame(value => (value + 1) % FRAMES.length), 80)-- return () => window.clearInterval(id)- }, [profile])-return (<divaria-hidden@@ -39,7 +26,14 @@ export function ChatSwapOverlay({ profile }: { profile: string | null }) {)}><div className="flex items-center gap-2 bg-[color-mix(in_srgb,var(--dt-card)_92%,transparent)] px-4 py-2 font-mono text-[0.8125rem] text-foreground shadow-composer">- <span className="w-3 text-(--ui-accent)">{FRAMES[frame]}</span>+ {/* Was a local 80ms setInterval + setState braille ticker — the same+ mechanism class (per-tick DOM mutation scheduling style recalc)+ that GlyphSpinner was rewritten to remove. `braille` is exactly the+ frame set and 80ms cadence this used. `justify-start` keeps the+ glyph left-aligned in its w-3 box the way the bare span was, and+ `paused` restores the old "no ticking once the swap is done"+ behaviour while the overlay fades out still mounted. */}+ <GlyphSpinner className="w-3 justify-start text-(--ui-accent)" paused={!profile} spinner="braille" />{t.composer.wakingProfile(label ?? '')}</div></div>diff --git a/apps/desktop/src/components/ui/glyph-spinner.css b/apps/desktop/src/components/ui/glyph-spinner.cssindex 825c54ffdc8..1b176adaabc 100644--- a/apps/desktop/src/components/ui/glyph-spinner.css+++ b/apps/desktop/src/components/ui/glyph-spinner.css@@ -23,20 +23,36 @@*/.glyph-spinner {+ /* Single source of truth for the frame metric: the clip viewport, each frame+ box, and the keyframe travel all derive from this, so they cannot drift+ apart. `em` resolves against the element it is used on, and font-size is+ uniform across this subtree — nothing below .glyph-spinner declares one —+ so the strip's `em` and the frame's `em` are the same length. */+ --glyph-spinner-frame-height: 1em;+display: block;- height: 1em;+ height: var(--glyph-spinner-frame-height);overflow: hidden;line-height: 1;+ /* Decorative and aria-hidden, so it must not land in a transcript copy.+ These spinners sit inside [data-selectable-text] subtrees (tool/delegate,+ tool/fallback), where the strip would otherwise contribute all N glyphs to+ a selection where the old one-character implementation contributed one. */+ -webkit-user-select: none;+ user-select: none;}.glyph-spinner__strip {display: block;animation: glyph-spinner-advance var(--glyph-spinner-duration) steps(var(--glyph-spinner-frames)) infinite;+ /* Promote to a compositor layer. Without it, trace instrumentation recorded+ a non-zero compositeFailed on every animation record. */+ will-change: transform;}.glyph-spinner__frame {display: block;- height: 1em;+ height: var(--glyph-spinner-frame-height);line-height: 1;}@@ -50,12 +66,19 @@animation-play-state: paused;}+/* The travel MUST be an absolute length, never a percentage. A percentage+ translate resolves against the strip's own box, so Chromium treats the+ animation as layout-dependent and refuses to composite it — trace+ instrumentation showed compositeFailed set on 184/184 records (codes+ 131072 / 131104) with translateY(-100%), while a sibling transform+ animation using an absolute length composited clean. N frames x the frame+ height is the same distance, computed rather than box-relative. */@keyframes glyph-spinner-advance {from {transform: translateY(0);}to {- transform: translateY(-100%);+ transform: translateY(calc(var(--glyph-spinner-frames) * -1 * var(--glyph-spinner-frame-height)));}}diff --git a/apps/desktop/src/components/ui/glyph-spinner.test.tsx b/apps/desktop/src/components/ui/glyph-spinner.test.tsxindex 1206c163f9c..652a7aa263d 100644--- a/apps/desktop/src/components/ui/glyph-spinner.test.tsx+++ b/apps/desktop/src/components/ui/glyph-spinner.test.tsx@@ -143,6 +143,43 @@ describe('GlyphSpinner', () => {expect(status.querySelector('.glyph-spinner')?.getAttribute('aria-hidden')).toBe('true')})+ it('pauses on request while staying mounted', () => {+ // For a caller that keeps the spinner in the tree through a fade-out+ // (ChatSwapOverlay) and does not want it animating once the wait is over.+ const { rerender } = render(<GlyphSpinner paused spinner="braille" />)+ const viewport = () => screen.getByRole('status', { name: 'Loading' }).querySelector('.glyph-spinner')++ expect(viewport()?.getAttribute('data-paused')).toBe('true')++ rerender(<GlyphSpinner paused={false} spinner="braille" />)++ expect(viewport()?.hasAttribute('data-paused')).toBe(false)+ })++ it('travels an absolute length, so the animation can be composited', () => {+ // A percentage translate resolves against the strip's own box, which makes+ // the animation layout-dependent and Chromium refuses to composite it:+ // instrumentation recorded compositeFailed on 184/184 records while the+ // keyframes used translateY(-100%). This guards the regression back to it,+ // which is invisible in jsdom and subtle on screen.+ const css = readFileSync(resolve(process.cwd(), 'src/components/ui/glyph-spinner.css'), 'utf8')+ const keyframes = css.slice(css.indexOf('@keyframes glyph-spinner-advance'))++ expect(keyframes).not.toMatch(/translateY\(\s*-?\d+%/)+ expect(keyframes).toContain('var(--glyph-spinner-frame-height)')+ expect(css).toContain('will-change: transform')+ })++ it('keeps the decorative strip out of text selection', () => {+ // These sit inside [data-selectable-text] subtrees; without this a+ // transcript copy would pick up all N glyphs of every spinner.+ const css = readFileSync(resolve(process.cwd(), 'src/components/ui/glyph-spinner.css'), 'utf8')++ expect(css.slice(css.indexOf('.glyph-spinner {'), css.indexOf('.glyph-spinner__strip'))).toContain(+ 'user-select: none'+ )+ })+it('is wired into the global renderer-animation pause rule', () => {// Window blur / minimize / document-hidden suspension now comes from this// rule rather than from a per-spinner pause controller. Dropping the classdiff --git a/apps/desktop/src/components/ui/glyph-spinner.tsx b/apps/desktop/src/components/ui/glyph-spinner.tsxindex c5a331d542b..07a762d0645 100644--- a/apps/desktop/src/components/ui/glyph-spinner.tsx+++ b/apps/desktop/src/components/ui/glyph-spinner.tsx@@ -33,6 +33,10 @@ const FRAMES_BY_NAME: Record<SpinnerName, NormalisedSpinner> = (() => {interface GlyphSpinnerProps {ariaLabel?: stringclassName?: string+ /** Freeze the animation while the spinner stays mounted — for a caller that+ * keeps it in the tree through a fade-out and does not want it animating+ * once it is no longer the thing being waited on. */+ paused?: booleanspinner?: SpinnerName}@@ -53,7 +57,12 @@ interface GlyphSpinnerProps {* clipping viewport is centred inside it by the same `items-center` that used* to centre the single glyph.*/-export function GlyphSpinner({ ariaLabel = 'Loading', className, spinner = 'braille' }: GlyphSpinnerProps) {+export function GlyphSpinner({+ ariaLabel = 'Loading',+ className,+ paused = false,+ spinner = 'braille'+}: GlyphSpinnerProps) {const spin = FRAMES_BY_NAME[spinner] ?? FRAMES_BY_NAME.braille!// Pause when this surface is a hidden (kept-alive) tab: N mounted tabs each// animating burns CPU for pixels nobody can see. Window blur / minimize /@@ -73,7 +82,7 @@ export function GlyphSpinner({ ariaLabel = 'Loading', className, spinner = 'braiThe frames are decorative, and this is a live region — the oldimplementation rewrote its text ~12x/second, which would announce anew glyph on every tick. */}- <span aria-hidden="true" className="glyph-spinner" data-paused={visible ? undefined : 'true'}>+ <span aria-hidden="true" className="glyph-spinner" data-paused={paused || !visible ? 'true' : undefined}><spanclassName="glyph-spinner__strip"style={