Skip to content

Commit

Permalink
Ensure effects are reused when bailing out on the child
Browse files Browse the repository at this point in the history
  • Loading branch information
acdlite committed Jan 11, 2017
1 parent 9a553a3 commit 0c240f4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
3 changes: 0 additions & 3 deletions scripts/fiber/tests-failing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ src/renderers/shared/__tests__/ReactPerf-test.js
* should not count time in a portal towards lifecycle method
* should work when measurement starts during reconciliation

src/renderers/shared/fiber/__tests__/ReactIncrementalSideEffects-test.js
* can defer side-effects and reuse them later - complex

src/renderers/shared/hooks/__tests__/ReactComponentTreeHook-test.js
* can be retrieved by ID

Expand Down
1 change: 1 addition & 0 deletions scripts/fiber/tests-passing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1231,6 +1231,7 @@ src/renderers/shared/fiber/__tests__/ReactIncrementalSideEffects-test.js
* can update a completed tree before it has a chance to commit
* updates a child even though the old props is empty
* can defer side-effects and resume them later on
* can defer side-effects and reuse them later - complex
* deprioritizes setStates that happens within a deprioritized tree
* calls callback after update is flushed
* calls setState callback even if component bails out
Expand Down
25 changes: 25 additions & 0 deletions src/renderers/shared/fiber/ReactFiberScheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,23 @@ module.exports = function<T, P, I, TI, C, CX, CI>(config : HostConfig<T, P, I, T
}
}

function reuseChildrenEffects(returnFiber : Fiber, firstChild : Fiber) {
let child = firstChild;
do {
// Ensure that the first and last effect of the parent corresponds
// to the children's first and last effect.
if (!returnFiber.firstEffect) {
returnFiber.firstEffect = child.firstEffect;
}
if (child.lastEffect) {
if (returnFiber.lastEffect) {
returnFiber.lastEffect.nextEffect = child.firstEffect;
}
returnFiber.lastEffect = child.lastEffect;
}
} while (child = child.sibling);
}

function performUnitOfWork(workInProgress : Fiber) : ?Fiber {

// The current, flushed, state of this fiber is the alternate.
Expand All @@ -513,6 +530,14 @@ module.exports = function<T, P, I, TI, C, CX, CI>(config : HostConfig<T, P, I, T
}

if (!next) {
const child = workInProgress.child;

if (child) {
// If we bailed out, ensure that we don't drop the effects from
// the subtree.
reuseChildrenEffects(workInProgress, child);
}

if (__DEV__ && ReactFiberInstrumentation.debugTool) {
ReactFiberInstrumentation.debugTool.onWillCompleteWork(workInProgress);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -831,9 +831,9 @@ describe('ReactIncrementalSideEffects', () => {
// Updated.
span(1),
div(
span(1),
// Still not updated.
span(0),
span(0),
span(0)
)
),
Expand Down

0 comments on commit 0c240f4

Please sign in to comment.