Bug: updating state to an existing value is (incorrectly?) triggering a re-render about react HOT 5 OPEN
Here is the full text of the set state optimization [as at 13th April]:
If the new value you provide is identical to the current state, as determined by an Object.is comparison, React will skip re-rendering the component and its children. This is an optimization. Although in some cases React may still need to call your component before skipping the children, it shouldn’t affect your code.
I think that wording the caveat that the re-render optimization is skipped "in some cases" implies that the de-optimization should only occur in outlier circumstances (eg nested set states in an effect), and not for standard happy path cases.
I think that skipping the re-render optimization for a happy path case is a bug.
I appreciate that component renders should be pure, and so an additional re-render should not cause any functional problems. However, I still think that this current behaviour is incorrect.
The current behaviour hurt me when I was trying to write a test to assert that a component should not render after a particular event, but a render did occur. It would be fair to ask: "Why assert render behaviour in a test?". I think it is fair to assert re-rendering behaviour given that re-rendering can be expensive with react
Might be a duplicate of #18098
On the linked documentation page it literally says that this is expected:
Although in some cases React may still need to call your component before skipping the children, it shouldn’t affect your code
It could be a joke but... Have you tried to remove the StictMode?
I can confirm that this bug appears without strict mode on
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.