Skip to content

Commit

Permalink
Updates in a hidden effect should be Idle
Browse files Browse the repository at this point in the history
I had made them Never to avoid an extra render when a hidden effect
updates the hidden component -- if they are Idle, we have to render once
at Idle, which bails out on the hidden subtree, then again at Never to
actually process the update -- but the problem of needing an extra
render pass to bail out hidden updates already exists and we should fix
that properly instead of adding yet another special case.
  • Loading branch information
acdlite committed Sep 24, 2019
1 parent 4aea11d commit 7ee2a58
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
17 changes: 3 additions & 14 deletions packages/react-reconciler/src/ReactFiberWorkLoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,18 +325,6 @@ export function computeExpirationForFiber(
return renderExpirationTime;
}

if ((executionContext & CommitContext) !== NoContext) {
if (pendingPassiveEffectsExpirationTime === Never) {
// Updates triggered by an effect inside an offscreen tree should be
// Never, not Idle.
// TODO: This wouldn't be necessary if we deprioritized offscreen updates
// when traversing the return path (`markUpdateTimeFromFiberToRoot`),
// instead of waiting to bail out in the render phase.
// TODO: Should there be a way to opt out, like with `runWithPriority`?
return Never;
}
}

let expirationTime;
if (suspenseConfig !== null) {
// Compute an expiration time based on the Suspense timeout.
Expand Down Expand Up @@ -2231,7 +2219,9 @@ function flushPassiveEffectsImpl() {
return false;
}
const root = rootWithPendingPassiveEffects;
const expirationTime = pendingPassiveEffectsExpirationTime;
rootWithPendingPassiveEffects = null;
pendingPassiveEffectsExpirationTime = NoWork;

invariant(
(executionContext & (RenderContext | CommitContext)) === NoContext,
Expand Down Expand Up @@ -2271,11 +2261,10 @@ function flushPassiveEffectsImpl() {

if (enableSchedulerTracing) {
popInteractions(((prevInteractions: any): Set<Interaction>));
finishPendingInteractions(root, pendingPassiveEffectsExpirationTime);
finishPendingInteractions(root, expirationTime);
}

executionContext = prevExecutionContext;
pendingPassiveEffectsExpirationTime = NoWork;

flushSyncCallbackQueue();

Expand Down
17 changes: 11 additions & 6 deletions packages/react/src/__tests__/ReactDOMTracing-test.internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,12 @@ describe('ReactDOMTracing', () => {
expect(
onInteractionScheduledWorkCompleted,
).toHaveBeenLastNotifiedOfInteraction(interaction);
expect(onRender).toHaveBeenCalledTimes(3);
// TODO: This is 4 instead of 3 because this update was scheduled at
// idle priority, and idle updates are slightly higher priority than
// offscreen work. So it takes two render passes to finish it. Profiler
// calls `onRender` for the first render even though everything
// bails out.
expect(onRender).toHaveBeenCalledTimes(4);
expect(onRender).toHaveLastRenderedWithInteractions(
new Set([interaction]),
);
Expand Down Expand Up @@ -281,11 +286,11 @@ describe('ReactDOMTracing', () => {
expect(
onInteractionScheduledWorkCompleted,
).toHaveBeenLastNotifiedOfInteraction(interaction);
// TODO: This is 4 instead of 3 because this update was explicitly
// scheduled at idle priority, and idle updates are slightly higher
// priority than offscreen work. So it takes two render passes to finish
// it. Profiler calls `onRender` for the first render even though
// everything bails out.
// TODO: This is 4 instead of 3 because this update was scheduled at
// idle priority, and idle updates are slightly higher priority than
// offscreen work. So it takes two render passes to finish it. Profiler
// calls `onRender` for the first render even though everything
// bails out.
expect(onRender).toHaveBeenCalledTimes(4);
expect(onRender).toHaveLastRenderedWithInteractions(
new Set([interaction]),
Expand Down

0 comments on commit 7ee2a58

Please sign in to comment.