Closed Ramon-W closed 3 months ago
Fixed link
That's because your components
prop always changes on every render.
See also https://github.com/remarkjs/react-markdown/issues/791#issuecomment-1933576418
Hi! This was closed. Team: If this was fixed, please add phase/solved
. Otherwise, please add one of the no/*
labels.
Initial checklist
Affected packages and versions
react-markdown@9.0.1, react-markdown@latest
Link to runnable example
https://codesandbox.io/p/devbox/boring-kepler-mzcxps?file=%2Fsrc%2Fapp.tsx%3A56%2C9
Steps to reproduce
On the sandbox:
p
.p
tag is being re-rendered even when it is not changing, and the non-custom components are not being re-rendered.Expected behavior
The custom component should act normal and not be re-rendered unnecessarily. I believe regular components are given a key equal to the index, but I am unable to figure out how to apply this index on custom components, which might fix this issue. I have also attempted using
memo
but it did not work for me.My specific issue is that I am streaming very long outputs from LLMs and passing them into react markdown, and I am using many stateful, custom components. However, these custom components are always being re-rendered and are unusable until the streaming stops.
Actual behavior
The custom components re-renders every time
children
changes.Runtime
Node v17
Package manager
npm 8
OS
Linux, macOS
Build and bundle tools
Vite