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

[code-infra] Fix StrictMode effects not being called twice in React 19 tests #45812

Merged
merged 4 commits into from
Apr 10, 2025

Conversation

bernardobelchior
Copy link
Member

@bernardobelchior bernardobelchior commented Apr 4, 2025

Related to testing-library/react-testing-library#1390.

In React 19, StrictMode won't double-call effects on initial mount unless StrictMode is at the root of the app. Our previous way of enabling StrictMode created a Wrapper, meaning that the Wrapper component was at the root of the app, resulting in the double calling of effects not happening in initial mount in React 19.

This PR uses the new property reactStrictMode from @testing-library/react to enable double-calling on initial mount in React 19 tests.

This option was introduced in this PR, that's why I also upgraded the dependency.

This PR also changes some tests. In the ones I was most confident, I actually updated the assertions. For the ones I wasn't, I disabled strict mode for that particular test in React 19. If you know how to fix it, please let me know 😄

@bernardobelchior bernardobelchior added scope: code-infra Specific to the core-infra product bug 🐛 Something doesn't work labels Apr 4, 2025
@bernardobelchior bernardobelchior changed the title [code-infra] Use reactStrictMode from @testing-library/react [code-infra] Fix StrictMode not being enabled for React 19 tests Apr 4, 2025
@bernardobelchior bernardobelchior changed the title [code-infra] Fix StrictMode not being enabled for React 19 tests [code-infra] Fix StrictMode effects not being called twice in React 19 tests Apr 4, 2025
@mui-bot
Copy link

mui-bot commented Apr 4, 2025

Netlify deploy preview

https://deploy-preview-45812--material-ui.netlify.app/

Bundle size report

No bundle size changes (Toolpad)
No bundle size changes

Generated by 🚫 dangerJS against 9c66533

@@ -20,4 +20,7 @@ module.exports = {
'**/build/**',
'docs/.next/**',
],
// detect-modules doesn't work with @babel/register
// https://github.com/babel/babel/issues/6737
'node-option': ['no-experimental-detect-module'],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cherry-picked from 0f92cc3 (#45630)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks again in Node 23, but ok, let's worry about that later

@bernardobelchior bernardobelchior force-pushed the render-strict-mode branch 2 times, most recently from b474437 to 61128ac Compare April 8, 2025 08:17
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Apr 8, 2025
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Apr 8, 2025
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Apr 8, 2025
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Apr 8, 2025
@bernardobelchior bernardobelchior marked this pull request as ready for review April 8, 2025 15:56
@ZeeshanTamboli
Copy link
Member

@bernardobelchior Should we merge #45828?

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Apr 9, 2025
@bernardobelchior
Copy link
Member Author

@bernardobelchior Should we merge #45828?

We can. I'll just rebase this PR.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Apr 9, 2025
@bernardobelchior bernardobelchior requested a review from a team April 9, 2025 10:34
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Apr 9, 2025
@bernardobelchior bernardobelchior merged commit 6772d5d into mui:master Apr 10, 2025
19 checks passed
@bernardobelchior bernardobelchior deleted the render-strict-mode branch April 10, 2025 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work PR: out-of-date The pull request has merge conflicts and can't be merged scope: code-infra Specific to the core-infra product
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants