Skip to content

Commit 52c9c43

Browse files
authored
[Flight] Emit Infinite Promise as a Halted Row (facebook#30746)
Stacked on facebook#30731. When logging a Promise we emit it as an infinite promise instead of blocking the replay on it. This models that as a halted row instead. No need for this special case. I unflag the receiving side since now it's used to replace a feature that's already unflagged so it's used.
1 parent 591adfa commit 52c9c43

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

packages/react-client/src/ReactFlightClient.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ import {
4646
enableRefAsProp,
4747
enableFlightReadableStream,
4848
enableOwnerStacks,
49-
enableHalt,
5049
} from 'shared/ReactFeatureFlags';
5150

5251
import {
@@ -1194,10 +1193,6 @@ function parseModelString(
11941193
}
11951194
case '@': {
11961195
// Promise
1197-
if (value.length === 2) {
1198-
// Infinite promise that never resolves.
1199-
return new Promise(() => {});
1200-
}
12011196
const id = parseInt(value.slice(2), 16);
12021197
const chunk = getChunk(response, id);
12031198
return chunk;
@@ -2638,10 +2633,8 @@ function processFullStringRow(
26382633
}
26392634
// Fallthrough
26402635
case 35 /* "#" */: {
2641-
if (enableHalt) {
2642-
resolveBlocked(response, id);
2643-
return;
2644-
}
2636+
resolveBlocked(response, id);
2637+
return;
26452638
}
26462639
// Fallthrough
26472640
default: /* """ "{" "[" "t" "f" "n" "0" - "9" */ {

packages/react-client/src/__tests__/ReactFlight-test.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2952,8 +2952,14 @@ describe('ReactFlight', () => {
29522952
function foo() {
29532953
return 'hello';
29542954
}
2955+
29552956
function ServerComponent() {
2956-
console.log('hi', {prop: 123, fn: foo, map: new Map([['foo', foo]])});
2957+
console.log('hi', {
2958+
prop: 123,
2959+
fn: foo,
2960+
map: new Map([['foo', foo]]),
2961+
promise: new Promise(() => {}),
2962+
});
29572963
throw new Error('err');
29582964
}
29592965

@@ -3018,6 +3024,10 @@ describe('ReactFlight', () => {
30183024
expect(loggedFn2).not.toBe(foo);
30193025
expect(loggedFn2.toString()).toBe(foo.toString());
30203026

3027+
const promise = mockConsoleLog.mock.calls[0][1].promise;
3028+
expect(promise).toBeInstanceOf(Promise);
3029+
expect(promise.status).toBe('blocked');
3030+
30213031
expect(ownerStacks).toEqual(['\n in App (at **)']);
30223032
});
30233033

packages/react-server/src/ReactFlightServer.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,10 +1817,6 @@ function serializeLazyID(id: number): string {
18171817
return '$L' + id.toString(16);
18181818
}
18191819

1820-
function serializeInfinitePromise(): string {
1821-
return '$@';
1822-
}
1823-
18241820
function serializePromiseID(id: number): string {
18251821
return '$@' + id.toString(16);
18261822
}
@@ -3273,7 +3269,10 @@ function renderConsoleValue(
32733269
}
32743270
// If it hasn't already resolved (and been instrumented) we just encode an infinite
32753271
// promise that will never resolve.
3276-
return serializeInfinitePromise();
3272+
request.pendingChunks++;
3273+
const blockedId = request.nextChunkId++;
3274+
emitBlockedChunk(request, blockedId);
3275+
return serializePromiseID(blockedId);
32773276
}
32783277

32793278
if (existingReference !== undefined) {

0 commit comments

Comments
 (0)