Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(site): skip streaming animation on first engine update#22535

Closed
kylecarbs wants to merge 1 commit intomainfrom
fix/stream-animation-replay
Closed

fix(site): skip streaming animation on first engine update#22535
kylecarbs wants to merge 1 commit intomainfrom
fix/stream-animation-replay

Conversation

@kylecarbs
Copy link
Member

@kylecarbs kylecarbs commented Mar 3, 2026

Problem

When navigating away from the agents chat page and returning, the smooth text streaming animation replays all existing text — you see the text animate in as if it's being freshly streamed.

Root Cause

On reconnect, the WebSocket replays all buffered message_part events as a snapshot. The client rebuilds streamState from scratch, so SmoothTextEngine starts at visibleLength = 0 and uses requestAnimationFrame to animate through all the text. Even with the MAX_VISUAL_LAG_CHARS (120) cap, the last 120 characters still visibly animate in.

Fix

Added a firstUpdate flag to SmoothTextEngine. On the very first update() call, the engine snaps to the full text length instead of starting the RAF animation loop. This means:

  • Reconnect/page load: snapshot text renders instantly (no replay)
  • Real-time streaming: after the first update is consumed, subsequent updates animate normally

The flag resets on reset() and new engine instances start with it set to true.

Changes

  • SmoothText.ts: Added firstUpdate flag that bypasses animation on first update() call
  • SmoothText.test.ts: Added explicit test for first-update snap behavior; updated existing tests to use createStreamingEngine() helper that consumes the first update so they continue testing incremental animation correctly

When navigating away from the agents chat page and returning, the
smooth text streaming animation replayed all existing text. This
happened because the WebSocket reconnects and replays buffered
message_part events, rebuilding streamState from scratch. The
SmoothTextEngine then animated from visibleLength=0 through all
the text via requestAnimationFrame.

Fix: add a firstUpdate flag to SmoothTextEngine that snaps to full
length on the very first update() call. This means pre-existing
text (reconnect snapshot) renders instantly. Subsequent updates
animate normally since firstUpdate is already consumed.
@kylecarbs kylecarbs force-pushed the fix/stream-animation-replay branch from c0d06e1 to b2f7ce1 Compare March 3, 2026 00:52
@kylecarbs kylecarbs changed the title fix(site): skip streaming animation for pre-existing text on remount fix(site): skip streaming animation on first engine update Mar 3, 2026
@kylecarbs kylecarbs closed this Mar 3, 2026
@github-actions github-actions bot locked and limited conversation to collaborators Mar 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant