Skip to content

Commit 1520802

Browse files
authored
Remove enableFlightReadableStream (facebook#31766)
Base: facebook#31765 Landed everywhere
1 parent 4996a8f commit 1520802

17 files changed

+96
-163
lines changed

packages/react-client/src/ReactFlightClient.js

Lines changed: 37 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ import type {TemporaryReferenceSet} from './ReactFlightTemporaryReferences';
4444

4545
import {
4646
enablePostpone,
47-
enableFlightReadableStream,
4847
enableOwnerStacks,
4948
enableServerComponentLogs,
5049
enableProfilerTimer,
@@ -406,14 +405,12 @@ function wakeChunkIfInitialized<T>(
406405

407406
function triggerErrorOnChunk<T>(chunk: SomeChunk<T>, error: mixed): void {
408407
if (chunk.status !== PENDING && chunk.status !== BLOCKED) {
409-
if (enableFlightReadableStream) {
410-
// If we get more data to an already resolved ID, we assume that it's
411-
// a stream chunk since any other row shouldn't have more than one entry.
412-
const streamChunk: InitializedStreamChunk<any> = (chunk: any);
413-
const controller = streamChunk.reason;
414-
// $FlowFixMe[incompatible-call]: The error method should accept mixed.
415-
controller.error(error);
416-
}
408+
// If we get more data to an already resolved ID, we assume that it's
409+
// a stream chunk since any other row shouldn't have more than one entry.
410+
const streamChunk: InitializedStreamChunk<any> = (chunk: any);
411+
const controller = streamChunk.reason;
412+
// $FlowFixMe[incompatible-call]: The error method should accept mixed.
413+
controller.error(error);
417414
return;
418415
}
419416
const listeners = chunk.reason;
@@ -512,13 +509,11 @@ function resolveModelChunk<T>(
512509
value: UninitializedModel,
513510
): void {
514511
if (chunk.status !== PENDING) {
515-
if (enableFlightReadableStream) {
516-
// If we get more data to an already resolved ID, we assume that it's
517-
// a stream chunk since any other row shouldn't have more than one entry.
518-
const streamChunk: InitializedStreamChunk<any> = (chunk: any);
519-
const controller = streamChunk.reason;
520-
controller.enqueueModel(value);
521-
}
512+
// If we get more data to an already resolved ID, we assume that it's
513+
// a stream chunk since any other row shouldn't have more than one entry.
514+
const streamChunk: InitializedStreamChunk<any> = (chunk: any);
515+
const controller = streamChunk.reason;
516+
controller.enqueueModel(value);
522517
return;
523518
}
524519
const resolveListeners = chunk.value;
@@ -1718,16 +1713,14 @@ function resolveModel(
17181713

17191714
function resolveText(response: Response, id: number, text: string): void {
17201715
const chunks = response._chunks;
1721-
if (enableFlightReadableStream) {
1722-
const chunk = chunks.get(id);
1723-
if (chunk && chunk.status !== PENDING) {
1724-
// If we get more data to an already resolved ID, we assume that it's
1725-
// a stream chunk since any other row shouldn't have more than one entry.
1726-
const streamChunk: InitializedStreamChunk<any> = (chunk: any);
1727-
const controller = streamChunk.reason;
1728-
controller.enqueueValue(text);
1729-
return;
1730-
}
1716+
const chunk = chunks.get(id);
1717+
if (chunk && chunk.status !== PENDING) {
1718+
// If we get more data to an already resolved ID, we assume that it's
1719+
// a stream chunk since any other row shouldn't have more than one entry.
1720+
const streamChunk: InitializedStreamChunk<any> = (chunk: any);
1721+
const controller = streamChunk.reason;
1722+
controller.enqueueValue(text);
1723+
return;
17311724
}
17321725
chunks.set(id, createInitializedTextChunk(response, text));
17331726
}
@@ -1738,16 +1731,14 @@ function resolveBuffer(
17381731
buffer: $ArrayBufferView | ArrayBuffer,
17391732
): void {
17401733
const chunks = response._chunks;
1741-
if (enableFlightReadableStream) {
1742-
const chunk = chunks.get(id);
1743-
if (chunk && chunk.status !== PENDING) {
1744-
// If we get more data to an already resolved ID, we assume that it's
1745-
// a stream chunk since any other row shouldn't have more than one entry.
1746-
const streamChunk: InitializedStreamChunk<any> = (chunk: any);
1747-
const controller = streamChunk.reason;
1748-
controller.enqueueValue(buffer);
1749-
return;
1750-
}
1734+
const chunk = chunks.get(id);
1735+
if (chunk && chunk.status !== PENDING) {
1736+
// If we get more data to an already resolved ID, we assume that it's
1737+
// a stream chunk since any other row shouldn't have more than one entry.
1738+
const streamChunk: InitializedStreamChunk<any> = (chunk: any);
1739+
const controller = streamChunk.reason;
1740+
controller.enqueueValue(buffer);
1741+
return;
17511742
}
17521743
chunks.set(id, createInitializedBufferChunk(response, buffer));
17531744
}
@@ -2967,38 +2958,28 @@ function processFullStringRow(
29672958
);
29682959
}
29692960
case 82 /* "R" */: {
2970-
if (enableFlightReadableStream) {
2971-
startReadableStream(response, id, undefined);
2972-
return;
2973-
}
2961+
startReadableStream(response, id, undefined);
2962+
return;
29742963
}
29752964
// Fallthrough
29762965
case 114 /* "r" */: {
2977-
if (enableFlightReadableStream) {
2978-
startReadableStream(response, id, 'bytes');
2979-
return;
2980-
}
2966+
startReadableStream(response, id, 'bytes');
2967+
return;
29812968
}
29822969
// Fallthrough
29832970
case 88 /* "X" */: {
2984-
if (enableFlightReadableStream) {
2985-
startAsyncIterable(response, id, false);
2986-
return;
2987-
}
2971+
startAsyncIterable(response, id, false);
2972+
return;
29882973
}
29892974
// Fallthrough
29902975
case 120 /* "x" */: {
2991-
if (enableFlightReadableStream) {
2992-
startAsyncIterable(response, id, true);
2993-
return;
2994-
}
2976+
startAsyncIterable(response, id, true);
2977+
return;
29952978
}
29962979
// Fallthrough
29972980
case 67 /* "C" */: {
2998-
if (enableFlightReadableStream) {
2999-
stopStream(response, id, row);
3000-
return;
3001-
}
2981+
stopStream(response, id, row);
2982+
return;
30022983
}
30032984
// Fallthrough
30042985
case 80 /* "P" */: {

packages/react-client/src/ReactFlightReplyClient.js

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ import type {
1818
import type {LazyComponent} from 'react/src/ReactLazy';
1919
import type {TemporaryReferenceSet} from './ReactFlightTemporaryReferences';
2020

21-
import {
22-
enableRenderableContext,
23-
enableFlightReadableStream,
24-
} from 'shared/ReactFeatureFlags';
21+
import {enableRenderableContext} from 'shared/ReactFeatureFlags';
2522

2623
import {
2724
REACT_ELEMENT_TYPE,
@@ -663,23 +660,21 @@ export function processReply(
663660
return Array.from((iterator: any));
664661
}
665662

666-
if (enableFlightReadableStream) {
667-
// TODO: ReadableStream is not available in old Node. Remove the typeof check later.
668-
if (
669-
typeof ReadableStream === 'function' &&
670-
value instanceof ReadableStream
671-
) {
672-
return serializeReadableStream(value);
673-
}
674-
const getAsyncIterator: void | (() => $AsyncIterator<any, any, any>) =
675-
(value: any)[ASYNC_ITERATOR];
676-
if (typeof getAsyncIterator === 'function') {
677-
// We treat AsyncIterables as a Fragment and as such we might need to key them.
678-
return serializeAsyncIterable(
679-
(value: any),
680-
getAsyncIterator.call((value: any)),
681-
);
682-
}
663+
// TODO: ReadableStream is not available in old Node. Remove the typeof check later.
664+
if (
665+
typeof ReadableStream === 'function' &&
666+
value instanceof ReadableStream
667+
) {
668+
return serializeReadableStream(value);
669+
}
670+
const getAsyncIterator: void | (() => $AsyncIterator<any, any, any>) =
671+
(value: any)[ASYNC_ITERATOR];
672+
if (typeof getAsyncIterator === 'function') {
673+
// We treat AsyncIterables as a Fragment and as such we might need to key them.
674+
return serializeAsyncIterable(
675+
(value: any),
676+
getAsyncIterator.call((value: any)),
677+
);
683678
}
684679

685680
// Verify that this is a simple plain object.

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2623,7 +2623,7 @@ describe('ReactFlight', () => {
26232623
);
26242624
});
26252625

2626-
// @gate enableFlightReadableStream && enableAsyncIterableChildren
2626+
// @gate enableAsyncIterableChildren
26272627
it('shares state when moving keyed Server Components that render async iterables', async () => {
26282628
function StatefulClient({name, initial}) {
26292629
const [state] = React.useState(initial);
@@ -2814,7 +2814,7 @@ describe('ReactFlight', () => {
28142814
);
28152815
});
28162816

2817-
// @gate enableFlightReadableStream && enableAsyncIterableChildren
2817+
// @gate enableAsyncIterableChildren
28182818
it('preserves debug info for server-to-server pass through of async iterables', async () => {
28192819
let resolve;
28202820
const iteratorPromise = new Promise(r => (resolve = r));
@@ -2849,10 +2849,9 @@ describe('ReactFlight', () => {
28492849
},
28502850
);
28512851

2852-
if (gate(flag => flag.enableFlightReadableStream)) {
2853-
// Wait for the iterator to finish
2854-
await iteratorPromise;
2855-
}
2852+
// Wait for the iterator to finish
2853+
await iteratorPromise;
2854+
28562855
await 0; // One more tick for the return value / closing.
28572856

28582857
const transport = ReactNoopFlightServer.render(

packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMBrowser-test.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2079,7 +2079,6 @@ describe('ReactFlightDOMBrowser', () => {
20792079
});
20802080
}
20812081

2082-
// @gate enableFlightReadableStream
20832082
it('should supports streaming ReadableStream with objects', async () => {
20842083
const errors = [];
20852084
let controller1;
@@ -2161,7 +2160,6 @@ describe('ReactFlightDOMBrowser', () => {
21612160
expect(errors).toEqual(['rejected']);
21622161
});
21632162

2164-
// @gate enableFlightReadableStream
21652163
it('should cancels the underlying ReadableStream when we are cancelled', async () => {
21662164
let controller;
21672165
let cancelReason;
@@ -2194,7 +2192,6 @@ describe('ReactFlightDOMBrowser', () => {
21942192
expect(loggedReason).toBe(reason);
21952193
});
21962194

2197-
// @gate enableFlightReadableStream
21982195
it('should cancels the underlying ReadableStream when we abort', async () => {
21992196
const errors = [];
22002197
let controller;
@@ -2252,7 +2249,6 @@ describe('ReactFlightDOMBrowser', () => {
22522249
expect(errors).toEqual([reason]);
22532250
});
22542251

2255-
// @gate enableFlightReadableStream
22562252
it('should supports streaming AsyncIterables with objects', async () => {
22572253
let resolve;
22582254
const wait = new Promise(r => (resolve = r));
@@ -2369,7 +2365,6 @@ describe('ReactFlightDOMBrowser', () => {
23692365
);
23702366
});
23712367

2372-
// @gate enableFlightReadableStream
23732368
it('should cancels the underlying AsyncIterable when we are cancelled', async () => {
23742369
let resolve;
23752370
const wait = new Promise(r => (resolve = r));
@@ -2408,7 +2403,6 @@ describe('ReactFlightDOMBrowser', () => {
24082403
expect(loggedReason).toBe(reason);
24092404
});
24102405

2411-
// @gate enableFlightReadableStream
24122406
it('should cancels the underlying AsyncIterable when we abort', async () => {
24132407
const errors = [];
24142408
const abortController = new AbortController();

packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMEdge-test.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,6 @@ describe('ReactFlightDOMEdge', () => {
645645
expect(result.get('value')).toBe('hello');
646646
});
647647

648-
// @gate enableFlightReadableStream
649648
it('can pass an async import to a ReadableStream while enqueuing in order', async () => {
650649
let resolve;
651650
const promise = new Promise(r => (resolve = r));
@@ -690,7 +689,6 @@ describe('ReactFlightDOMEdge', () => {
690689
expect(await reader.read()).toEqual({value: undefined, done: true});
691690
});
692691

693-
// @gate enableFlightReadableStream
694692
it('can pass an async import a AsyncIterable while allowing peaking at future values', async () => {
695693
let resolve;
696694
const promise = new Promise(r => (resolve = r));
@@ -742,7 +740,6 @@ describe('ReactFlightDOMEdge', () => {
742740
expect(await iterator.next()).toEqual({value: undefined, done: true});
743741
});
744742

745-
// @gate enableFlightReadableStream
746743
it('should ideally dedupe objects inside async iterables but does not yet', async () => {
747744
const obj = {
748745
this: {is: 'a large objected'},
@@ -820,7 +817,6 @@ describe('ReactFlightDOMEdge', () => {
820817
);
821818
});
822819

823-
// @gate enableFlightReadableStream
824820
it('should supports ReadableStreams with typed arrays', async () => {
825821
const buffer = new Uint8Array([
826822
123, 4, 10, 5, 100, 255, 244, 45, 56, 67, 43, 124, 67, 89, 100, 20,
@@ -879,7 +875,6 @@ describe('ReactFlightDOMEdge', () => {
879875
expect(streamedBuffers).toEqual(buffers);
880876
});
881877

882-
// @gate enableFlightReadableStream
883878
it('should support BYOB binary ReadableStreams', async () => {
884879
const buffer = new Uint8Array([
885880
123, 4, 10, 5, 100, 255, 244, 45, 56, 67, 43, 124, 67, 89, 100, 20,

packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMNode-test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,6 @@ describe('ReactFlightDOMNode', () => {
292292
);
293293
});
294294

295-
// @gate enableFlightReadableStream
296295
it('should cancels the underlying ReadableStream when we are cancelled', async () => {
297296
let controller;
298297
let cancelReason;
@@ -336,7 +335,6 @@ describe('ReactFlightDOMNode', () => {
336335
);
337336
});
338337

339-
// @gate enableFlightReadableStream
340338
it('should cancels the underlying ReadableStream when we abort', async () => {
341339
const errors = [];
342340
let controller;

packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMReply-test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,6 @@ describe('ReactFlightDOMReply', () => {
449449
expect(response.obj).toBe(obj);
450450
});
451451

452-
// @gate enableFlightReadableStream
453452
it('should supports streaming ReadableStream with objects', async () => {
454453
let controller1;
455454
let controller2;
@@ -511,7 +510,6 @@ describe('ReactFlightDOMReply', () => {
511510
});
512511
});
513512

514-
// @gate enableFlightReadableStream
515513
it('should supports streaming AsyncIterables with objects', async () => {
516514
let resolve;
517515
const wait = new Promise(r => (resolve = r));

packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMReplyEdge-test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ describe('ReactFlightDOMReplyEdge', () => {
147147
expect(await resultBlob.arrayBuffer()).toEqual(await blob.arrayBuffer());
148148
});
149149

150-
// @gate enableFlightReadableStream
151150
it('should supports ReadableStreams with typed arrays', async () => {
152151
const buffer = new Uint8Array([
153152
123, 4, 10, 5, 100, 255, 244, 45, 56, 67, 43, 124, 67, 89, 100, 20,
@@ -194,7 +193,6 @@ describe('ReactFlightDOMReplyEdge', () => {
194193
expect(streamedBuffers).toEqual(buffers);
195194
});
196195

197-
// @gate enableFlightReadableStream
198196
it('should support BYOB binary ReadableStreams', async () => {
199197
const buffer = new Uint8Array([
200198
123, 4, 10, 5, 100, 255, 244, 45, 56, 67, 43, 124, 67, 89, 100, 20,

0 commit comments

Comments
 (0)