Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare internal code sync #23144

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Revert "Revert "Revert yieldy behavior for non-use Suspense""
This reverts commit b73a5c6.

This reverts commit 5f9d29a.

To derisk the rollout of `use`, and simplify the implementation, this
reverts the yield-to-microtasks behavior for promises that are thrown
directly (as opposed to being unwrapped by `use`).

We may add this back later. However, the plan is to deprecate throwing a
promise directly and migrate all existing Suspense code to `use`, so the
extra code probably isn't worth it.
  • Loading branch information
acdlite committed Dec 6, 2022
commit 97a2263fc26327ce8bdabec4374888dc04382e0b
1 change: 1 addition & 0 deletions packages/react-server/src/ReactFizzHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ function use<T>(usable: Usable<T>): T {
const index = thenableIndexCounter;
thenableIndexCounter += 1;

// TODO: Unify this switch statement with the one in trackUsedThenable.
switch (thenable.status) {
case 'fulfilled': {
const fulfilledValue: T = thenable.value;
Expand Down
7 changes: 0 additions & 7 deletions packages/react-server/src/ReactFizzServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import type {
ReactContext,
ReactProviderType,
OffscreenMode,
Wakeable,
} from 'shared/ReactTypes';
import type {LazyComponent as LazyComponentType} from 'react/src/ReactLazy';
import type {
Expand Down Expand Up @@ -139,7 +138,6 @@ import {
import assign from 'shared/assign';
import getComponentNameFromType from 'shared/getComponentNameFromType';
import isArray from 'shared/isArray';
import {trackSuspendedWakeable} from './ReactFizzThenable';

const ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
const ReactCurrentCache = ReactSharedInternals.ReactCurrentCache;
Expand Down Expand Up @@ -1554,8 +1552,6 @@ function spawnNewSuspendedTask(
task.treeContext,
);

trackSuspendedWakeable(x);

if (__DEV__) {
if (task.componentStack !== null) {
// We pop one task off the stack because the node that suspended will be tried again,
Expand Down Expand Up @@ -1879,9 +1875,6 @@ function retryTask(request: Request, task: Task): void {
// Something suspended again, let's pick it back up later.
const ping = task.ping;
x.then(ping, ping);

const wakeable: Wakeable = x;
trackSuspendedWakeable(wakeable);
task.thenableState = getThenableStateAfterSuspending();
} else {
task.abortSet.delete(task);
Expand Down
23 changes: 6 additions & 17 deletions packages/react-server/src/ReactFizzThenable.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// instead of "Wakeable". Or some other more appropriate name.

import type {
Wakeable,
Thenable,
PendingThenable,
FulfilledThenable,
Expand All @@ -30,12 +29,12 @@ export function createThenableState(): ThenableState {
return [];
}

export function trackSuspendedWakeable(wakeable: Wakeable) {
// If this wakeable isn't already a thenable, turn it into one now. Then,
// when we resume the work loop, we can check if its status is
// still pending.
// TODO: Get rid of the Wakeable type? It's superseded by UntrackedThenable.
const thenable: Thenable<mixed> = (wakeable: any);
export function trackUsedThenable<T>(
thenableState: ThenableState,
thenable: Thenable<T>,
index: number,
) {
thenableState[index] = thenable;

// We use an expando to track the status and result of a thenable so that we
// can synchronously unwrap the value. Think of this as an extension of the
Expand Down Expand Up @@ -82,16 +81,6 @@ export function trackSuspendedWakeable(wakeable: Wakeable) {
}
}

export function trackUsedThenable<T>(
thenableState: ThenableState,
thenable: Thenable<T>,
index: number,
) {
// This is only a separate function from trackSuspendedWakeable for symmetry
// with Fiber.
thenableState[index] = thenable;
}

export function getPreviouslyUsedThenableAtIndex<T>(
thenableState: ThenableState | null,
index: number,
Expand Down