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

[Flight] Start initial work immediately #30961

Merged
merged 1 commit into from
Sep 14, 2024
Merged
Changes from all commits
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
49 changes: 24 additions & 25 deletions packages/react-server/src/ReactFlightServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,17 @@ type Task = {

interface Reference {}

const OPENING = 10;
const OPEN = 11;
const ABORTING = 12;
const CLOSING = 13;
const CLOSED = 14;

const RENDER = 20;
const PRERENDER = 21;

export type Request = {
status: 10 | 11 | 12 | 13,
status: 10 | 11 | 12 | 13 | 14,
type: 20 | 21,
flushScheduled: boolean,
fatalError: mixed,
Expand Down Expand Up @@ -426,14 +435,6 @@ function defaultPostponeHandler(reason: string) {
// Noop
}

const OPEN = 10;
const ABORTING = 11;
const CLOSING = 12;
const CLOSED = 13;

const RENDER = 20;
const PRERENDER = 21;

function RequestInstance(
this: $FlowFixMe,
type: 20 | 21,
Expand Down Expand Up @@ -472,7 +473,7 @@ function RequestInstance(
}
const hints = createHints();
this.type = type;
this.status = OPEN;
this.status = OPENING;
this.flushScheduled = false;
this.fatalError = null;
this.destination = null;
Expand Down Expand Up @@ -1794,7 +1795,7 @@ function pingTask(request: Request, task: Task): void {
pingedTasks.push(task);
if (pingedTasks.length === 1) {
request.flushScheduled = request.destination !== null;
if (request.type === PRERENDER) {
if (request.type === PRERENDER || request.status === OPENING) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can unify the prerender path here and avoid the double conditional?

scheduleMicrotask(() => performWork(request));
} else {
scheduleWork(() => performWork(request));
Expand Down Expand Up @@ -4062,21 +4063,18 @@ function flushCompletedChunks(

export function startWork(request: Request): void {
request.flushScheduled = request.destination !== null;
if (request.type === PRERENDER) {
if (supportsRequestStorage) {
scheduleMicrotask(() => {
requestStorage.run(request, performWork, request);
});
} else {
scheduleMicrotask(() => performWork(request));
}
if (supportsRequestStorage) {
scheduleMicrotask(() => {
requestStorage.run(request, performWork, request);
});
} else {
if (supportsRequestStorage) {
scheduleWork(() => requestStorage.run(request, performWork, request));
} else {
scheduleWork(() => performWork(request));
}
scheduleMicrotask(() => performWork(request));
}
scheduleWork(() => {
if (request.status === OPENING) {
request.status = OPEN;
}
});
}

function enqueueFlush(request: Request): void {
Expand Down Expand Up @@ -4129,7 +4127,8 @@ export function stopFlowing(request: Request): void {

export function abort(request: Request, reason: mixed): void {
try {
if (request.status === OPEN) {
// We define any status below OPEN as OPEN equivalent
if (request.status <= OPEN) {
request.status = ABORTING;
}
const abortableTasks = request.abortableTasks;
Expand Down
Loading