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

[test] Count profiler renders not passive effects #26678

Merged
merged 3 commits into from
Jun 11, 2021

Conversation

eps1lon
Copy link
Member

@eps1lon eps1lon commented Jun 9, 2021

Uses React.Profiler instead of useEffect 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.

@eps1lon eps1lon added the test label Jun 9, 2021
@eps1lon eps1lon added this to the Concurrent React milestone Jun 9, 2021
@mui-pr-bot
Copy link

mui-pr-bot commented Jun 9, 2021

No bundle size changes (experimental)

Generated by 🚫 dangerJS against a3810c5

@eps1lon eps1lon marked this pull request as ready for review June 9, 2021 18:38
@oliviertassinari
Copy link
Member

@eps1lon
Copy link
Member Author

eps1lon commented Jun 10, 2021

Thanks for the ping, we do count commits with a useEffect

Yep, that'll no longer work in React 18. You should start migrating to React.Profiler when you get the chance.

test/utils/components.js Outdated Show resolved Hide resolved
@oliviertassinari
Copy link
Member

oliviertassinari commented Jun 10, 2021

@eps1lon Reading this thread reactwg/react-18#19, it seems that we could measure renders with a useEffect if we disable the strict mode for a specific test (not saying that we should do it, but to make sure I got it right).

@dtassone I have opened this umbrella issue for React 18: mui/mui-x#1870.

@eps1lon
Copy link
Member Author

eps1lon commented Jun 11, 2021

No that could still fail once Offscreen APIs get implemented

@eps1lon eps1lon merged commit 7f571c8 into mui:next Jun 11, 2021
@eps1lon eps1lon deleted the test/strict-effects-render-count branch June 11, 2021 06:55
@oliviertassinari
Copy link
Member

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.
Copy link
Member

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?

Suggested change
* 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.

Copy link
Member Author

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.

oliviertassinari added a commit to oliviertassinari/material-ui that referenced this pull request Jun 26, 2021
oliviertassinari added a commit to oliviertassinari/material-ui that referenced this pull request Jul 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants