-
Notifications
You must be signed in to change notification settings - Fork 47.3k
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
useReducer - eagerReducer optimization discussion/questions #15088
Comments
I don't know what that means. What are you trying to do? Preferably describe it from user perspective than impl details.
Why does it matter to you? These heuristics can change over time. They shouldn't affect how your reducer works.
We are rendering that component but the bailout still determines whether we'll recurse on children or not. That's the important part. |
I stand corrected! This indeed is working thanks for this line. It's a new concept (for me) that render might get called but it might not result in children reconciliation and I got confused.
From the user perspective, everything works OK(-ish). The whole reason I've started testing this was to know the implementation details - not to depend on them or exploit them but to get a better understanding of how things work. Therefore I'd like to focus on some of the implementation details here. After investigating this more I must correct what I have stated about the observed behaviour - This seems like we could optimize this because we could not schedule the render at all in this bailout case, but again - I might not understand something about how Fiber works. Maybe this is needed and I'm just confused about it. The more interesting demo I can provide is this - https://codesandbox.io/s/735onv7mv6 . Just click BAILOUT 3x times and then click INCREMENT. What we can observe is that BAILOUT actions are preserved in the action queue and are being processed when we finally call render. And this is somewhat strange because those actions were previously "ignored" because we decided to bail out based on them. This is IMHO strange because initially those 3 actions were computing new state using "old" reducer, but at the render time they might use the "new" reducer - the one seeing the newest props & stuff. And if the bail out logic inside reducer depends i.e. on some props (when I try to think how this could happen in real life I'm imagining |
I'd like to continue the discussion started by me under a recent blog post by Dan as encouraged by Dan 😉 gaearon/overreacted.io@99bfdca#r32694433
Just to summarize what I've stumbled upon when experimenting with useReducer after reading that hoisted & declared in render reducers are treated differently (I've wanted to explore how they are handled by React):
fiber.expirationTime
is not 0 (NoWork) and the work gets scheduled right away. Any pointers regarding this? Is this valid? Might this be a bug somewhere?Note I'm happy to provide documentation changes if needed, I'd like to discuss those points first to get a better understanding of things.
The text was updated successfully, but these errors were encountered: