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 430e8ca61b..2b71e5babf 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 400 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 (