Skip to content

Commit

Permalink
Attaching a ping listener might interrupt the render so instead use a…
Browse files Browse the repository at this point in the history
… dummy
  • Loading branch information
sebmarkbage committed Feb 1, 2023
1 parent 0a54f74 commit c618cfa
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions packages/react-reconciler/src/ReactFiberThenable.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ import type {
import ReactSharedInternals from 'shared/ReactSharedInternals';
const {ReactCurrentActQueue} = ReactSharedInternals;

import {
getWorkInProgressRoot,
getWorkInProgressRootRenderLanes,
attachPingListener,
} from './ReactFiberWorkLoop';

export opaque type ThenableState = Array<Thenable<any>>;

// An error that is thrown (e.g. by `use`) to trigger Suspense. If we
Expand Down Expand Up @@ -94,6 +88,9 @@ export function trackUsedThenable<T>(
// Only instrument the thenable if the status if not defined. If
// it's defined, but an unknown value, assume it's been instrumented by
// some custom userspace implementation. We treat it as "pending".
// Attach a dummy listener, to ensure that any lazy initialization can
// haappen.
thenable.then(noop, noop);
} else {
const pendingThenable: PendingThenable<T> = (thenable: any);
pendingThenable.status = 'pending';
Expand All @@ -115,12 +112,6 @@ export function trackUsedThenable<T>(
);
}

// Attach ping listeners eagerly in case this synchronously resolves.
const root = getWorkInProgressRoot();
if (root) {
attachPingListener(root, thenable, getWorkInProgressRootRenderLanes());
}

// Check one more time in case the thenable resolved synchronously.
switch (thenable.status) {
case 'fulfilled': {
Expand Down

0 comments on commit c618cfa

Please sign in to comment.