From 05158282725ef2a28ac9b87187a8a69532b88239 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Sun, 15 Nov 2026 21:21:06 +0000 Subject: [PATCH 1/3] fix(ui-kit): end the ghost handoff on its fades' own end (#3425) The arrival handoff ended on a 600ms timer started at the commit, while the fades start on the first frame rendered after it. A late first frame (a loaded runner, a long task right after the commit) let the timer remove the ghost part-way through its fade; even unloaded it cut the fade a frame short. useArrival now takes the item's frame and waits for that frame's running ghost-in/ghost-out animations to finish. Where no fade runs (reduced motion's 0s, animation: none, no Web Animations) it keeps the HANDOFF_MS timer, and a fade that has not started FIRST_FRAME_MS after the commit (a document that renders no frames) ends the handoff then. The handoff clock now records whether the fade ended before removal, and the stories assert it. New Chromium controls stall the main thread right after the arrival commit; the 200ms-hold controls hold the incoming fade instead of the retired timer. Co-Authored-By: Claude Opus 5.5 --- .changeset/3425-ghost-fade-end.md | 5 ++ docs/decisions/design-kit/loading.md | 17 +++++ docs/process/test-waits.md | 16 +++-- .../src/conversation/StreamingAnswer.tsx | 6 +- packages/ui-kit/src/decisions/ActionCard.tsx | 6 +- .../ui-kit/src/evidence/SearchResultCard.tsx | 6 +- packages/ui-kit/src/internal/GhostText.tsx | 70 ++++++++++++++++--- packages/ui-kit/src/rows/FileRow.tsx | 6 +- packages/ui-kit/src/rows/QueueItemRow.tsx | 6 +- packages/ui-kit/src/states/Placeholder.tsx | 7 +- packages/ui-kit/stories/_ghost.tsx | 13 ++-- packages/ui-kit/stories/_handoff-clock.ts | 21 ++++-- .../ui-kit/stories/_streaming-handoff.tsx | 1 + .../stories/states/Placeholder.stories.tsx | 1 + packages/ui-kit/tests/ghost-text.test.tsx | 69 ++++++++++++++++-- .../tests/visual/ghost-handoff.visual.tsx | 41 +++++++---- .../tests/visual/ghost-media.visual.tsx | 57 +++++++++++++-- .../tests/visual/streaming-handoff.visual.tsx | 41 +++++++---- 18 files changed, 312 insertions(+), 77 deletions(-) create mode 100644 .changeset/3425-ghost-fade-end.md diff --git a/.changeset/3425-ghost-fade-end.md b/.changeset/3425-ghost-fade-end.md new file mode 100644 index 0000000000..8941e8e846 --- /dev/null +++ b/.changeset/3425-ghost-fade-end.md @@ -0,0 +1,5 @@ +--- +"@schlessera/brain-ui-kit": patch +--- + +End the loading ghost's handoff when its fade ends, not 600ms after the data arrives, so a late first frame no longer removes the ghost from partial opacity. Where no fade runs (reduced motion, `animation: none`) the handoff still ends after 600ms. diff --git a/docs/decisions/design-kit/loading.md b/docs/decisions/design-kit/loading.md index 40f3cf3693..5235a6e39c 100644 --- a/docs/decisions/design-kit/loading.md +++ b/docs/decisions/design-kit/loading.md @@ -143,6 +143,23 @@ so ellipsis does not cut off blurred ends. Reduced motion hides the entire band and disables every translation; print hides ghosts and the band. The existing instant reduced-motion handoff and stream tail rules remain. +### D53 addendum — the handoff ends on its fades' end (#3425, 2026-11-15) + +The handoff now ends when the item's own fades end, not on a 600ms timer +started at the arrival commit (`useArrival`, +`packages/ui-kit/src/internal/GhostText.tsx:216-248`). The fades start on the +first frame the browser renders after the commit. On a loaded browser that +frame can come hundreds of ms late, and the commit timer then removed the +ghost from partial opacity, part-way through its fade. Even unloaded, the timer +ended the fade a frame early. Each consumer hands its root element to the hook, +which waits on that frame's running `ghost-in` and `ghost-out` animations. + +Where no fade runs, the handoff still ends after `HANDOFF_MS`. That covers +reduced motion's 0s fades, `animation: none` and a DOM without Web Animations. +A fade that has not started `FIRST_FRAME_MS` (3s) after the commit means the +document renders no frames, and the handoff ends then rather than hold the +ghost forever. The 600ms fade, its easing and its keyframes are unchanged. + diff --git a/docs/process/test-waits.md b/docs/process/test-waits.md index 94322c9efb..4fc9c7cc4f 100644 --- a/docs/process/test-waits.md +++ b/docs/process/test-waits.md @@ -587,7 +587,9 @@ The nine former 640 ms settlements in `packages/ui-kit/tests/ghost-text.test.tsx retain their assertions. The test captures every global timeout registered by these mounted components, including a wrongly configured delay. Its independent 600 ms oracle checks the actual `useArrival` effect (`useArrival`, -`packages/ui-kit/src/internal/GhostText.tsx:181-194`). At 599 ms the same outgoing +`packages/ui-kit/src/internal/GhostText.tsx:216-248`). happy-dom computes no CSS +animations, so no fade runs and the hook ends the handoff on its 600 ms +fallback timer. Stand-in fades cover the path where a fade runs (#3425). At 599 ms the same outgoing and incoming nodes must remain; at 600 ms the real callback runs inside React `act`, whose committed result must remove both handoff classes. Neither an arbitrary microtask nor immediate absence proves completion. @@ -614,13 +616,15 @@ in the successor. The original glyph, role, style, accessibility, inertness, interaction, ordering and loaded-state assertions stay in this file. Native proof remains unchanged and required: `playHandoff` in -`packages/ui-kit/stories/_ghost.tsx` observes 300 ms mid-handoff opacity, -320/720 px geometry, a 600 ms fade in animation time and removal within three -rendered frames of that fade's end (#3417). LoadingToReady +`packages/ui-kit/stories/_ghost.tsx` observes mid-handoff opacity, +320/720 px geometry, a 600 ms fade in animation time, a fade that ends before +removal (#3425) and removal within three rendered frames of that fade's end +(#3417). LoadingToReady stories run in both Storybook theme projects. Chromium's `packages/ui-kit/tests/visual/ghost-handoff.visual.tsx` retains both themes, -input-orchestration and main-thread-stall exclusion, and the mutation holding -one width's ghost 200 ms past its fade that still fails. +input-orchestration and main-thread-stall exclusion, a long task right after +the commit that delays the fades' start (#3425), and the mutation holding one +width's ghost 200 ms past its fade that still fails. Logical component time proves none of CSS rasterization, native elapsed animation budgets or geometry. Production JavaScript and CSS remain 600 ms. diff --git a/packages/ui-kit/src/conversation/StreamingAnswer.tsx b/packages/ui-kit/src/conversation/StreamingAnswer.tsx index 4446f2fdff..d63bb06e46 100644 --- a/packages/ui-kit/src/conversation/StreamingAnswer.tsx +++ b/packages/ui-kit/src/conversation/StreamingAnswer.tsx @@ -1,5 +1,5 @@ import { GhostBand } from "../internal/GhostBand.js"; -import type { CSSProperties, KeyboardEvent } from "react"; +import { useRef, type CSSProperties, type KeyboardEvent } from "react"; import { GhostText, INCOMING, useArrival } from "../internal/GhostText.js"; import { StatusDot } from "../primitives/StatusDot.js"; @@ -78,7 +78,8 @@ export function StreamingAnswer(p: StreamingAnswerProps) { const canStop = p.stoppable !== false; const act = Boolean(p.onStop); const waiting = p.bars !== false && !text; - const arriving = useArrival(waiting); + const frame = useRef(null); + const arriving = useArrival(waiting, frame); // Code points, not UTF-16 units, so the tail never splits a character. const chars = Array.from(text); const split = Math.max(0, chars.length - TAIL); @@ -100,6 +101,7 @@ export function StreamingAnswer(p: StreamingAnswerProps) { return (
(null); + const arriving = useArrival(loading, frame); // The ghost's seed is this instance — kept per item key, not per list // position — so re-ranking a row never regenerates its glyphs. const id = useId(); @@ -311,6 +312,7 @@ export function ActionCard(p: ActionCardProps) { return (
(null); + const arriving = useArrival(loading, frame); // The ghost's seed is this instance — kept per item key, not per list // position — so re-ranking a row never regenerates its glyphs. const id = useId(); @@ -167,6 +168,7 @@ export function SearchResultCard(p: SearchResultCardProps) { return (