The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
perf(desktop): keep the keyframes hoist only; the composer rAF coalescing is dropped
kshitijk4poorefa09f49c12f
diff --git a/apps/desktop/src/app/chat/composer/hooks/use-composer-metrics.test.tsx b/apps/desktop/src/app/chat/composer/hooks/use-composer-metrics.test.tsxindex 450669c4f9e..cf082d02026 100644--- a/apps/desktop/src/app/chat/composer/hooks/use-composer-metrics.test.tsx+++ b/apps/desktop/src/app/chat/composer/hooks/use-composer-metrics.test.tsx@@ -1,4 +1,4 @@-import { act, cleanup, render } from '@testing-library/react'+import { cleanup, render } from '@testing-library/react'import { type RefObject, StrictMode, useRef } from 'react'import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'@@ -35,8 +35,6 @@ class FakeResizeObserver implements ResizeObserver {}}-// Measurements coalesce into one requestAnimationFrame (#99889), so a delivered-// resize is observable only after the frame runs.const deliverResize = () => {for (const observer of observers) {const entries = [...observer.targets].map(target => ({ target }) as ResizeObserverEntry)@@ -45,10 +43,6 @@ const deliverResize = () => {observer.callback(entries, observer)}}-- act(() => {- vi.advanceTimersToNextFrame()- })}const sized =@@ -88,34 +82,12 @@ const surfaceOf = (container: HTMLElement) => container.querySelector<HTMLElemendescribe('useComposerMetrics — published clearance survives an effect replay', () => {beforeEach(() => {observers.length = 0- vi.useFakeTimers({ toFake: ['requestAnimationFrame', 'cancelAnimationFrame'] })vi.stubGlobal('ResizeObserver', FakeResizeObserver)})afterEach(() => {cleanup()vi.unstubAllGlobals()- vi.useRealTimers()- })-- it('coalesces a burst of resize notifications into one measurement per frame', () => {- const { container } = render(<Harness dockHeight={200} surfaceHeight={120} />)- deliverResize()- const dock = container.querySelector('form')!.parentElement!- const measure = vi.spyOn(dock, 'getBoundingClientRect')-- for (const observer of observers) {- const entries = [...observer.targets].map(target => ({ target }) as ResizeObserverEntry)- observer.callback(entries, observer)- observer.callback(entries, observer)- observer.callback(entries, observer)- }-- expect(measure).not.toHaveBeenCalled()- act(() => {- vi.advanceTimersToNextFrame()- })- expect(measure).toHaveBeenCalledTimes(1)})it('republishes the dock height after StrictMode replays the cleanup', () => {diff --git a/apps/desktop/src/app/chat/composer/hooks/use-composer-metrics.ts b/apps/desktop/src/app/chat/composer/hooks/use-composer-metrics.tsindex fd3a21d7a98..644f0a30367 100644--- a/apps/desktop/src/app/chat/composer/hooks/use-composer-metrics.ts+++ b/apps/desktop/src/app/chat/composer/hooks/use-composer-metrics.ts@@ -1,5 +1,5 @@import { useAuiState } from '@assistant-ui/react'-import { type RefObject, useCallback, useEffect, useMemo, useRef, useState } from 'react'+import { type RefObject, useCallback, useEffect, useRef, useState } from 'react'import {chatSurfaceRoot,@@ -9,7 +9,6 @@ import {setSurfaceVar} from '@/app/chat/surface-vars'import { useResizeObserver } from '@/hooks/use-resize-observer'-import { rafCoalesce } from '@/lib/raf-coalesce'import {COMPOSER_COMPACT_PILL_PX,@@ -116,7 +115,7 @@ export function useComposerMetrics({const poppedOutRef = useRef(poppedOut)poppedOutRef.current = poppedOut- const measureComposerMetrics = useCallback(() => {+ const syncComposerMetrics = useCallback(() => {const composer = composerRef.current// The dock is the full docked footprint — strips, status stack, composer —// so it, not the composer alone, is what the thread has to clear.@@ -181,11 +180,6 @@ export function useComposerMetrics({}}, [composerDockRef, composerRef, composerSurfaceRef, editorRef])- // setSurfaceVar changes layout, which re-fires the observer that wrote it; coalesce to one- // measurement per frame so at most one style invalidation is scheduled per frame (#99889).- const coalescedMeasure = useMemo(() => rafCoalesce<true>(() => measureComposerMetrics()), [measureComposerMetrics])- const syncComposerMetrics = useCallback(() => coalescedMeasure.push(true), [coalescedMeasure])-useResizeObserver(syncComposerMetrics, composerDockRef, composerRef, composerSurfaceRef, editorRef)// Toggling pop-out changes whether the composer reserves thread clearance.@@ -204,7 +198,6 @@ export function useComposerMetrics({const root = chatSurfaceRoot(composerRef.current)return () => {- coalescedMeasure.cancel()clearSurfaceVar(root, COMPOSER_HEIGHT_VAR)clearSurfaceVar(root, COMPOSER_SURFACE_HEIGHT_VAR)// The bucket refs mirror what is published, so clearing the vars must@@ -218,7 +211,7 @@ export function useComposerMetrics({lastBucketedHeightRef.current = 0lastBucketedSurfaceHeightRef.current = 0}- }, [coalescedMeasure, composerRef])+ }, [composerRef])// Every decision comes from the composer's OWN measured width, never the// viewport's. There used to be a `(max-width: 30rem)` media query in here asdiff --git a/apps/desktop/src/lib/raf-coalesce.test.ts b/apps/desktop/src/lib/raf-coalesce.test.tsdeleted file mode 100644index e91221a5f8d..00000000000--- a/apps/desktop/src/lib/raf-coalesce.test.ts+++ /dev/null@@ -1,34 +0,0 @@-import { afterEach, describe, expect, it, vi } from 'vitest'--import { rafCoalesce } from './raf-coalesce'--afterEach(() => {- vi.useRealTimers()-})--describe('rafCoalesce', () => {- it('applies only the last pushed value, once per frame', () => {- vi.useFakeTimers({ toFake: ['requestAnimationFrame', 'cancelAnimationFrame'] })- const apply = vi.fn()- const coalesced = rafCoalesce<number>(apply)-- coalesced.push(1)- coalesced.push(2)- vi.advanceTimersToNextFrame()-- expect(apply).toHaveBeenCalledTimes(1)- expect(apply).toHaveBeenCalledWith(2)- })-- it('cancel drops the pending value without applying it', () => {- vi.useFakeTimers({ toFake: ['requestAnimationFrame', 'cancelAnimationFrame'] })- const apply = vi.fn()- const coalesced = rafCoalesce<number>(apply)-- coalesced.push(1)- coalesced.cancel()- vi.advanceTimersToNextFrame()-- expect(apply).not.toHaveBeenCalled()- })-})diff --git a/apps/desktop/src/lib/raf-coalesce.ts b/apps/desktop/src/lib/raf-coalesce.tsindex a7bc09453e3..788b99d6e83 100644--- a/apps/desktop/src/lib/raf-coalesce.ts+++ b/apps/desktop/src/lib/raf-coalesce.ts@@ -1,14 +1,9 @@/** Coalesce a stream of values (pointermove positions, resize deltas) to one* `apply` per animation frame, so a drag can't drive several layouts per frame.* `push` records the latest value and schedules a frame; `finish` commits the- * last value and cancels any pending frame (call it on pointerup/cancel);- * `cancel` drops the pending value without applying it (unmount teardown).+ * last value and cancels any pending frame (call it on pointerup/cancel).* `null` is the empty sentinel, so `T` must never legitimately be `null`. */-export function rafCoalesce<T>(apply: (value: T) => void): {- cancel: () => void- finish: () => void- push: (value: T) => void-} {+export function rafCoalesce<T>(apply: (value: T) => void): { finish: () => void; push: (value: T) => void } {let frame: null | number = nulllet pending: null | T = null@@ -20,20 +15,12 @@ export function rafCoalesce<T>(apply: (value: T) => void): {}}- const dropFrame = (): void => {- if (frame !== null) {- cancelAnimationFrame(frame)- frame = null- }- }-return {- cancel() {- dropFrame()- pending = null- },finish() {- dropFrame()+ if (frame !== null) {+ cancelAnimationFrame(frame)+ frame = null+ }if (pending !== null) {apply(pending)