GeezerVison is showing github.com — Emit Infinite Promise as a Halted Row · react/react@c7ab906
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/react-client/src/ReactFlightClient.js +2-9Lines changed: 2 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -45,7 +45,6 @@ import { | 45 | 45 | enableRefAsProp, | 46 | 46 | enableFlightReadableStream, | 47 | 47 | enableOwnerStacks, | 48 | | - enableHalt, | 49 | 48 | } from 'shared/ReactFeatureFlags'; | 50 | 49 |
| 51 | 50 | import { | @@ -1193,10 +1192,6 @@ function parseModelString( | 1193 | 1192 | } | 1194 | 1193 | case '@': { | 1195 | 1194 | // Promise | 1196 | | - if (value.length === 2) { | 1197 | | - // Infinite promise that never resolves. | 1198 | | - return new Promise(() => {}); | 1199 | | - } | 1200 | 1195 | const id = parseInt(value.slice(2), 16); | 1201 | 1196 | const chunk = getChunk(response, id); | 1202 | 1197 | return chunk; | @@ -2634,10 +2629,8 @@ function processFullStringRow( | 2634 | 2629 | } | 2635 | 2630 | // Fallthrough | 2636 | 2631 | case 35 /* "#" */: { | 2637 | | - if (enableHalt) { | 2638 | | - resolveBlocked(response, id); | 2639 | | - return; | 2640 | | - } | | 2632 | + resolveBlocked(response, id); | | 2633 | + return; | 2641 | 2634 | } | 2642 | 2635 | // Fallthrough | 2643 | 2636 | default: /* """ "{" "[" "t" "f" "n" "0" - "9" */ { | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-client/src/__tests__/ReactFlight-test.js +11-1Lines changed: 11 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -2952,8 +2952,14 @@ describe('ReactFlight', () => { | 2952 | 2952 | function foo() { | 2953 | 2953 | return 'hello'; | 2954 | 2954 | } | | 2955 | + | 2955 | 2956 | 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 | + }); | 2957 | 2963 | throw new Error('err'); | 2958 | 2964 | } | 2959 | 2965 |
| @@ -3018,6 +3024,10 @@ describe('ReactFlight', () => { | 3018 | 3024 | expect(loggedFn2).not.toBe(foo); | 3019 | 3025 | expect(loggedFn2.toString()).toBe(foo.toString()); | 3020 | 3026 |
| | 3027 | + const promise = mockConsoleLog.mock.calls[0][1].promise; | | 3028 | + expect(promise).toBeInstanceOf(Promise); | | 3029 | + expect(promise.status).toBe('blocked'); | | 3030 | + | 3021 | 3031 | expect(ownerStacks).toEqual(['\n in App (at **)']); | 3022 | 3032 | }); | 3023 | 3033 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/react-server/src/ReactFlightServer.js +5-6Lines changed: 5 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1815,10 +1815,6 @@ function serializeLazyID(id: number): string { | 1815 | 1815 | return '$L' + id.toString(16); | 1816 | 1816 | } | 1817 | 1817 |
| 1818 | | -function serializeInfinitePromise(): string { | 1819 | | - return '$@'; | 1820 | | -} | 1821 | | - | 1822 | 1818 | function serializePromiseID(id: number): string { | 1823 | 1819 | return '$@' + id.toString(16); | 1824 | 1820 | } | @@ -3241,7 +3237,10 @@ function renderConsoleValue( | 3241 | 3237 | } | 3242 | 3238 | // If it hasn't already resolved (and been instrumented) we just encode an infinite | 3243 | 3239 | // promise that will never resolve. | 3244 | | - return serializeInfinitePromise(); | | 3240 | + request.pendingChunks++; | | 3241 | + const blockedId = request.nextChunkId++; | | 3242 | + emitBlockedChunk(request, blockedId); | | 3243 | + return serializePromiseID(blockedId); | 3245 | 3244 | } | 3246 | 3245 |
| 3247 | 3246 | if (existingReference !== undefined) { | @@ -3502,7 +3501,7 @@ function emitConsoleChunk( | 3502 | 3501 | value, | 3503 | 3502 | ); | 3504 | 3503 | } catch (x) { | 3505 | | - return 'unknown value'; | | 3504 | + return 'unknown value' + x.message; | 3506 | 3505 | } | 3507 | 3506 | } | 3508 | 3507 |
| |
|