Skip to content

fix(streamdown): re-render memoized components when node offset changes#538

Open
julesyoungberg wants to merge 3 commits into
vercel:mainfrom
julesyoungberg:feature/rerender-on-offset-change
Open

fix(streamdown): re-render memoized components when node offset changes#538
julesyoungberg wants to merge 3 commits into
vercel:mainfrom
julesyoungberg:feature/rerender-on-offset-change

Conversation

@julesyoungberg

Copy link
Copy Markdown

Description

Fixes stale DOM when markdown is updated in the middle of an existing block. Memoized leaf components (ol, ul, p, headings, etc.) use sameNodePosition to skip re-renders, but it only compared line and column. When content changed without updating line/column (only offset, e.g. injecting a link mid-line), React kept stale output until Streamdown remounted.

sameNodePosition is shared by all memoized markdown components via sameClassAndNode, so this fix applies broadly rather than to a single element type.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Changes Made

Testing

  • All existing tests pass
  • Added new tests for the changes
  • Manually tested the changes
pnpm exec vitest run __tests__/components-rerender.test.tsx

All 18 tests in that file pass.

Checklist

  • My code follows the project's code style
  • I have performed a self-review of my own code
  • My changes generate no new warnings or errors
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have created a changeset (pnpm changeset)

Additional Notes

No documentation or inline comment changes — this is an internal comparator fix with no API surface change. The new test documents the edge case.

@vercel

vercel Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

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

A member of the Team first needs to authorize it.

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.

1 participant