Skip to content

✨ feat: Smooth Streaming Text Fade-In - #14757

Merged
danny-avila merged 8 commits into
devfrom
claude/flowtoken-smooth-streaming-td4yj7
Aug 12, 2026
Merged

danny-avila merged 8 commits into
devfrom
claude/flowtoken-smooth-streaming-td4yj7

Conversation

@danny-avila

@danny-avila danny-avila commented Aug 12, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Native FlowToken-style smooth streaming: newly streamed words fade in with a subtle staggered opacity animation, purely as a presentation-layer effect — the streaming data path (rAF-coalesced delta flush, per-block markdown memoization) is untouched, and token delivery rate is unchanged (pacing stays server-side).

How it works

After researching FlowToken, Vercel's streamdown, llm-ui, and the AI SDK's smoothStream, this adopts streamdown's architecture (the approach Claude.ai uses), which is the only one whose "don't re-animate old text" mechanism survives markdown re-parsing — FlowToken's per-node ref/key diffing flickers whenever a re-parse moves text between elements (e.g. **bold completing into <strong>).

  • Content/animate.tsx — a rehype plugin factory. The transform walks the HAST in document order, splits text into word parts (whitespace attached to its word; Intl.Segmenter for CJK, which whitespace-splitting can't handle), and wraps them in <span data-lc-fade> driving a one-shot 250ms CSS opacity animation with a capped 25ms stagger.
  • New-text detection is by document-order character offset, held in the plugin instance's closure: a word starting below the previous render's total offset mounts as a bare span and never animates, even if React remounts it. Words still inside their animation window replay byte-identical props, so React leaves the in-flight CSS animation untouched — an improvement over streamdown, which switches mid-flight words to duration: 0ms and cuts their fade short. This also means a word growing at the stream head (hel → hello) keeps fading rather than restarting.
  • One plugin instance per MarkdownBlock, appended to the cached rehype plugin array only while animating. Since only the last, still-growing block re-runs the pipeline, settled blocks never even execute the transform. The block memo comparator gains only an animate check.
  • Gating: smoothStreaming && isLatestMessage && isSubmitting (both signals already in MessageContext, covering the content-parts and legacy text paths). When the stream ends the plugin is dropped and the settled message re-renders once with zero wrapper spans — clean DOM, clean copy/paste.
  • Skip list: code/pre, math/KaTeX output, artifacts, citations, and MCP-UI subtrees are never wrapped (FlowToken's per-word code-block animation is a documented perf drag).
  • Reasoning: ThinkingContent gets the same treatment via a lightweight AnimatedText component (plain text, no markdown — nearly free).
  • Settings: "Smooth streaming text" toggle (default on) under Settings → Chat → Messages; @media (prefers-reduced-motion: reduce) disables the animation regardless of the toggle. The streaming cursor (.result-streaming …:last-child:after) is unaffected since spans live inside the last block element.

Performance

Measured two ways, both comparing current main behavior vs. fade enabled.

1. jsdom Profiler bench (extended MarkdownBlocks.bench.tsx, committed — 9KB message with 12 code blocks + tables, 80 stream steps):

code-block renders total render time
OLD whole-message 500 1280.9 ms
NEW per-block (main) 62 591.9 ms
NEW + fade 62 645.3 ms (+9.0%)

The bench now asserts the fade cannot disturb block memoization (identical code-block render counts).

2. react-scan + frame timing in headless Chromium (Vite dev server harness streaming an 8-section markdown fixture with code blocks/tables at ~60 words/s, react-scan onRender aggregation + rAF frame deltas + PerformanceObserver long tasks, 3 iterations averaged):

CPU metric current fade
1× (desktop) avg frame 17.7 ms 16.7 ms
1× (desktop) p95 frame 25.1 ms 16.8 ms
1× (desktop) long-task total 536 ms 288 ms
4× throttle avg frame 25.8 ms 36.3 ms
4× throttle p95 frame 58.3 ms 83.4 ms
4× throttle React render time 11.0 s (+0%) 12.1 s (+10%)
  • Unthrottled hardware: no regression — both hold ~60fps, and the fade run is actually steadier (compositor-driven opacity animations).
  • Under 4× CPU throttle on this torture fixture the fade adds ~10ms/frame. Isolation runs show the React/DOM side of the span wrapping is only ~+7%; the remainder is the browser running the animations themselves (style/compositing), and it is independent of animation duration. The baseline already misses 60fps in that scenario; low-end users have the toggle and reduced-motion as escape hatches.
  • react-scan per-component data confirms render counts are unchanged where it matters: MarkdownBlocks 323 renders in both modes, CodeBlock 1340 vs 1341.

Follow-ups (not in this PR)

  • Optional blurIn variant (blur masks chunk boundaries on very fast models — streamdown's recommendation) as a second animation style.
  • Client-side adaptive pacing was researched (llm-ui-style rAF drain) but deliberately excluded — rate control stays server-side per scope.

Change Type

  • New feature (non-breaking change which adds functionality)

Testing

  • client: npx jest src/components/Chat/Messages/Content/__tests__/animate.test.tsx — 12 new tests covering word splitting (round-trip, CJK), classification (stagger cap, whitespace, append-only detection, mid-window prop replay, growing head word), the rehype plugin through real ReactMarkdown renders (skip lists, streamed re-renders, restructuring around **final**), and AnimatedText.
  • Existing markdown suites (MarkdownBlocks, MermaidBlockIds, Markdown.mcpui, MarkdownBlocks.artifacts, Part, ContentParts, Translation.spec) all pass — 82 tests total.
  • Streaming bench: node node_modules/jest/bin/jest.js --runInBand --coverage=false --testMatch '**/MarkdownBlocks.bench.tsx' from client/ (numbers above).
  • Browser measurement: temporary Vite-served harness page streaming through the real <Markdown> pipeline in headless Chromium with react-scan onRender aggregation, rAF frame deltas, and long-task observation, at 1× and 4× CPU throttle (numbers above; harness not committed).
  • npx tsc --noEmit clean (one pre-existing unrelated error in lib/rum/useRum.ts); ESLint and npm run sort-imports:check clean on all touched files.

Test Configuration:

  • Node v22, client workspace Jest (jsdom) for unit tests/bench; headless Chromium (Playwright) against the Vite dev server for frame/react-scan measurements.

Checklist

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • I have commented in any complex areas of my code
  • My changes do not introduce new warnings
  • I have written tests demonstrating that my changes are effective or that my feature works
  • Local unit tests pass with my changes

🤖 Generated with Claude Code

https://claude.ai/code/session_01DrUMn8aEKtMY2QRZhpheJB

Copilot AI lite review requested due to automatic review settings August 12, 2026 01:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a presentation-layer “smooth streaming” effect so newly streamed words fade in with a short, staggered opacity animation, while keeping the existing streaming/rendering pipeline unchanged and providing a user setting + reduced-motion support.

Changes:

  • Introduces a rehype-based word-wrapping fade plugin for markdown streaming plus a lightweight AnimatedText for plain-text reasoning.
  • Adds a Settings toggle (persisted via Jotai storage atom) and corresponding localization strings.
  • Extends markdown streaming benchmarks and adds a dedicated test suite for segmentation/animation behavior.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
client/src/style.css Adds [data-lc-fade] keyframes + reduced-motion disablement.
client/src/store/smoothStreaming.ts Adds persisted setting atom for smooth streaming toggle.
client/src/locales/en/translation.json Adds UI label + hover help text for the setting.
client/src/components/Nav/Settings/registry.tsx Registers the “Smooth streaming text” toggle under Chat → Messages.
client/src/components/Chat/Messages/Content/Parts/Thinking.tsx Adds optional animated rendering for reasoning text via AnimatedText.
client/src/components/Chat/Messages/Content/Parts/Reasoning.tsx Gates reasoning animation on smoothStreaming + streaming state.
client/src/components/Chat/Messages/Content/MarkdownBlocks.tsx Adds per-block rehype fade plugin instance when animate is enabled.
client/src/components/Chat/Messages/Content/MarkdownBlocks.bench.tsx Extends benchmark to measure fade mode and assert memoization stability.
client/src/components/Chat/Messages/Content/Markdown.tsx Wires smoothStreaming + message submitting state into MarkdownBlocks.animate.
client/src/components/Chat/Messages/Content/animate.tsx Implements word splitting, fade classification/state, rehype plugin, and AnimatedText.
client/src/components/Chat/Messages/Content/tests/animate.test.tsx Adds unit/integration tests for splitting, classification, plugin wrapping, and AnimatedText.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +34 to +37
const WORD_REGEX = /\S+\s*/g;
const NON_WHITESPACE_REGEX = /\S/;
const CJK_REGEX = /[\u2E80-\u9FFF\uAC00-\uD7AF\uF900-\uFAFF]/;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hiragana and Katakana are covered: ぀–ヿ sits inside the ⺀-鿿 range (CJK Radicals Supplement through CJK Unified Ideographs, which spans CJK Symbols/Punctuation, Hiragana, Katakana, and Extension A along the way). Verified: /[⺀-鿿가-힯豈-﫿]/.test('こんにちは') → true, same for 'カタカナ'. Added a kana-only regression test in aefc4de so this stays locked in CI.


Generated by Claude Code

Comment on lines +43 to +47
it('splits CJK runs into smaller segments', () => {
const parts = splitWords('これは日本語のテストです');
expect(parts.join('')).toBe('これは日本語のテストです');
expect(parts.length).toBeGreaterThan(1);
});

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in aefc4de — added a kana-only case asserting both a Hiragana-only and a Katakana-only string split into multiple segments and round-trip exactly.


Generated by Claude Code

@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review

claude added 3 commits August 12, 2026 08:21
Adds a native FlowToken-style fade-in for streamed message text, with no
changes to the streaming data path: a per-block rehype plugin wraps newly
arrived words in one-shot CSS fade spans, using document-order character
offsets so already-visible text never re-animates, even when markdown
re-parsing restructures the tree. Words still inside their animation
window replay identical props so in-flight fades are never cut short.

- New Content/animate.tsx: word splitting (Intl.Segmenter for CJK),
  offset-based new-text classification, rehype plugin factory, and an
  AnimatedText component for plain-text reasoning content
- MarkdownBlocks: per-block plugin instance appended to the cached
  rehype plugins only while animating; block memoization untouched
  (bench asserts identical code-block render counts)
- Animation gated on isSubmitting && isLatestMessage and dropped at
  stream end, so settled messages render without wrapper spans
- Skips code, pre, math/KaTeX, artifacts, citations, and MCP UI subtrees
- Smooth streaming toggle (default on) under Settings → Chat → Messages;
  animation disabled under prefers-reduced-motion
- Extends the streaming bench with a fade variant (+9% render time in
  jsdom, 62/62 code-block renders) and adds unit tests for the plugin,
  classification, and AnimatedText

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DrUMn8aEKtMY2QRZhpheJB
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DrUMn8aEKtMY2QRZhpheJB
@danny-avila
danny-avila force-pushed the claude/flowtoken-smooth-streaming-td4yj7 branch from aefc4de to 7c1d2a0 Compare August 12, 2026 12:21

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: aefc4deb3a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

segments.push({ start, value: part, animated: false, delay: 0 });
continue;
}
if (start >= state.prevCount) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reset offset tracking when rendered text contracts

When streamed Markdown completes syntax that hides source characters—such as See [OpenAI](https://openai.com becoming See [OpenAI](https://openai.com) for details, or an inline-code span closing—the HAST text count contracts because the URL/markers or code subtree are no longer counted. prevCount still contains the larger prior rendered count, so start >= state.prevCount classifies subsequent new words as old and suppresses their fade until the visible text grows past that stale offset; detect contraction or track stable source positions instead.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stall described here can't occur: prevCount is re-baselined to the current run's total at the end of every run (now via stageRun/commitRun, previously endRun), not only when text grows. So when a completing link hides URL characters, only the words arriving in that same single render are misclassified as old — the very next render's baseline is already the contracted count and fading resumes immediately. The worst case is a one-render pop of a few words each time a link's syntax completes, which we're accepting rather than paying for two-pass classification or source-position tracking on every token. (The mid-animation active map also keeps already-fading words unaffected by the contraction.)


Generated by Claude Code

@@ -39,6 +44,7 @@ const Markdown = memo(function Markdown({ content = '', isLatestMessage }: TCont
remarkPlugins={getRemarkPlugins()}
rehypePlugins={getRehypePlugins()}
components={getMarkdownComponents()}
animate={smoothStreaming && isLatestMessage && isSubmitting}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Disable the transform when reduced motion is requested

For users with prefers-reduced-motion: reduce, the media query only suppresses the CSS animation; this condition still enables the rehype plugin and AnimatedText, so every streaming update continues splitting and wrapping words in spans despite producing no visual effect. Those users therefore retain the feature's extra parsing, React elements, and DOM cost—particularly significant for long single-block responses—even though the setting text says it is disabled automatically; include the media preference in the render gate rather than relying only on CSS.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 05f648d — useMediaQuery('(prefers-reduced-motion: reduce)') is now part of the animate gate in both Markdown and Reasoning, so reduced-motion users skip the transform and span creation entirely. The CSS media query stays as a second layer of defense.


Generated by Claude Code

* stream ends so the settled message renders without wrapper spans.
*/
export function createFadePlugin(): Plugin<[], Root> {
const state = createFadeState();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Treat hydrated content as the animation baseline

When an active generation is reopened or resumed after navigation/reload, useResumeOnLoad hydrates the assistant placeholder with the already accumulated response before isSubmitting becomes true. This newly mounted plugin always starts with prevCount: 0, so it classifies the entire historical partial response as new, re-fades every word, and can create a large burst of spans instead of animating only deltas received after attachment; seed the tracker with the hydrated prefix for resumed streams.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 05f648d. Rather than threading the hydrated prefix down from the resume path, the plugin now decides at its own first run: if the first classified run already holds more than FADE_HYDRATION_THRESHOLD (120) characters, that content is treated as the baseline — nothing animates and prevCount is seeded to the full length, so only deltas received after attachment fade. A genuinely fresh stream's first per-frame delta is far below the threshold, so normal first-word animation is unaffected. Covered by new tests for both the rehype plugin and AnimatedText.


Generated by Claude Code


export function endRun(run: FadeRun): void {
const { state, now } = run;
state.prevCount = run.count;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Commit fade state only after React commits the render

With the React 18 concurrent root, this transformer and AnimatedText update prevCount, active, and animation timestamps while rendering, before React has committed any corresponding DOM. If a streaming render is interrupted or abandoned by a higher-priority update, the tracker still advances; a later committed render can then classify never-displayed deltas as old, or remove their fade after measuring the animation window from the abandoned render. Keep render-time classification transactional and publish the new tracker state only after the render commits.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 05f648d. Classification no longer mutates committed state during render: each run stages its result (stageRun) — new-animation entries and the next baseline offset — and MarkdownBlock publishes it via fade.commit() in a useLayoutEffect (same for AnimatedText). An abandoned render's staged run is simply overwritten by the next render, so never-displayed deltas are re-classified as new when they actually commit. Added a test asserting a never-committed render re-classifies identically.


Generated by Claude Code

…tion

Addresses Codex review on the smooth streaming fade:

- Hydrated/resumed content becomes the animation baseline: a renderer whose
  first run already exceeds FADE_HYDRATION_THRESHOLD (reconnected stream,
  conversation switch) no longer re-fades the entire accumulated response
- Classification is now transactional under React 18 concurrency: runs are
  staged during render and published via commit() from a layout effect, so
  abandoned renders (interruption, StrictMode double-render) leave no trace
- prefers-reduced-motion now disables the rehype transform and AnimatedText
  in the render gate, not just the CSS animation, so reduced-motion users
  skip the span-wrapping work entirely

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DrUMn8aEKtMY2QRZhpheJB
@danny-avila
danny-avila changed the base branch from main to dev August 12, 2026 12:40

Copy link
Copy Markdown
Collaborator Author

@codex review


Generated by Claude Code

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 05f648d7c2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

const state = createFadeState();
const plugin: Plugin<[], Root> = function rehypeFade() {
return (tree: Root) => {
const suppress = state.firstRun && countText(tree) > FADE_HYDRATION_THRESHOLD;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Use a real hydration signal for first runs

When a resumed response contains 120 characters or fewer, this condition treats the historical prefix as new and re-fades it; conversely, because MarkdownBlocks creates one plugin per block, a genuinely new paragraph first delivered in a chunk over 120 characters is treated as hydrated and receives no fade. Fresh evidence in this revision is that hydration is inferred solely from each renderer's text length, so the earlier resume issue remains for short prefixes and introduces false suppression for large new blocks; pass an explicit hydrated/baseline signal instead.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 72c4421 — hydration is now an explicit signal rather than a per-block length guess. Markdown captures whether substantial content already exists at the render where its animate gate flips on (the actual resume/switch/follow-up moment) and passes hydrated to each block's plugin; the flag clears after that render commits. So a genuinely new paragraph delivered in one large chunk mid-stream always animates (the false-suppression case), and resumed content becomes the baseline across all its blocks regardless of individual block sizes. The one remaining heuristic is the whole-message threshold at flip time, needed to distinguish a resume from a fresh stream's first delta — a sub-120-char resumed prefix briefly re-fades, which is visually harmless.


Generated by Claude Code

Comment on lines +125 to +127
<ThinkingContent
animate={smoothStreaming && !reducedMotion && effectiveIsSubmitting && isLast}
>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Skip word animation while reasoning is collapsed

With the default showThinkingAtom value of false, the reasoning panel is height-collapsed but remains mounted, and this condition still enables AnimatedText throughout generation. For long reasoning streams that means repeatedly splitting the entire accumulated text and maintaining one React node per word even though none of the animation is visible; gate the transform on expansion (while preserving an appropriate baseline when the panel opens) so the default collapsed path keeps rendering the raw string. CLAUDE.mdL54-L60

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 72c4421 — the animate gate now includes isExpanded, so collapsed reasoning renders the raw string with zero transform work. Expanding mid-stream mounts AnimatedText fresh with the accumulated backlog, which its hydration baseline treats as already-seen — only deltas after expansion fade.


Generated by Claude Code

Comment on lines +101 to +102
if (CJK_REGEX.test(token)) {
pushCjkParts(parts, token);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Segment all scripts that do not use spaces

For Thai, Lao, Khmer, Burmese, and other scripts that normally omit spaces, this condition never calls Intl.Segmenter, so the entire growing text is one part whose start offset remains zero. Once that part's initial animation window expires, later appended characters have start < prevCount and no active entry, meaning the rest of a continuously streamed response never fades; apply word segmentation to all supported scripts rather than limiting it to these CJK/Hangul ranges.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 72c4421 — the segmentation trigger now covers Thai, Lao, Tibetan, Myanmar, and Khmer ranges in addition to CJK/Hangul (SPACELESS_REGEX), all routed through the same Intl.Segmenter path (verified ICU segments each of these correctly). Added Thai and Burmese round-trip segmentation tests.


Generated by Claude Code

…soning

Second Codex review round on the smooth streaming fade:

- Hydration is now an explicit signal instead of a per-block length guess:
  Markdown captures whether substantial content already exists at the render
  where its animate gate flips on, and passes it to each block's plugin. New
  blocks mounting later in the stream always animate regardless of size, and
  resumed content becomes the baseline regardless of block sizes
- Word segmentation now covers all spaceless scripts (Thai, Lao, Tibetan,
  Myanmar, Khmer) in addition to CJK/Hangul, so continuously streamed text in
  those scripts keeps fading instead of freezing after the first window
- Reasoning text no longer runs the word transform while the thinking panel
  is collapsed; expanding mid-stream starts from a hydrated baseline

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DrUMn8aEKtMY2QRZhpheJB
@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 72c44212d6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

claude added 3 commits August 12, 2026 15:06
The word fade itself signals streaming, so the trailing block cursor
(result-streaming) and the pulsing thinking dot (result-thinking) are
now suppressed whenever the smooth streaming fade is enabled. Both
return when the setting is off or the device prefers reduced motion.
Extracts the shared gate into a useSmoothStreaming hook consumed by
Markdown, Reasoning, TextPart, DisplayMessage, EmptyText, and the
legacy loading fallback.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DrUMn8aEKtMY2QRZhpheJB
The pulsing thinking cursor now only renders while the smooth streaming
fade is off, so the tests asserting it set the toggle off first (at file
level where earlier renders would cache the atom's first read).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DrUMn8aEKtMY2QRZhpheJB
The trailing streaming cursor stays hidden while the fade is active (the
fade itself signals text arriving), but the pre-first-token dot returns:
nothing else tells the user the run started before any text exists.

Restyled to match the word fade rather than the classic size throb — it
fades in on the same 250ms ease-out curve, then breathes on opacity, so
"run starting" and "text arriving" read as one system. Applied only when
the fade is active; with the setting off or reduced motion preferred the
dot keeps its original pulseSize behavior, so the cursor assertions in
the existing suites hold unchanged.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DrUMn8aEKtMY2QRZhpheJB
@danny-avila
danny-avila merged commit ae24461 into dev Aug 12, 2026
19 checks passed
@danny-avila
danny-avila deleted the claude/flowtoken-smooth-streaming-td4yj7 branch August 12, 2026 17:21
LogicalAbsurd pushed a commit to LogicalAbsurd/LibreChat that referenced this pull request Aug 27, 2026
* 🚣‍♀️ feat: Smooth Streaming Text Fade-In

Adds a native FlowToken-style fade-in for streamed message text, with no
changes to the streaming data path: a per-block rehype plugin wraps newly
arrived words in one-shot CSS fade spans, using document-order character
offsets so already-visible text never re-animates, even when markdown
re-parsing restructures the tree. Words still inside their animation
window replay identical props so in-flight fades are never cut short.

- New Content/animate.tsx: word splitting (Intl.Segmenter for CJK),
  offset-based new-text classification, rehype plugin factory, and an
  AnimatedText component for plain-text reasoning content
- MarkdownBlocks: per-block plugin instance appended to the cached
  rehype plugins only while animating; block memoization untouched
  (bench asserts identical code-block render counts)
- Animation gated on isSubmitting && isLatestMessage and dropped at
  stream end, so settled messages render without wrapper spans
- Skips code, pre, math/KaTeX, artifacts, citations, and MCP UI subtrees
- Smooth streaming toggle (default on) under Settings → Chat → Messages;
  animation disabled under prefers-reduced-motion
- Extends the streaming bench with a fade variant (+9% render time in
  jsdom, 62/62 code-block renders) and adds unit tests for the plugin,
  classification, and AnimatedText

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DrUMn8aEKtMY2QRZhpheJB

* 🔧 chore: Fix Import Order in Markdown and Settings Registry

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DrUMn8aEKtMY2QRZhpheJB

* ✅ test: Cover Kana-Only CJK Word Segmentation

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DrUMn8aEKtMY2QRZhpheJB

* 🛡️ fix: Harden Streaming Fade for Resume, Concurrency, and Reduced Motion

Addresses Codex review on the smooth streaming fade:

- Hydrated/resumed content becomes the animation baseline: a renderer whose
  first run already exceeds FADE_HYDRATION_THRESHOLD (reconnected stream,
  conversation switch) no longer re-fades the entire accumulated response
- Classification is now transactional under React 18 concurrency: runs are
  staged during render and published via commit() from a layout effect, so
  abandoned renders (interruption, StrictMode double-render) leave no trace
- prefers-reduced-motion now disables the rehype transform and AnimatedText
  in the render gate, not just the CSS animation, so reduced-motion users
  skip the span-wrapping work entirely

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DrUMn8aEKtMY2QRZhpheJB

* 🌏 fix: Refine Fade Hydration Signal, Spaceless Scripts, Collapsed Reasoning

Second Codex review round on the smooth streaming fade:

- Hydration is now an explicit signal instead of a per-block length guess:
  Markdown captures whether substantial content already exists at the render
  where its animate gate flips on, and passes it to each block's plugin. New
  blocks mounting later in the stream always animate regardless of size, and
  resumed content becomes the baseline regardless of block sizes
- Word segmentation now covers all spaceless scripts (Thai, Lao, Tibetan,
  Myanmar, Khmer) in addition to CJK/Hangul, so continuously streamed text in
  those scripts keeps fading instead of freezing after the first window
- Reasoning text no longer runs the word transform while the thinking panel
  is collapsed; expanding mid-stream starts from a hydrated baseline

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DrUMn8aEKtMY2QRZhpheJB

* 🖱️ feat: Hide Streaming Cursors While Smooth Fade Is Active

The word fade itself signals streaming, so the trailing block cursor
(result-streaming) and the pulsing thinking dot (result-thinking) are
now suppressed whenever the smooth streaming fade is enabled. Both
return when the setting is off or the device prefers reduced motion.
Extracts the shared gate into a useSmoothStreaming hook consumed by
Markdown, Reasoning, TextPart, DisplayMessage, EmptyText, and the
legacy loading fallback.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DrUMn8aEKtMY2QRZhpheJB

* ✅ test: Pin Cursor Assertions to Fade-Off State

The pulsing thinking cursor now only renders while the smooth streaming
fade is off, so the tests asserting it set the toggle off first (at file
level where earlier renders would cache the atom's first read).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DrUMn8aEKtMY2QRZhpheJB

* 💫 feat: Restore Start-of-Run Dot With Fade-Matched Treatment

The trailing streaming cursor stays hidden while the fade is active (the
fade itself signals text arriving), but the pre-first-token dot returns:
nothing else tells the user the run started before any text exists.

Restyled to match the word fade rather than the classic size throb — it
fades in on the same 250ms ease-out curve, then breathes on opacity, so
"run starting" and "text arriving" read as one system. Applied only when
the fade is active; with the setting off or reduced motion preferred the
dot keeps its original pulseSize behavior, so the cursor assertions in
the existing suites hold unchanged.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DrUMn8aEKtMY2QRZhpheJB

---------

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants