question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: onRender of parent <Profiler> called for each child update

See original GitHub issue

With 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:closed
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
bvaughncommented, Feb 3, 2020

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

0reactions
bvaughncommented, Feb 3, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found