Fix 613 - remove random react key generation #664
Conversation
… this fixes unnecessary rerenders due to react thinking this is a new component.
|
You'll need to check against the Switch, this was a major issue there. |
|
I remember, but works, also in a menu. I ran the tests and dmc docs with the index. Here are the test results: |
|
When I run the tests individually - the tests pass: collecting ... |
|
Hi @chgiesse Thanks for the PR! It makes sense that it would be an improvement. I tried the Stepper example in the docs both with the current release and with your change, and I don't see much improvement. It's usually smoother when run locally, rather than in the live docs site, but I still see the flicker. Can you describe the difference you see and how you measured the performance improvement? |
|
Hi @AnnMarieW Yes so the stepper is fixed for me now and I think the main reason why I face the issue more than the examples in the docs is that the stepper updates the URL and the whole pages gets loaded again. With the random ID, although the components are mostly the same react treats them as completely new component leading to the rendering issues. Beside that, I could notice better memory management with quicker going to base level memory usage after heavy loads. Around 20% less memory usage overall. You can see these metrics in the dev tools perfomance monitor. I compared the docs with each version. Also lighthouse score went from 83 to 99 - with first contentfull paint from 1.2s to 0.5s and largest contentful paint from 2.4 to 1.0! I used slow 4g throttling and cache clearing to get the same request times like your deployed version. After all these test the patched version dropped down to 108mb while the dash-mantine-components.com version is still at 158mb. I think this is all due to better caching and less rendering. Also easier for the heap to garbage collect unused elements/components. |
|
Thanks for the detailed explanation! I tried it in all the pages that used the function and they all worked (at least as well as the current version), plus all the tests pass. I think there is no harm in merging this. I have few other open PRs that are ready for review, and I'll add this one to the queue for the next release. Before merging, I like to see if @alexcjohnson has time to take a look because he provides such great feedback. 🙂 |
|
This looks great, with one speculative issue: the plural |
|
Hi @alexcjohnson, |
alexcjohnson
left a comment
There was a problem hiding this comment.
💃 Looks good, thanks for the tweak @chgiesse!
|
Thanks @chgiesse Before merging could you please update the CHANGELOG.md? At the top of the file, it should look like Then a short description, PR # and your GitHub username. |
|
Hi! I just wanted to checkin on a snippet from the documentation
That shouldn't be a problem, because the dashRenderer renders the whole list of items also with patch operations - right? I have multiple callbacks with patch operations on mantine components with the updated version and they work as expected. |
|
I think this is OK because the index in this case is the order of the props that need to be rendered. For example, the But I'll leave this open for a bit in case @alexcjohnson wants to weigh in again |
|
Sounds good! |
|
Agreed, index is the best we can do given the information we have at this stage. |
|
@alexcjohnson - thanks for double checking @chgiesse - thanks again for this PR - it's a nice performance improvement for rendering components-as-props |
Hey!
After some lucky coincidence and investigation, I think I found the issue leading to the rendering issues. I just had to change the
keyprop innewDashRenderComponentfromMath().random()to a stable value (index ?? 0).you can find details in the official react docs https://react.dev/learn/rendering-lists#rules-of-keys
I could notice overall rendering performance improvements and these rendering artefacts mentioned in the issue are removed to 99.9%.
Best regards,
Christian