Skip to content

Commit c7ab906

Browse files
committed
Emit Infinite Promise as a Halted Row
No need for the special case.
1 parent 35b6d73 commit c7ab906

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

packages/react-client/src/ReactFlightClient.js

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

5150
import {
@@ -1193,10 +1192,6 @@ function parseModelString(
11931192
}
11941193
case '@': {
11951194
// Promise
1196-
if (value.length === 2) {
1197-
// Infinite promise that never resolves.
1198-
return new Promise(() => {});
1199-
}
12001195
const id = parseInt(value.slice(2), 16);
12011196
const chunk = getChunk(response, id);
12021197
return chunk;
@@ -2634,10 +2629,8 @@ function processFullStringRow(
26342629
}
26352630
// Fallthrough
26362631
case 35 /* "#" */: {
2637-
if (enableHalt) {
2638-
resolveBlocked(response, id);
2639-
return;
2640-
}
2632+
resolveBlocked(response, id);
2633+
return;
26412634
}
26422635
// Fallthrough
26432636
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: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,10 +1815,6 @@ function serializeLazyID(id: number): string {
18151815
return '$L' + id.toString(16);
18161816
}
18171817

1818-
function serializeInfinitePromise(): string {
1819-
return '$@';
1820-
}
1821-
18221818
function serializePromiseID(id: number): string {
18231819
return '$@' + id.toString(16);
18241820
}
@@ -3241,7 +3237,10 @@ function renderConsoleValue(
32413237
}
32423238
// If it hasn't already resolved (and been instrumented) we just encode an infinite
32433239
// promise that will never resolve.
3244-
return serializeInfinitePromise();
3240+
request.pendingChunks++;
3241+
const blockedId = request.nextChunkId++;
3242+
emitBlockedChunk(request, blockedId);
3243+
return serializePromiseID(blockedId);
32453244
}
32463245

32473246
if (existingReference !== undefined) {
@@ -3502,7 +3501,7 @@ function emitConsoleChunk(
35023501
value,
35033502
);
35043503
} catch (x) {
3505-
return 'unknown value';
3504+
return 'unknown value' + x.message;
35063505
}
35073506
}
35083507

0 commit comments

Comments
 (0)