Skip to content

fix: update streamed code block content - #583

Closed
Kinfe123 wants to merge 1 commit into
vercel:mainfrom
Kinfe123:fix/streamed-code-block-content
Closed

fix: update streamed code block content#583
Kinfe123 wants to merge 1 commit into
vercel:mainfrom
Kinfe123:fix/streamed-code-block-content

Conversation

@Kinfe123

Copy link
Copy Markdown
Contributor

Summary

  • include rendered code content in the Markdown code memo comparison
  • reuse the same content extraction for rendering and memoization
  • add a regression test for replacing a streamed fenced block in place

Why

MemoCode previously compared only className and source position. Replacing a streamed code block without moving it in the document, such as changing first to second, kept the same source position and caused React to retain the stale rendered code. Comparing the extracted code text preserves the existing optimization for unchanged blocks while allowing changed blocks to update.

Validation

  • pnpm build:packages
  • pnpm --filter streamdown test (73 files, 1,019 tests)
  • pnpm check
  • pnpm --filter streamdown build

@vercel

vercel Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

@Kinfe123 is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.

@dasheidt

Copy link
Copy Markdown
Contributor

There is an adjacent half to this that content comparison alone will not reach: CodeComponent's block branch never forwards its rest props to CodeBlock at all, while the inline branch four screens up does spread them. So an attribute a consumer puts on a code element via a rehype plugin reaches inline code and silently disappears on code blocks, whatever the comparator decides.

And once it is forwarded, CodeBlockBody's comparator lists five props by hand and ignores the rest, so a forwarded attribute keeps the value it first rendered with even when MemoCode does re-render.

I opened #585 for those two, with a test that fails with only the forwarding half applied, so each is pinned separately. It is independent of this PR — happy to rebuild it on top if this lands first.

Worth noting that #584 (comparators generally) makes the in-place content case here fall out too, since a re-parsed block hands its code component new children. If that shape is the one the maintainers want, sameCodeContent may not be needed; if they prefer the targeted comparator, this PR stands on its own.

@farnabaz

Copy link
Copy Markdown
Collaborator

Thanks for the PR. The issue was fixed in #584, but I picked your test in another PR (#593) and added you as a co-author.
Closing this.

@farnabaz farnabaz closed this Aug 21, 2026
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