Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Components Always Re-rendered #821

Closed
4 tasks done
Ramon-W opened this issue Mar 4, 2024 · 4 comments
Closed
4 tasks done

Custom Components Always Re-rendered #821

Ramon-W opened this issue Mar 4, 2024 · 4 comments
Labels
🙋 no/question This does not need any changes 👎 phase/no Post cannot or will not be acted on

Comments

@Ramon-W
Copy link

Ramon-W commented Mar 4, 2024

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:

  1. Replace any component with a custom component, in this case p.
  2. Inspect element and observe how the 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

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Mar 4, 2024
@JounQin
Copy link
Member

JounQin commented Mar 4, 2024

image

@Ramon-W
Copy link
Author

Ramon-W commented Mar 4, 2024

Fixed link

@JounQin
Copy link
Member

JounQin commented Mar 4, 2024

That's because your components prop always changes on every render.

See also #791 (comment)

@JounQin JounQin closed this as not planned Won't fix, can't repro, duplicate, stale Mar 4, 2024
@JounQin JounQin added the 🙋 no/question This does not need any changes label Mar 4, 2024

This comment has been minimized.

@github-actions github-actions bot added 👎 phase/no Post cannot or will not be acted on and removed 🤞 phase/open Post is being triaged manually labels Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙋 no/question This does not need any changes 👎 phase/no Post cannot or will not be acted on
Development

No branches or pull requests

2 participants