-
-
Notifications
You must be signed in to change notification settings - Fork 72
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
Concurrent rendering problem in React 18 #177
Comments
Does it work as expected if you update If that's the case, it's a behavioral change in React 18 useReducer, which is somewhat reasonable. It's how it works now to be full compatible for concurrent rendering. If it causes serious performance problems, like heavy computation, we need to consider wrapping the heavy computation with |
This is really not solvable unless we give up concurrency support. If React provides native useContextSelector, react-tracked can migrate to it and everything will work nicely. So, what is your real issue? Do you see any performance drop? Double rendering is an expected outcome as of now. |
@dai-shi Thanks for answering. I really didn't dig much into this, I just see extra renders in a component that doesn't depend on a sub-context that was affected by some outer update, and I don't like it. I see that useMemo (and other techniques like splitting/wrapping you mentioned here) can fix it, while react-tracked can't (in React 18 App). Maybe these extra renders don't matter with react-tracked, I haven't done any performance testing, but they obviousely happen at the App level. I think there should be a special note regarding React 18 in the lib documnetation, as it really confuses. |
I forked minimal example on codesandbox and sligthly changed it: https://codesandbox.io/s/damp-sun-0bhfb1?file=/src/index.js. My goal is to make sure that the lib does prevent re-renders, so I separated render counters for TextBox and Counter components. I would expect their counters to increment independently as I change different parts of the state. But they increase, as if it were a single counter. Also, console.log shows that both componentes are rendered every time the state changes. Am I doing it wrong?
Repro:
Expectation:
Result:
The text was updated successfully, but these errors were encountered: