Skip to content

Commit 08dfd0b

Browse files
authored
Remove enableBinaryflight (facebook#31759)
Based off facebook#31757 This has landed everywhere.
1 parent ef63718 commit 08dfd0b

17 files changed

+352
-399
lines changed

packages/react-client/src/ReactFlightClient.js

+73-81
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ import type {Postpone} from 'react/src/ReactPostpone';
4343
import type {TemporaryReferenceSet} from './ReactFlightTemporaryReferences';
4444

4545
import {
46-
enableBinaryFlight,
4746
enablePostpone,
4847
enableFlightReadableStream,
4948
enableOwnerStacks,
@@ -1461,11 +1460,8 @@ function parseModelString(
14611460
}
14621461
case 'B': {
14631462
// Blob
1464-
if (enableBinaryFlight) {
1465-
const ref = value.slice(2);
1466-
return getOutlinedModel(response, ref, parentObject, key, createBlob);
1467-
}
1468-
return undefined;
1463+
const ref = value.slice(2);
1464+
return getOutlinedModel(response, ref, parentObject, key, createBlob);
14691465
}
14701466
case 'K': {
14711467
// FormData
@@ -2821,53 +2817,51 @@ function processFullBinaryRow(
28212817
buffer: Array<Uint8Array>,
28222818
chunk: Uint8Array,
28232819
): void {
2824-
if (enableBinaryFlight) {
2825-
switch (tag) {
2826-
case 65 /* "A" */:
2827-
// We must always clone to extract it into a separate buffer instead of just a view.
2828-
resolveBuffer(response, id, mergeBuffer(buffer, chunk).buffer);
2829-
return;
2830-
case 79 /* "O" */:
2831-
resolveTypedArray(response, id, buffer, chunk, Int8Array, 1);
2832-
return;
2833-
case 111 /* "o" */:
2834-
resolveBuffer(
2835-
response,
2836-
id,
2837-
buffer.length === 0 ? chunk : mergeBuffer(buffer, chunk),
2838-
);
2839-
return;
2840-
case 85 /* "U" */:
2841-
resolveTypedArray(response, id, buffer, chunk, Uint8ClampedArray, 1);
2842-
return;
2843-
case 83 /* "S" */:
2844-
resolveTypedArray(response, id, buffer, chunk, Int16Array, 2);
2845-
return;
2846-
case 115 /* "s" */:
2847-
resolveTypedArray(response, id, buffer, chunk, Uint16Array, 2);
2848-
return;
2849-
case 76 /* "L" */:
2850-
resolveTypedArray(response, id, buffer, chunk, Int32Array, 4);
2851-
return;
2852-
case 108 /* "l" */:
2853-
resolveTypedArray(response, id, buffer, chunk, Uint32Array, 4);
2854-
return;
2855-
case 71 /* "G" */:
2856-
resolveTypedArray(response, id, buffer, chunk, Float32Array, 4);
2857-
return;
2858-
case 103 /* "g" */:
2859-
resolveTypedArray(response, id, buffer, chunk, Float64Array, 8);
2860-
return;
2861-
case 77 /* "M" */:
2862-
resolveTypedArray(response, id, buffer, chunk, BigInt64Array, 8);
2863-
return;
2864-
case 109 /* "m" */:
2865-
resolveTypedArray(response, id, buffer, chunk, BigUint64Array, 8);
2866-
return;
2867-
case 86 /* "V" */:
2868-
resolveTypedArray(response, id, buffer, chunk, DataView, 1);
2869-
return;
2870-
}
2820+
switch (tag) {
2821+
case 65 /* "A" */:
2822+
// We must always clone to extract it into a separate buffer instead of just a view.
2823+
resolveBuffer(response, id, mergeBuffer(buffer, chunk).buffer);
2824+
return;
2825+
case 79 /* "O" */:
2826+
resolveTypedArray(response, id, buffer, chunk, Int8Array, 1);
2827+
return;
2828+
case 111 /* "o" */:
2829+
resolveBuffer(
2830+
response,
2831+
id,
2832+
buffer.length === 0 ? chunk : mergeBuffer(buffer, chunk),
2833+
);
2834+
return;
2835+
case 85 /* "U" */:
2836+
resolveTypedArray(response, id, buffer, chunk, Uint8ClampedArray, 1);
2837+
return;
2838+
case 83 /* "S" */:
2839+
resolveTypedArray(response, id, buffer, chunk, Int16Array, 2);
2840+
return;
2841+
case 115 /* "s" */:
2842+
resolveTypedArray(response, id, buffer, chunk, Uint16Array, 2);
2843+
return;
2844+
case 76 /* "L" */:
2845+
resolveTypedArray(response, id, buffer, chunk, Int32Array, 4);
2846+
return;
2847+
case 108 /* "l" */:
2848+
resolveTypedArray(response, id, buffer, chunk, Uint32Array, 4);
2849+
return;
2850+
case 71 /* "G" */:
2851+
resolveTypedArray(response, id, buffer, chunk, Float32Array, 4);
2852+
return;
2853+
case 103 /* "g" */:
2854+
resolveTypedArray(response, id, buffer, chunk, Float64Array, 8);
2855+
return;
2856+
case 77 /* "M" */:
2857+
resolveTypedArray(response, id, buffer, chunk, BigInt64Array, 8);
2858+
return;
2859+
case 109 /* "m" */:
2860+
resolveTypedArray(response, id, buffer, chunk, BigUint64Array, 8);
2861+
return;
2862+
case 86 /* "V" */:
2863+
resolveTypedArray(response, id, buffer, chunk, DataView, 1);
2864+
return;
28712865
}
28722866

28732867
const stringDecoder = response._stringDecoder;
@@ -3061,20 +3055,19 @@ export function processBinaryChunk(
30613055
const resolvedRowTag = chunk[i];
30623056
if (
30633057
resolvedRowTag === 84 /* "T" */ ||
3064-
(enableBinaryFlight &&
3065-
(resolvedRowTag === 65 /* "A" */ ||
3066-
resolvedRowTag === 79 /* "O" */ ||
3067-
resolvedRowTag === 111 /* "o" */ ||
3068-
resolvedRowTag === 85 /* "U" */ ||
3069-
resolvedRowTag === 83 /* "S" */ ||
3070-
resolvedRowTag === 115 /* "s" */ ||
3071-
resolvedRowTag === 76 /* "L" */ ||
3072-
resolvedRowTag === 108 /* "l" */ ||
3073-
resolvedRowTag === 71 /* "G" */ ||
3074-
resolvedRowTag === 103 /* "g" */ ||
3075-
resolvedRowTag === 77 /* "M" */ ||
3076-
resolvedRowTag === 109 /* "m" */ ||
3077-
resolvedRowTag === 86)) /* "V" */
3058+
resolvedRowTag === 65 /* "A" */ ||
3059+
resolvedRowTag === 79 /* "O" */ ||
3060+
resolvedRowTag === 111 /* "o" */ ||
3061+
resolvedRowTag === 85 /* "U" */ ||
3062+
resolvedRowTag === 83 /* "S" */ ||
3063+
resolvedRowTag === 115 /* "s" */ ||
3064+
resolvedRowTag === 76 /* "L" */ ||
3065+
resolvedRowTag === 108 /* "l" */ ||
3066+
resolvedRowTag === 71 /* "G" */ ||
3067+
resolvedRowTag === 103 /* "g" */ ||
3068+
resolvedRowTag === 77 /* "M" */ ||
3069+
resolvedRowTag === 109 /* "m" */ ||
3070+
resolvedRowTag === 86 /* "V" */
30783071
) {
30793072
rowTag = resolvedRowTag;
30803073
rowState = ROW_LENGTH;
@@ -3187,20 +3180,19 @@ export function processStringChunk(response: Response, chunk: string): void {
31873180
const resolvedRowTag = chunk.charCodeAt(i);
31883181
if (
31893182
resolvedRowTag === 84 /* "T" */ ||
3190-
(enableBinaryFlight &&
3191-
(resolvedRowTag === 65 /* "A" */ ||
3192-
resolvedRowTag === 79 /* "O" */ ||
3193-
resolvedRowTag === 111 /* "o" */ ||
3194-
resolvedRowTag === 85 /* "U" */ ||
3195-
resolvedRowTag === 83 /* "S" */ ||
3196-
resolvedRowTag === 115 /* "s" */ ||
3197-
resolvedRowTag === 76 /* "L" */ ||
3198-
resolvedRowTag === 108 /* "l" */ ||
3199-
resolvedRowTag === 71 /* "G" */ ||
3200-
resolvedRowTag === 103 /* "g" */ ||
3201-
resolvedRowTag === 77 /* "M" */ ||
3202-
resolvedRowTag === 109 /* "m" */ ||
3203-
resolvedRowTag === 86)) /* "V" */
3183+
resolvedRowTag === 65 /* "A" */ ||
3184+
resolvedRowTag === 79 /* "O" */ ||
3185+
resolvedRowTag === 111 /* "o" */ ||
3186+
resolvedRowTag === 85 /* "U" */ ||
3187+
resolvedRowTag === 83 /* "S" */ ||
3188+
resolvedRowTag === 115 /* "s" */ ||
3189+
resolvedRowTag === 76 /* "L" */ ||
3190+
resolvedRowTag === 108 /* "l" */ ||
3191+
resolvedRowTag === 71 /* "G" */ ||
3192+
resolvedRowTag === 103 /* "g" */ ||
3193+
resolvedRowTag === 77 /* "M" */ ||
3194+
resolvedRowTag === 109 /* "m" */ ||
3195+
resolvedRowTag === 86 /* "V" */
32043196
) {
32053197
rowTag = resolvedRowTag;
32063198
rowState = ROW_LENGTH;

packages/react-client/src/ReactFlightReplyClient.js

+63-66
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import type {TemporaryReferenceSet} from './ReactFlightTemporaryReferences';
2020

2121
import {
2222
enableRenderableContext,
23-
enableBinaryFlight,
2423
enableFlightReadableStream,
2524
} from 'shared/ReactFeatureFlags';
2625

@@ -578,73 +577,71 @@ export function processReply(
578577
return serializeSetID(setId);
579578
}
580579

581-
if (enableBinaryFlight) {
582-
if (value instanceof ArrayBuffer) {
583-
const blob = new Blob([value]);
584-
const blobId = nextPartId++;
585-
if (formData === null) {
586-
formData = new FormData();
587-
}
588-
formData.append(formFieldPrefix + blobId, blob);
589-
return '$' + 'A' + blobId.toString(16);
590-
}
591-
if (value instanceof Int8Array) {
592-
// char
593-
return serializeTypedArray('O', value);
594-
}
595-
if (value instanceof Uint8Array) {
596-
// unsigned char
597-
return serializeTypedArray('o', value);
598-
}
599-
if (value instanceof Uint8ClampedArray) {
600-
// unsigned clamped char
601-
return serializeTypedArray('U', value);
602-
}
603-
if (value instanceof Int16Array) {
604-
// sort
605-
return serializeTypedArray('S', value);
606-
}
607-
if (value instanceof Uint16Array) {
608-
// unsigned short
609-
return serializeTypedArray('s', value);
610-
}
611-
if (value instanceof Int32Array) {
612-
// long
613-
return serializeTypedArray('L', value);
614-
}
615-
if (value instanceof Uint32Array) {
616-
// unsigned long
617-
return serializeTypedArray('l', value);
618-
}
619-
if (value instanceof Float32Array) {
620-
// float
621-
return serializeTypedArray('G', value);
622-
}
623-
if (value instanceof Float64Array) {
624-
// double
625-
return serializeTypedArray('g', value);
626-
}
627-
if (value instanceof BigInt64Array) {
628-
// number
629-
return serializeTypedArray('M', value);
630-
}
631-
if (value instanceof BigUint64Array) {
632-
// unsigned number
633-
// We use "m" instead of "n" since JSON can start with "null"
634-
return serializeTypedArray('m', value);
635-
}
636-
if (value instanceof DataView) {
637-
return serializeTypedArray('V', value);
580+
if (value instanceof ArrayBuffer) {
581+
const blob = new Blob([value]);
582+
const blobId = nextPartId++;
583+
if (formData === null) {
584+
formData = new FormData();
638585
}
639-
// TODO: Blob is not available in old Node/browsers. Remove the typeof check later.
640-
if (typeof Blob === 'function' && value instanceof Blob) {
641-
if (formData === null) {
642-
formData = new FormData();
643-
}
644-
const blobId = nextPartId++;
645-
formData.append(formFieldPrefix + blobId, value);
646-
return serializeBlobID(blobId);
586+
formData.append(formFieldPrefix + blobId, blob);
587+
return '$' + 'A' + blobId.toString(16);
588+
}
589+
if (value instanceof Int8Array) {
590+
// char
591+
return serializeTypedArray('O', value);
592+
}
593+
if (value instanceof Uint8Array) {
594+
// unsigned char
595+
return serializeTypedArray('o', value);
596+
}
597+
if (value instanceof Uint8ClampedArray) {
598+
// unsigned clamped char
599+
return serializeTypedArray('U', value);
600+
}
601+
if (value instanceof Int16Array) {
602+
// sort
603+
return serializeTypedArray('S', value);
604+
}
605+
if (value instanceof Uint16Array) {
606+
// unsigned short
607+
return serializeTypedArray('s', value);
608+
}
609+
if (value instanceof Int32Array) {
610+
// long
611+
return serializeTypedArray('L', value);
612+
}
613+
if (value instanceof Uint32Array) {
614+
// unsigned long
615+
return serializeTypedArray('l', value);
616+
}
617+
if (value instanceof Float32Array) {
618+
// float
619+
return serializeTypedArray('G', value);
620+
}
621+
if (value instanceof Float64Array) {
622+
// double
623+
return serializeTypedArray('g', value);
624+
}
625+
if (value instanceof BigInt64Array) {
626+
// number
627+
return serializeTypedArray('M', value);
628+
}
629+
if (value instanceof BigUint64Array) {
630+
// unsigned number
631+
// We use "m" instead of "n" since JSON can start with "null"
632+
return serializeTypedArray('m', value);
633+
}
634+
if (value instanceof DataView) {
635+
return serializeTypedArray('V', value);
636+
}
637+
// TODO: Blob is not available in old Node/browsers. Remove the typeof check later.
638+
if (typeof Blob === 'function' && value instanceof Blob) {
639+
if (formData === null) {
640+
formData = new FormData();
647641
}
642+
const blobId = nextPartId++;
643+
formData.append(formFieldPrefix + blobId, value);
644+
return serializeBlobID(blobId);
648645
}
649646

650647
const iteratorFn = getIteratorFn(value);

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -2059,7 +2059,7 @@ describe('ReactFlight', () => {
20592059
expect(errors).toEqual(['Cannot pass a secret token to the client']);
20602060
});
20612061

2062-
// @gate enableTaint && enableBinaryFlight
2062+
// @gate enableTaint
20632063
it('errors when a tainted binary value is serialized', async () => {
20642064
function UserClient({user}) {
20652065
return <span>{user.name}</span>;

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

+2-5
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,6 @@ describe('ReactFlightDOMEdge', () => {
524524
expect(serializedContent.length).toBeLessThan(150 + expectedDebugInfoSize);
525525
});
526526

527-
// @gate enableBinaryFlight
528527
it('should be able to serialize any kind of typed array', async () => {
529528
const buffer = new Uint8Array([
530529
123, 4, 10, 5, 100, 255, 244, 45, 56, 67, 43, 124, 67, 89, 100, 20,
@@ -556,7 +555,6 @@ describe('ReactFlightDOMEdge', () => {
556555
expect(result).toEqual(buffers);
557556
});
558557

559-
// @gate enableBinaryFlight
560558
it('should be able to serialize a blob', async () => {
561559
const bytes = new Uint8Array([
562560
123, 4, 10, 5, 100, 255, 244, 45, 56, 67, 43, 124, 67, 89, 100, 20,
@@ -578,7 +576,6 @@ describe('ReactFlightDOMEdge', () => {
578576
expect(await result.arrayBuffer()).toEqual(await blob.arrayBuffer());
579577
});
580578

581-
// @gate enableBinaryFlight
582579
it('can transport FormData (blobs)', async () => {
583580
const bytes = new Uint8Array([
584581
123, 4, 10, 5, 100, 255, 244, 45, 56, 67, 43, 124, 67, 89, 100, 20,
@@ -823,7 +820,7 @@ describe('ReactFlightDOMEdge', () => {
823820
);
824821
});
825822

826-
// @gate enableFlightReadableStream && enableBinaryFlight
823+
// @gate enableFlightReadableStream
827824
it('should supports ReadableStreams with typed arrays', async () => {
828825
const buffer = new Uint8Array([
829826
123, 4, 10, 5, 100, 255, 244, 45, 56, 67, 43, 124, 67, 89, 100, 20,
@@ -882,7 +879,7 @@ describe('ReactFlightDOMEdge', () => {
882879
expect(streamedBuffers).toEqual(buffers);
883880
});
884881

885-
// @gate enableFlightReadableStream && enableBinaryFlight
882+
// @gate enableFlightReadableStream
886883
it('should support BYOB binary ReadableStreams', async () => {
887884
const buffer = new Uint8Array([
888885
123, 4, 10, 5, 100, 255, 244, 45, 56, 67, 43, 124, 67, 89, 100, 20,

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

-1
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,6 @@ describe('ReactFlightDOMForm', () => {
972972
expect(form2.firstChild.tagName).toBe('DIV');
973973
});
974974

975-
// @gate enableBinaryFlight
976975
it('useActionState can return binary state during MPA form submission', async () => {
977976
const serverAction = serverExports(
978977
async function action(prevState, formData) {

0 commit comments

Comments
 (0)