Bug: onRender of parent <Profiler> called for each child update
See original GitHub issueWith Profiler API it’s not possible (or at least not clear) how to measure commit time for parent components which renders child which is also should be profiled.
Example from the documentation:
Profiler components can also be nested to measure different components within the same subtree:
<App>
<Profiler id="Panel" onRender={callback}>
<Panel {...props}>
<Profiler id="Content" onRender={callback}>
<Content {...props} />
</Profiler>
<Profiler id="PreviewPane" onRender={callback}>
<PreviewPane {...props} />
</Profiler>
</Panel>
</Profiler>
</App>
In this case, we can’t measure separately updates only for Panel component as the same callback will be called for updates in Content or PreviewPane.
React version: 16.9.0
I prepared a simplified demo: https://codesandbox.io/s/react-codesandbox-9zf7v
As you can see here wrapper profiler updated every time with counter profiler even though that wrapper component is not updated.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5
Top Results From Across the Web
Why does React re-render children when the parent changes?
React achieves a fast and responsive UI by re-rendering components on every state change (using setState) or from changes of props, ...
Read more >Reasons React would be calling render() when memo returns ...
My understanding is that the point of memo is actually specifically for this use case: to prevent children from updating when a parent...
Read more >React re-renders guide: everything, all at once - Developer way
A component will re-render itself if its parent re-renders. Or, if we look at this ... This can also be called “wrap state...
Read more >Update parent's state from child component : r/reactjs - Reddit
This is working fine but React throws me this error on console: index.js:1 Warning: Cannot update a component ('Parent') while rendering a ......
Read more >Warning: Each Child in a List Should Have a Unique 'key' Prop
Learn what causes"Warning: Each child in a list should have a unique ... Then React will get confused and re-render the incorrect element....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The behavior you have described how the API was intentionally designed. Profiler reports times for any/ever update within its subtree. (This enables you to provide an entire application, while also collecting times for certain subtrees.)
If you’re interested in the Profiler API’s design, you can find the RFC here: https://github.com/reactjs/rfcs/blob/master/text/0051-profiler.md
Right. I understood what you were asking for. That’s just not how the Profiler API was designed to work. 😄
Implicit in my previous comment was that you would need to subtract subtree durations from a Profiler to determine the duration only for the single component in between, but again- we don’t recommend using the API that way.