Skip to content

Conversation

@oliviertassinari
Copy link
Member

@oliviertassinari oliviertassinari commented Aug 23, 2025

Fix #46804 at the root (where the test case comes from). As you can see with the failing test case added, when an array is provided, React in strict mode will render twice, the instances will be different, and the warning triggers.

Considering that the effect depends on JSON.stringify, the comparison should continue to use it to fix the Strict Mode support.

The alternative solution is to remove JSON.stringify altogether, and have developers using this utility guarantee that the default value never changes; however, the warning was added to help developers spot cases where they do clearly stupid things, it's not about being a purist. We should keep it easy, so not go down this path.

For those worried about JSON.stringify performance, a cool one: https://v8.dev/blog/json-stringify.

@oliviertassinari oliviertassinari added type: bug It doesn't behave as expected. package: utils Specific to the utils package. internal Behind-the-scenes enhancement. Formerly called “core”. labels Aug 23, 2025
@mui-bot
Copy link

mui-bot commented Aug 23, 2025

Netlify deploy preview

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

Bundle size report

Bundle Parsed size Gzip size
@mui/material 0B(0.00%) 0B(0.00%)
@mui/lab 0B(0.00%) 0B(0.00%)
@mui/system 0B(0.00%) 0B(0.00%)
@mui/utils 0B(0.00%) 0B(0.00%)

Details of bundle changes

Generated by 🚫 dangerJS against 151366d

@oliviertassinari oliviertassinari force-pushed the useControlled-improve-strict-mode-handling branch from 9e5a62c to 3b52cff Compare August 23, 2025 22:30
@oliviertassinari oliviertassinari changed the title [internal] Improve useControlled strict mode handling [internal] Improve useControlled() strict mode handling Aug 24, 2025
Signed-off-by: Olivier Tassinari <oliviertassinari@users.noreply.github.com>
@oliviertassinari oliviertassinari merged commit 41da88f into mui:master Aug 26, 2025
18 checks passed
@oliviertassinari oliviertassinari deleted the useControlled-improve-strict-mode-handling branch August 26, 2025 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal Behind-the-scenes enhancement. Formerly called “core”. package: utils Specific to the utils package. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants