Skip to content

Commit

Permalink
Don't warn if an unmounted component is pinged (facebook#14158)
Browse files Browse the repository at this point in the history
* Add failing test for ping on unmounted component

We had a test for this, but not outside of concurrent mode :)

* Don't warn if an unmounted component is pinged
  • Loading branch information
acdlite authored and jetoneza committed Jan 23, 2019
1 parent 64cf3e3 commit 0e48936
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 43 deletions.
83 changes: 40 additions & 43 deletions packages/react-reconciler/src/ReactFiberScheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -1747,6 +1747,46 @@ function scheduleWorkToRoot(fiber: Fiber, expirationTime): FiberRoot | null {
}
}

if (enableSchedulerTracing) {
if (root !== null) {
const interactions = __interactionsRef.current;
if (interactions.size > 0) {
const pendingInteractionMap = root.pendingInteractionMap;
const pendingInteractions = pendingInteractionMap.get(expirationTime);
if (pendingInteractions != null) {
interactions.forEach(interaction => {
if (!pendingInteractions.has(interaction)) {
// Update the pending async work count for previously unscheduled interaction.
interaction.__count++;
}

pendingInteractions.add(interaction);
});
} else {
pendingInteractionMap.set(expirationTime, new Set(interactions));

// Update the pending async work count for the current interactions.
interactions.forEach(interaction => {
interaction.__count++;
});
}

const subscriber = __subscriberRef.current;
if (subscriber !== null) {
const threadID = computeThreadID(
expirationTime,
root.interactionThreadID,
);
subscriber.onWorkScheduled(interactions, threadID);
}
}
}
}
return root;
}

function scheduleWork(fiber: Fiber, expirationTime: ExpirationTime) {
const root = scheduleWorkToRoot(fiber, expirationTime);
if (root === null) {
if (__DEV__) {
switch (fiber.tag) {
Expand All @@ -1761,49 +1801,6 @@ function scheduleWorkToRoot(fiber: Fiber, expirationTime): FiberRoot | null {
break;
}
}
return null;
}

if (enableSchedulerTracing) {
const interactions = __interactionsRef.current;
if (interactions.size > 0) {
const pendingInteractionMap = root.pendingInteractionMap;
const pendingInteractions = pendingInteractionMap.get(expirationTime);
if (pendingInteractions != null) {
interactions.forEach(interaction => {
if (!pendingInteractions.has(interaction)) {
// Update the pending async work count for previously unscheduled interaction.
interaction.__count++;
}

pendingInteractions.add(interaction);
});
} else {
pendingInteractionMap.set(expirationTime, new Set(interactions));

// Update the pending async work count for the current interactions.
interactions.forEach(interaction => {
interaction.__count++;
});
}

const subscriber = __subscriberRef.current;
if (subscriber !== null) {
const threadID = computeThreadID(
expirationTime,
root.interactionThreadID,
);
subscriber.onWorkScheduled(interactions, threadID);
}
}
}

return root;
}

function scheduleWork(fiber: Fiber, expirationTime: ExpirationTime) {
const root = scheduleWorkToRoot(fiber, expirationTime);
if (root === null) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -838,5 +838,53 @@ describe('ReactSuspense', () => {
]);
expect(root).toMatchRenderedOutput('Tab: 2 + sibling');
});

it('does not warn if an mounted component is pinged', () => {
const {useState} = React;

const root = ReactTestRenderer.create(null);

let setStep;
function UpdatingText({text, ms}) {
const [step, _setStep] = useState(0);
setStep = _setStep;
const fullText = `${text}:${step}`;
try {
TextResource.read([fullText, ms]);
ReactTestRenderer.unstable_yield(fullText);
return fullText;
} catch (promise) {
if (typeof promise.then === 'function') {
ReactTestRenderer.unstable_yield(`Suspend! [${fullText}]`);
} else {
ReactTestRenderer.unstable_yield(`Error! [${fullText}]`);
}
throw promise;
}
}

root.update(
<Suspense fallback={<Text text="Loading..." />}>
<UpdatingText text="A" ms={1000} />
</Suspense>,
);

expect(ReactTestRenderer).toHaveYielded(['Suspend! [A:0]', 'Loading...']);
jest.advanceTimersByTime(1000);
expect(ReactTestRenderer).toHaveYielded([
'Promise resolved [A:0]',
'A:0',
]);
expect(root).toMatchRenderedOutput('A:0');

setStep(1);
expect(ReactTestRenderer).toHaveYielded(['Suspend! [A:1]', 'Loading...']);
expect(root).toMatchRenderedOutput('Loading...');

root.update(null);
expect(root).toFlushWithoutYielding();

jest.advanceTimersByTime(1000);
});
});
});

0 comments on commit 0e48936

Please sign in to comment.