-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
[test] Count profiler renders not passive effects #26678
Conversation
Thanks for the ping, we do count commits with a useEffect in https://github.com/mui-org/material-ui-x/blob/45093913e390b9c71b89a3debf76a58a46e68a2f/packages/grid/x-grid/src/tests/sorting.XGrid.test.tsx#L232-L241. |
Yep, that'll no longer work in React 18. You should start migrating to |
@eps1lon Reading this thread reactwg/react-18#19, it seems that we could measure renders with a @dtassone I have opened this umbrella issue for React 18: mui/mui-x#1870. |
No that could still fail once Offscreen APIs get implemented |
@eps1lon Oh sure, right. I meant for the tests specifically. All good |
@@ -37,3 +35,29 @@ export class ErrorBoundary extends React.Component { | |||
return this.props.children; | |||
} | |||
} | |||
|
|||
/** | |||
* Allows counting how many times the owner of `RenderCounter` rendered. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on https://reactjs.org/docs/profiler.html#onrender-callback, would this be more accurate?
* Allows counting how many times the owner of `RenderCounter` rendered. | |
* Allows counting how many times the owner of `RenderCounter` rendered or | |
* a component within the RenderCounter tree "commits" an update. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! I didn't really think about this use case considering how we used useEffect
. I'll think about how we better document this.
Uses
React.Profiler
instead ofuseEffect
to count commits (implementation in https://github.com/eps1lon/material-ui/blob/af74ef1e9fcbbc40d23b0fd6f05fb05fac42689e/test/utils/components.js#L45-L63).useEffect
will have slightly different semantics in React 18. See reactwg/react-18#18 for more context./cc @oliviertassinari and @dtassone. I think one of you asked me a while back how to test render count.