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

Multiple react re-renderings when updating tree data #798

Open
avmalyutin opened this issue Jan 22, 2024 · 2 comments
Open

Multiple react re-renderings when updating tree data #798

avmalyutin opened this issue Jan 22, 2024 · 2 comments

Comments

@avmalyutin
Copy link

avmalyutin commented Jan 22, 2024

Disclaimer: I use the term re-renderings. By this term here I mean react re-renderings and not browser re-renderings.

I have prepared a code example to reproduce the issue: codesandbox
Code example can be tested in separate window: separate window

Steps to reproduce:

  1. Expand all Elements
  2. Toggle Switch Button of single Element
  3. Internally: object treeData will be completely recalculated and passed into rc-tree component
  4. Expected results:
    • I expect here, that rc-tree will be re-rendered 1 time (because treeData has changed)
    • I expect here, that only single CustomTreeNode will be re-rendered, which Switch component I have toggled on step 2.
  5. Actual results:
    • rc-tree component re-rendered 3 times instead of 1 -> NOK
    • only one CustomTreeNode will be re-rendered -> OK

Example video:
https://github.com/react-component/tree/assets/8103060/78917bcd-1e21-48ce-907a-4cc2082ff8d7

Duration of re-renderings from the video for rc-tree and all of its descendants:

  • re-rendering no.1: 11.6 ms
  • re-rendering no.2: 6.1 ms
  • re-rendering no.3: 13.5 ms
Re-rendering screenshots

Re-rendering no.1:
rerenreding-1

Re-rendering no.2:
rerenreding-2

Re-rendering no.3:
rerenreding-3


My questions are:

  • Is this a known behavior?
  • Is it possible to fix it? (reduce number of re-renderings from 3 to 1. This should improve performance dramatically (11.6ms vs 31.2 ms - almost 3 times faster)

Thank you for your work and thank you in advance

@roflc0pter
Copy link

I am happy that you have "only" three (react)-re-renders. In my component a single change on a TreeNode such as expanding it, triggers up 70 re-renders. On a simple interaction such as mouse over on a item or expanding a node with maybe 10 items (including children) in total it causes up to 680 re-renders. And yes, nothing on my renderTitle component was changed, no keys, no props. Everything the same but tons of re-renders.

@blackswanny
Copy link

we also found rc-tree one of the most under performing component. Chrome Dev Tools React Profiler indicates many times more unnecessary re-renders. imho, applying memoization to all func callbacks and data will help the problem.
So I would cover it with useCallback and useMemo whenever possible

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

No branches or pull requests

3 participants