perf(markdown): cache completed streaming blocks#7306
Conversation
Coverage Report
File CoverageNo changed files found. |
|
✅ Admin Preview Image Ready! 🕒 Time: 2026-07-14 21:12:06 (UTC+8) |
|
✅ Build Successful - Preview fastgpt Image for this PR: 🕒 Time: 2026-07-14 21:14:28 (UTC+8) |
There was a problem hiding this comment.
Pull request overview
This PR improves streaming Markdown rendering performance in the app by splitting streamed Markdown into root-level blocks and memoizing completed blocks so only the actively-growing block re-renders. It maintains the existing “tail-only” fade animation on the active block and preserves correctness for cross-block reference links / GFM footnotes by falling back to full-document rendering when those constructs are present.
Changes:
- Add a
splitMarkdownBlocksutility that parses Markdown and slices the source into stable root-level blocks (with a full-document fallback for references/footnotes). - Update the Markdown renderer to render blocks via a memoized
MarkdownStreamBlock, applying the streaming tail animation only to the last block. - Add unit tests for block splitting behavior and rendering equivalence, and add required parser dependencies.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| projects/app/test/components/Markdown/streamMarkdownBlocks.test.ts | Adds tests covering block splitting rules, offsets, and render equivalence across block rendering vs full-document rendering. |
| projects/app/src/components/Markdown/streamMarkdownBlocks.ts | Implements Markdown root-level block splitting using unified + remark-parse with math/GFM support and fallbacks for references/footnotes/whitespace-only input. |
| projects/app/src/components/Markdown/index.tsx | Refactors streaming rendering to memoize completed blocks and keep tail fade on the active (last) block. |
| projects/app/package.json | Adds direct dependencies needed for parsing (remark-parse, unified). |
| pnpm-lock.yaml | Updates lockfile for the newly added dependencies. |
Files not reviewed (1)
- pnpm-lock.yaml: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
Verification
pnpm exec vitest run -c vitest.config.ts test/components/Markdown/streamMarkdownBlocks.test.ts test/components/Markdown/rehypeStreamAnimated.test.ts test/components/Markdown/utils.test.ts --run --coverage=falseNo documentation changes.