@samitouri / QOS-React / commits / a98aba4d73

Always override priority level when visiting children

It is not possible for a child to have a higher priority level than we're reconciling at, unless we intentionally want to down-prioritize it.

Sebastian Markbage committed Oct 6, 2016 at 18:50 UTC a98aba4d73a6db2ddb2a44156697adbae429f218
2 files changed +22 -4
src/renderers/shared/fiber/ReactChildFiber.js
+4 -4
@@ -148,10 +148,10 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
148 clone.sibling = null;
149 return clone;
150 } else {
151 - if (fiber.pendingWorkPriority === NoWork ||
152 - fiber.pendingWorkPriority > priority) {
153 - fiber.pendingWorkPriority = priority;
154 - }
151 + // We override the pending priority even if it is higher, because if
152 + // we're reconciling at a lower priority that means that this was
153 + // down-prioritized.
154 + fiber.pendingWorkPriority = priority;
155 fiber.effectTag = NoWork;
156 fiber.index = 0;
157 fiber.sibling = null;
src/renderers/shared/fiber/__tests__/ReactIncremental-test.js
+18
@@ -417,6 +417,24 @@ describe('ReactIncremental', () => {
417 // after them which is not correct.
418 ReactNoop.flush();
419 expect(ops).toEqual(['Bar', 'Middle', 'Bar']);
420 +
421 + ops = [];
422 +
423 + // Let us try this again without fully finishing the first time. This will
424 + // create a hanging subtree that is reconciling at the normal priority.
425 + ReactNoop.render(<Foo text="foo" />);
426 + ReactNoop.flushDeferredPri(40);
427 +
428 + expect(ops).toEqual(['Foo', 'Bar']);
429 +
430 + ops = [];
431 +
432 + // This update will create a tree that aborts that work and down-prioritizes
433 + // it. If the priority levels aren't down-prioritized correctly this may
434 + // abort rendering of the down-prioritized content.
435 + ReactNoop.render(<Foo text="bar" />);
436 + ReactNoop.flush();
437 + expect(ops).toEqual(['Foo', 'Bar', 'Bar']);
438 });
439
440 it('can reuse work done after being preempted', () => {