mirror of
https://github.com/facebook/react.git
synced 2026-11-18 20:15:56 +00:00
Fix NoWork bug
Thanks @acdlite. Add comment about future unit test coverage. This was actually hiding the fact that we are only able to reuse existing work if it was marked as completely finished which it won't be if we reuse its pending priority. However, we should be able to bail out even if there is work remaining in a subtree.
This commit is contained in:
1 parent
48b7b2c67c
commit
9fca812139
2 files changed
+27
-8
No files matched your search
@@ -169,7 +169,7 @@ module.exports = function<T, P, I, C>(config : HostConfig<T, P, I, C>) {
|
||||
// it until the next tick.
|
||||
workInProgress.child = current.child;
|
||||
reuseChildren(workInProgress, workInProgress.child);
|
||||
if (workInProgress.pendingWorkPriority <= priorityLevel) {
|
||||
if (workInProgress.pendingWorkPriority !== NoWork && workInProgress.pendingWorkPriority <= priorityLevel) {
|
||||
// TODO: This passes the current node and reads the priority level and
|
||||
// pending props from that. We want it to read our priority level and
|
||||
// pending props from the work in progress. Needs restructuring.
|
||||
@@ -184,15 +184,25 @@ module.exports = function<T, P, I, C>(config : HostConfig<T, P, I, C>) {
|
||||
}
|
||||
|
||||
if (!workInProgress.hasWorkInProgress &&
|
||||
workInProgress.pendingProps === workInProgress.memoizedProps &&
|
||||
workInProgress.pendingWorkPriority === NoWork) {
|
||||
workInProgress.pendingProps === workInProgress.memoizedProps) {
|
||||
// If we started this work before, and finished it, or if we're in a
|
||||
// ping-pong update scenario, this version could already be what we're
|
||||
// looking for. In that case, we should be able to just bail out.
|
||||
const priorityLevel = workInProgress.pendingWorkPriority;
|
||||
workInProgress.pendingProps = null;
|
||||
// TODO: We should be able to bail out if there is remaining work at a lower
|
||||
// priority too. However, I don't know if that is safe or even better since
|
||||
// the other tree could've potentially finished that work.
|
||||
workInProgress.pendingWorkPriority = NoWork;
|
||||
if (workInProgress.child) {
|
||||
// If we bail out but still has work with the current priority in this
|
||||
// subtree, we need to go find it right now. If we don't, we won't flush
|
||||
// it until the next tick.
|
||||
reuseChildren(workInProgress, workInProgress.child);
|
||||
if (workInProgress.pendingWorkPriority !== NoWork && workInProgress.pendingWorkPriority <= priorityLevel) {
|
||||
// TODO: This passes the current node and reads the priority level and
|
||||
// pending props from that. We want it to read our priority level and
|
||||
// pending props from the work in progress. Needs restructuring.
|
||||
return findNextUnitOfWorkAtPriority(workInProgress, priorityLevel);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ var {
|
||||
} = require('ReactPriorityLevel');
|
||||
|
||||
function cloneSiblings(current : Fiber, workInProgress : Fiber, returnFiber : Fiber) {
|
||||
workInProgress.return = returnFiber;
|
||||
while (current.sibling) {
|
||||
current = current.sibling;
|
||||
workInProgress = workInProgress.sibling = cloneFiber(
|
||||
@@ -49,6 +50,7 @@ exports.findNextUnitOfWorkAtPriority = function(currentRoot : Fiber, priorityLev
|
||||
workInProgress.pendingProps = current.pendingProps;
|
||||
return workInProgress;
|
||||
}
|
||||
|
||||
// If we have a child let's see if any of our children has work to do.
|
||||
// Only bother doing this at all if the current priority level matches
|
||||
// because it is the highest priority for the whole subtree.
|
||||
@@ -62,8 +64,15 @@ exports.findNextUnitOfWorkAtPriority = function(currentRoot : Fiber, priorityLev
|
||||
throw new Error('Should have wip now');
|
||||
}
|
||||
workInProgress.pendingWorkPriority = current.pendingWorkPriority;
|
||||
workInProgress.child = cloneFiber(currentChild, NoWork);
|
||||
workInProgress.child.return = workInProgress;
|
||||
// TODO: The below priority used to be set to NoWork which would've
|
||||
// dropped work. This is currently unobservable but will become
|
||||
// observable when the first sibling has lower priority work remaining
|
||||
// than the next sibling. At that point we should add tests that catches
|
||||
// this.
|
||||
workInProgress.child = cloneFiber(
|
||||
currentChild,
|
||||
currentChild.pendingWorkPriority
|
||||
);
|
||||
cloneSiblings(currentChild, workInProgress.child, workInProgress);
|
||||
current = current.child;
|
||||
continue;
|
||||
|
||||
Reference in new issue
Block a user