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

v2.2.0 causes double renders in tests #81

Closed
rohan-deshpande opened this issue May 24, 2020 · 1 comment
Closed

v2.2.0 causes double renders in tests #81

rohan-deshpande opened this issue May 24, 2020 · 1 comment
Labels
wontfix This will not be worked on

Comments

@rohan-deshpande
Copy link
Contributor

It seems that as of v2.2.0 sweet state is causing double unnecessary double renders in enzyme tests.

@albertogasparin albertogasparin added the wontfix This will not be worked on label May 24, 2020
@albertogasparin
Copy link
Collaborator

In order to be StrictMode compliant we had to remove an optimisation that prevented a re-render from happening if the updated state was the same. Indeed, while that optimisation was conditionally calling setState on update, in reality it was making React in StrictMode completely ignoring the update under certain conditions.

As a matter of fact, that is considered a bad practice in the docs and given the risk of such optimisation making sweet-state buggy with concurrent mode, it has been decided to let React to handle the update.

With the adoption of batching by sweet-state and based on some comments left by React devs in this issue it looks it should not be really a problem from the performance point of view.

From the testing side of things, if you we counting re-renders then I understand it might appear as children get re-rendered more (as before some re-renders were automatically skipped) but it is a trade-off we have to accept for better React consistency: every action that calls dispatch or setState will trigger a re-render even if the state is unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants