Closed
Description
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):
- I have no idea how to reenter eagerReducer calculation after first scheduled work (& after render gets fully processed & committed). This might very well be just me not understanding how fibers work - but currently I'm confused by this. It doesn't enter this code branch because
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? - The logic around reducer bailouts is somewhat iffy for me - maybe it's just a matter of mentioning those in the documentation:
- not every reducer update can bailout from rendering. If the action queue gets processed in the render phase then it's just not possible, we are already rendering after all.
- action queue gets processed in the render phase for reducers declared inside render, this means that any new state computation might depend on the "fresh" props. This is not the case for the bailout mechanism though - it's only possible to perform a bailout when dispatching an action (so when we do not have access to the fresh props). Should this restriction be mentioned in the docs? IMHO this behaviour is inconsistent - for the greater good, so it's acceptable but I think it should be documented because it's slightly inconsistent & people might trip over this.
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.