You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a component calls setState, we must update the pendingWorkPriority on its fiber and on all its ancestor fibers up to the root. When we get to the root, we ensure that the root is scheduled:
If setState is called multiple times consecutively, we walk the path each time. And if a callback is passed to setState, that requires an additional walk.
Because the priority of a child is always greater than or equal to the priority of its parent, it'd be nice to optimize this by stopping whenever the condition in step 1 fails.
The problem is step 2. We can't assume that the root of a tree is scheduled just because it has pending work: roots are unscheduled if an uncaught error is thrown in that tree. So we have to ensure the root is scheduled for every update.
One idea would be to use a field on FiberRoot (e.g. hasUncaughtError) rather than unschedule it. But that field would still need to be cleared on every update, which requires access to the root. So that doesn't solve the problem.
Possible solution
We could solve it by adding a root field to Fiber, so that we can always update it quickly. The question is whether the extra memory usage is worth the performance gain.
If we need to do extra work for the purpose of satisfying the scheduling problems during an error scenario, we've done the wrong tradeoff IMO. Error handling is a bonus.
roots are unscheduled if an uncaught error is thrown in that tree
Can you help me understand what happens here conceptually? If all work has been invalidated, should we clear the priority flag in the entire tree to get it to a consistent state?
@gaearon can probably explain it better. If there's an uncaught error, we need to avoid doing any pending work on that tree until there's another update.
If all work has been invalidated, should we clear the priority flag in the entire tree to get it to a consistent state?
I don't know. I don't understand the case quite. However, currently we seem to be breaking one invariant of the model: If there are priority levels pending, then the root is scheduled.
I need to understand why they should be allowed to diverge.
Activity
acdlite commentedon Nov 7, 2016
Another option: since it's only needed for class components, we could add a root field to the class instead.
sebmarkbage commentedon Nov 7, 2016
Intuitively it feels to me that the problem is with the scheduling of the root and not the fiber.
sebmarkbage commentedon Nov 7, 2016
If we need to do extra work for the purpose of satisfying the scheduling problems during an error scenario, we've done the wrong tradeoff IMO. Error handling is a bonus.
acdlite commentedon Nov 7, 2016
Do you mean this part?
sebmarkbage commentedon Nov 7, 2016
yea
acdlite commentedon Nov 7, 2016
I agree with your trade-off analysis, not sure how to solve it though.
sebmarkbage commentedon Nov 7, 2016
Can you help me understand what happens here conceptually? If all work has been invalidated, should we clear the priority flag in the entire tree to get it to a consistent state?
acdlite commentedon Nov 7, 2016
@gaearon can probably explain it better. If there's an uncaught error, we need to avoid doing any pending work on that tree until there's another update.
That seems like a viable option
acdlite commentedon Nov 7, 2016
What if there are pending updates on the queue and we clear the priority flag? Should they be dropped completely?
sebmarkbage commentedon Nov 7, 2016
I don't know. I don't understand the case quite. However, currently we seem to be breaking one invariant of the model: If there are priority levels pending, then the root is scheduled.
I need to understand why they should be allowed to diverge.
acdlite commentedon Nov 7, 2016
They diverge in master for now mostly as a hack. I think you're totally right, though. That's an important invariant.
I think clearing the entire tree would also fix the issue Dan found in #8212.Never mind, unrelated.Re: my previous question, dropping updates because of an uncaught error makes sense to me conceptually, I think.
acdlite commentedon Nov 8, 2016
Closing in favor of #8227