Skip to content

Commit 99c106c

Browse files
authored
Revert sync abort replay restoration pending a complete fix (#37852)
Revert #37710 and #37850 while we revisit how synchronous prerender aborts preserve replay state. Restoring the aborted task root as a replay point can overlap postpones from child tasks. #37850 suppresses one form of the overlap, but an indexed parent slot can still coexist with a descendant replay node and fail during resumption. This removes the incomplete change so we can address the replay invariants together. This deliberately restores the behavior reported in #37709: if a prerender abort interrupts a task after it has rendered part of its shell, the later resume can omit that markup. That regression needs a follow-up fix. This supersedes #37851. Tests: `yarn test ReactDOMFizzStaticBrowser --runInBand` and `yarn test ReactDOMFizzStaticBrowser --prod --runInBand` (34 passed in each mode).
1 parent e25b4a4 commit 99c106c

2 files changed

Lines changed: 4 additions & 131 deletions

File tree

‎packages/react-dom/src/__tests__/ReactDOMFizzStaticBrowser-test.js‎

Lines changed: 0 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -864,130 +864,6 @@ describe('ReactDOMFizzStaticBrowser', () => {
864864
expect(errors).toEqual(['resume abort']);
865865
});
866866

867-
it('resumes a task that was aborted while rendering from where it started', async () => {
868-
let resolve;
869-
const promise = new Promise(r => (resolve = r));
870-
let prerendering = true;
871-
const controller = new AbortController();
872-
873-
function Abort() {
874-
if (prerendering) {
875-
controller.abort();
876-
}
877-
return 'World';
878-
}
879-
880-
function Content() {
881-
React.use(promise);
882-
return (
883-
<section>
884-
<span>Hello</span>
885-
<Abort />
886-
</section>
887-
);
888-
}
889-
890-
function App() {
891-
return (
892-
<div>
893-
<Suspense fallback="Loading...">
894-
<Content />
895-
</Suspense>
896-
</div>
897-
);
898-
}
899-
900-
const errors = [];
901-
let pendingResult;
902-
await serverAct(() => {
903-
pendingResult = ReactDOMFizzStatic.prerender(<App />, {
904-
signal: controller.signal,
905-
onError(error) {
906-
errors.push(error.message);
907-
},
908-
});
909-
});
910-
await serverAct(() => resolve());
911-
const prerendered = await pendingResult;
912-
913-
expect(errors).toEqual(['This operation was aborted']);
914-
await readIntoContainer(prerendered.prelude);
915-
expect(getVisibleChildren(container)).toEqual(<div>Loading...</div>);
916-
917-
prerendering = false;
918-
const resumed = await serverAct(() =>
919-
ReactDOMFizzServer.resume(
920-
<App />,
921-
JSON.parse(JSON.stringify(prerendered.postponed)),
922-
),
923-
);
924-
925-
await readIntoContainer(resumed);
926-
expect(getVisibleChildren(container)).toEqual(
927-
<div>
928-
<section>
929-
<span>Hello</span>World
930-
</section>
931-
</div>,
932-
);
933-
});
934-
935-
it('resumes after one child suspends and another aborts the prerender', async () => {
936-
const never = new Promise(() => {});
937-
const controller = new AbortController();
938-
let prerendering = true;
939-
940-
function Pending() {
941-
if (prerendering) {
942-
React.use(never);
943-
}
944-
return 'First';
945-
}
946-
947-
function Abort() {
948-
if (prerendering) {
949-
controller.abort('prerender abort');
950-
}
951-
return 'Second';
952-
}
953-
954-
function App() {
955-
return (
956-
<div>
957-
<Suspense fallback="Loading...">
958-
<Pending />
959-
<Abort />
960-
</Suspense>
961-
</div>
962-
);
963-
}
964-
965-
let pendingResult;
966-
await serverAct(() => {
967-
pendingResult = ReactDOMFizzStatic.prerender(<App />, {
968-
signal: controller.signal,
969-
onError() {},
970-
});
971-
});
972-
const prerendered = await pendingResult;
973-
974-
expect(prerendered.postponed).not.toBe(null);
975-
await readIntoContainer(prerendered.prelude);
976-
expect(getVisibleChildren(container)).toEqual(<div>Loading...</div>);
977-
978-
prerendering = false;
979-
const resumed = await serverAct(() =>
980-
ReactDOMFizzServer.resume(
981-
<App />,
982-
JSON.parse(JSON.stringify(prerendered.postponed)),
983-
),
984-
);
985-
await readIntoContainer(resumed);
986-
expect(getVisibleChildren(container)).toEqual(
987-
<div>{['First', 'Second']}</div>,
988-
);
989-
});
990-
991867
it('can prerender a preamble', async () => {
992868
const errors = [];
993869

‎packages/react-server/src/ReactFizzServer.js‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4196,9 +4196,10 @@ function trackPostpone(
41964196
if (slots === null) {
41974197
slots = resumableNode[3] = {} as {[index: number]: number};
41984198
} else if (typeof slots === 'number') {
4199-
// The parent task was aborted after it spawned this child task.
4200-
// Resuming the parent also renders this child, so its slot is redundant.
4201-
return;
4199+
throw new Error(
4200+
'It should not be possible to postpone both at the root of an element ' +
4201+
'as well as a slot below. This is a bug in React.',
4202+
);
42024203
}
42034204
}
42044205
}
@@ -5367,8 +5368,6 @@ function retryRenderTask(
53675368
const chunkLength = segment.chunks.length;
53685369
// Used to detect forward progress if we hit a stack overflow below.
53695370
const startNode = task.node;
5370-
const startKeyPath = task.keyPath;
5371-
const startChildIndex = task.childIndex;
53725371
try {
53735372
// We call the destructive form that mutates this task. That way if something
53745373
// suspends again, we can reuse the same task instead of spawning a new one.
@@ -5415,8 +5414,6 @@ function retryRenderTask(
54155414
// Restore the parent instead of clearing this field because finishing
54165415
// can reenter Fizz and abort an outer render that is still on the stack.
54175416
request.currentTask = prevTask;
5418-
task.keyPath = startKeyPath;
5419-
task.childIndex = startChildIndex;
54205417
abortUnwoundTask(task, request);
54215418
return;
54225419
}

0 commit comments

Comments
 (0)