diff --git a/packages/react-client/src/ReactFlightClient.js b/packages/react-client/src/ReactFlightClient.js index 4d5204ab00220..259864e91d398 100644 --- a/packages/react-client/src/ReactFlightClient.js +++ b/packages/react-client/src/ReactFlightClient.js @@ -43,7 +43,6 @@ import type {Postpone} from 'react/src/ReactPostpone'; import type {TemporaryReferenceSet} from './ReactFlightTemporaryReferences'; import { - enableBinaryFlight, enablePostpone, enableFlightReadableStream, enableOwnerStacks, @@ -1461,11 +1460,8 @@ function parseModelString( } case 'B': { // Blob - if (enableBinaryFlight) { - const ref = value.slice(2); - return getOutlinedModel(response, ref, parentObject, key, createBlob); - } - return undefined; + const ref = value.slice(2); + return getOutlinedModel(response, ref, parentObject, key, createBlob); } case 'K': { // FormData @@ -2821,53 +2817,51 @@ function processFullBinaryRow( buffer: Array, chunk: Uint8Array, ): void { - if (enableBinaryFlight) { - switch (tag) { - case 65 /* "A" */: - // We must always clone to extract it into a separate buffer instead of just a view. - resolveBuffer(response, id, mergeBuffer(buffer, chunk).buffer); - return; - case 79 /* "O" */: - resolveTypedArray(response, id, buffer, chunk, Int8Array, 1); - return; - case 111 /* "o" */: - resolveBuffer( - response, - id, - buffer.length === 0 ? chunk : mergeBuffer(buffer, chunk), - ); - return; - case 85 /* "U" */: - resolveTypedArray(response, id, buffer, chunk, Uint8ClampedArray, 1); - return; - case 83 /* "S" */: - resolveTypedArray(response, id, buffer, chunk, Int16Array, 2); - return; - case 115 /* "s" */: - resolveTypedArray(response, id, buffer, chunk, Uint16Array, 2); - return; - case 76 /* "L" */: - resolveTypedArray(response, id, buffer, chunk, Int32Array, 4); - return; - case 108 /* "l" */: - resolveTypedArray(response, id, buffer, chunk, Uint32Array, 4); - return; - case 71 /* "G" */: - resolveTypedArray(response, id, buffer, chunk, Float32Array, 4); - return; - case 103 /* "g" */: - resolveTypedArray(response, id, buffer, chunk, Float64Array, 8); - return; - case 77 /* "M" */: - resolveTypedArray(response, id, buffer, chunk, BigInt64Array, 8); - return; - case 109 /* "m" */: - resolveTypedArray(response, id, buffer, chunk, BigUint64Array, 8); - return; - case 86 /* "V" */: - resolveTypedArray(response, id, buffer, chunk, DataView, 1); - return; - } + switch (tag) { + case 65 /* "A" */: + // We must always clone to extract it into a separate buffer instead of just a view. + resolveBuffer(response, id, mergeBuffer(buffer, chunk).buffer); + return; + case 79 /* "O" */: + resolveTypedArray(response, id, buffer, chunk, Int8Array, 1); + return; + case 111 /* "o" */: + resolveBuffer( + response, + id, + buffer.length === 0 ? chunk : mergeBuffer(buffer, chunk), + ); + return; + case 85 /* "U" */: + resolveTypedArray(response, id, buffer, chunk, Uint8ClampedArray, 1); + return; + case 83 /* "S" */: + resolveTypedArray(response, id, buffer, chunk, Int16Array, 2); + return; + case 115 /* "s" */: + resolveTypedArray(response, id, buffer, chunk, Uint16Array, 2); + return; + case 76 /* "L" */: + resolveTypedArray(response, id, buffer, chunk, Int32Array, 4); + return; + case 108 /* "l" */: + resolveTypedArray(response, id, buffer, chunk, Uint32Array, 4); + return; + case 71 /* "G" */: + resolveTypedArray(response, id, buffer, chunk, Float32Array, 4); + return; + case 103 /* "g" */: + resolveTypedArray(response, id, buffer, chunk, Float64Array, 8); + return; + case 77 /* "M" */: + resolveTypedArray(response, id, buffer, chunk, BigInt64Array, 8); + return; + case 109 /* "m" */: + resolveTypedArray(response, id, buffer, chunk, BigUint64Array, 8); + return; + case 86 /* "V" */: + resolveTypedArray(response, id, buffer, chunk, DataView, 1); + return; } const stringDecoder = response._stringDecoder; @@ -3061,20 +3055,19 @@ export function processBinaryChunk( const resolvedRowTag = chunk[i]; if ( resolvedRowTag === 84 /* "T" */ || - (enableBinaryFlight && - (resolvedRowTag === 65 /* "A" */ || - resolvedRowTag === 79 /* "O" */ || - resolvedRowTag === 111 /* "o" */ || - resolvedRowTag === 85 /* "U" */ || - resolvedRowTag === 83 /* "S" */ || - resolvedRowTag === 115 /* "s" */ || - resolvedRowTag === 76 /* "L" */ || - resolvedRowTag === 108 /* "l" */ || - resolvedRowTag === 71 /* "G" */ || - resolvedRowTag === 103 /* "g" */ || - resolvedRowTag === 77 /* "M" */ || - resolvedRowTag === 109 /* "m" */ || - resolvedRowTag === 86)) /* "V" */ + resolvedRowTag === 65 /* "A" */ || + resolvedRowTag === 79 /* "O" */ || + resolvedRowTag === 111 /* "o" */ || + resolvedRowTag === 85 /* "U" */ || + resolvedRowTag === 83 /* "S" */ || + resolvedRowTag === 115 /* "s" */ || + resolvedRowTag === 76 /* "L" */ || + resolvedRowTag === 108 /* "l" */ || + resolvedRowTag === 71 /* "G" */ || + resolvedRowTag === 103 /* "g" */ || + resolvedRowTag === 77 /* "M" */ || + resolvedRowTag === 109 /* "m" */ || + resolvedRowTag === 86 /* "V" */ ) { rowTag = resolvedRowTag; rowState = ROW_LENGTH; @@ -3187,20 +3180,19 @@ export function processStringChunk(response: Response, chunk: string): void { const resolvedRowTag = chunk.charCodeAt(i); if ( resolvedRowTag === 84 /* "T" */ || - (enableBinaryFlight && - (resolvedRowTag === 65 /* "A" */ || - resolvedRowTag === 79 /* "O" */ || - resolvedRowTag === 111 /* "o" */ || - resolvedRowTag === 85 /* "U" */ || - resolvedRowTag === 83 /* "S" */ || - resolvedRowTag === 115 /* "s" */ || - resolvedRowTag === 76 /* "L" */ || - resolvedRowTag === 108 /* "l" */ || - resolvedRowTag === 71 /* "G" */ || - resolvedRowTag === 103 /* "g" */ || - resolvedRowTag === 77 /* "M" */ || - resolvedRowTag === 109 /* "m" */ || - resolvedRowTag === 86)) /* "V" */ + resolvedRowTag === 65 /* "A" */ || + resolvedRowTag === 79 /* "O" */ || + resolvedRowTag === 111 /* "o" */ || + resolvedRowTag === 85 /* "U" */ || + resolvedRowTag === 83 /* "S" */ || + resolvedRowTag === 115 /* "s" */ || + resolvedRowTag === 76 /* "L" */ || + resolvedRowTag === 108 /* "l" */ || + resolvedRowTag === 71 /* "G" */ || + resolvedRowTag === 103 /* "g" */ || + resolvedRowTag === 77 /* "M" */ || + resolvedRowTag === 109 /* "m" */ || + resolvedRowTag === 86 /* "V" */ ) { rowTag = resolvedRowTag; rowState = ROW_LENGTH; diff --git a/packages/react-client/src/ReactFlightReplyClient.js b/packages/react-client/src/ReactFlightReplyClient.js index bfb2573ea35b0..81212437a09a0 100644 --- a/packages/react-client/src/ReactFlightReplyClient.js +++ b/packages/react-client/src/ReactFlightReplyClient.js @@ -20,7 +20,6 @@ import type {TemporaryReferenceSet} from './ReactFlightTemporaryReferences'; import { enableRenderableContext, - enableBinaryFlight, enableFlightReadableStream, } from 'shared/ReactFeatureFlags'; @@ -578,73 +577,71 @@ export function processReply( return serializeSetID(setId); } - if (enableBinaryFlight) { - if (value instanceof ArrayBuffer) { - const blob = new Blob([value]); - const blobId = nextPartId++; - if (formData === null) { - formData = new FormData(); - } - formData.append(formFieldPrefix + blobId, blob); - return '$' + 'A' + blobId.toString(16); - } - if (value instanceof Int8Array) { - // char - return serializeTypedArray('O', value); - } - if (value instanceof Uint8Array) { - // unsigned char - return serializeTypedArray('o', value); - } - if (value instanceof Uint8ClampedArray) { - // unsigned clamped char - return serializeTypedArray('U', value); - } - if (value instanceof Int16Array) { - // sort - return serializeTypedArray('S', value); - } - if (value instanceof Uint16Array) { - // unsigned short - return serializeTypedArray('s', value); - } - if (value instanceof Int32Array) { - // long - return serializeTypedArray('L', value); - } - if (value instanceof Uint32Array) { - // unsigned long - return serializeTypedArray('l', value); - } - if (value instanceof Float32Array) { - // float - return serializeTypedArray('G', value); - } - if (value instanceof Float64Array) { - // double - return serializeTypedArray('g', value); - } - if (value instanceof BigInt64Array) { - // number - return serializeTypedArray('M', value); - } - if (value instanceof BigUint64Array) { - // unsigned number - // We use "m" instead of "n" since JSON can start with "null" - return serializeTypedArray('m', value); - } - if (value instanceof DataView) { - return serializeTypedArray('V', value); + if (value instanceof ArrayBuffer) { + const blob = new Blob([value]); + const blobId = nextPartId++; + if (formData === null) { + formData = new FormData(); } - // TODO: Blob is not available in old Node/browsers. Remove the typeof check later. - if (typeof Blob === 'function' && value instanceof Blob) { - if (formData === null) { - formData = new FormData(); - } - const blobId = nextPartId++; - formData.append(formFieldPrefix + blobId, value); - return serializeBlobID(blobId); + formData.append(formFieldPrefix + blobId, blob); + return '$' + 'A' + blobId.toString(16); + } + if (value instanceof Int8Array) { + // char + return serializeTypedArray('O', value); + } + if (value instanceof Uint8Array) { + // unsigned char + return serializeTypedArray('o', value); + } + if (value instanceof Uint8ClampedArray) { + // unsigned clamped char + return serializeTypedArray('U', value); + } + if (value instanceof Int16Array) { + // sort + return serializeTypedArray('S', value); + } + if (value instanceof Uint16Array) { + // unsigned short + return serializeTypedArray('s', value); + } + if (value instanceof Int32Array) { + // long + return serializeTypedArray('L', value); + } + if (value instanceof Uint32Array) { + // unsigned long + return serializeTypedArray('l', value); + } + if (value instanceof Float32Array) { + // float + return serializeTypedArray('G', value); + } + if (value instanceof Float64Array) { + // double + return serializeTypedArray('g', value); + } + if (value instanceof BigInt64Array) { + // number + return serializeTypedArray('M', value); + } + if (value instanceof BigUint64Array) { + // unsigned number + // We use "m" instead of "n" since JSON can start with "null" + return serializeTypedArray('m', value); + } + if (value instanceof DataView) { + return serializeTypedArray('V', value); + } + // TODO: Blob is not available in old Node/browsers. Remove the typeof check later. + if (typeof Blob === 'function' && value instanceof Blob) { + if (formData === null) { + formData = new FormData(); } + const blobId = nextPartId++; + formData.append(formFieldPrefix + blobId, value); + return serializeBlobID(blobId); } const iteratorFn = getIteratorFn(value); diff --git a/packages/react-client/src/__tests__/ReactFlight-test.js b/packages/react-client/src/__tests__/ReactFlight-test.js index 75220b762918e..af12c583db11a 100644 --- a/packages/react-client/src/__tests__/ReactFlight-test.js +++ b/packages/react-client/src/__tests__/ReactFlight-test.js @@ -2059,7 +2059,7 @@ describe('ReactFlight', () => { expect(errors).toEqual(['Cannot pass a secret token to the client']); }); - // @gate enableTaint && enableBinaryFlight + // @gate enableTaint it('errors when a tainted binary value is serialized', async () => { function UserClient({user}) { return {user.name}; diff --git a/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMEdge-test.js b/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMEdge-test.js index e702ae8f8e84f..3bd481205f1b4 100644 --- a/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMEdge-test.js +++ b/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMEdge-test.js @@ -524,7 +524,6 @@ describe('ReactFlightDOMEdge', () => { expect(serializedContent.length).toBeLessThan(150 + expectedDebugInfoSize); }); - // @gate enableBinaryFlight it('should be able to serialize any kind of typed array', async () => { const buffer = new Uint8Array([ 123, 4, 10, 5, 100, 255, 244, 45, 56, 67, 43, 124, 67, 89, 100, 20, @@ -556,7 +555,6 @@ describe('ReactFlightDOMEdge', () => { expect(result).toEqual(buffers); }); - // @gate enableBinaryFlight it('should be able to serialize a blob', async () => { const bytes = new Uint8Array([ 123, 4, 10, 5, 100, 255, 244, 45, 56, 67, 43, 124, 67, 89, 100, 20, @@ -578,7 +576,6 @@ describe('ReactFlightDOMEdge', () => { expect(await result.arrayBuffer()).toEqual(await blob.arrayBuffer()); }); - // @gate enableBinaryFlight it('can transport FormData (blobs)', async () => { const bytes = new Uint8Array([ 123, 4, 10, 5, 100, 255, 244, 45, 56, 67, 43, 124, 67, 89, 100, 20, @@ -823,7 +820,7 @@ describe('ReactFlightDOMEdge', () => { ); }); - // @gate enableFlightReadableStream && enableBinaryFlight + // @gate enableFlightReadableStream it('should supports ReadableStreams with typed arrays', async () => { const buffer = new Uint8Array([ 123, 4, 10, 5, 100, 255, 244, 45, 56, 67, 43, 124, 67, 89, 100, 20, @@ -882,7 +879,7 @@ describe('ReactFlightDOMEdge', () => { expect(streamedBuffers).toEqual(buffers); }); - // @gate enableFlightReadableStream && enableBinaryFlight + // @gate enableFlightReadableStream it('should support BYOB binary ReadableStreams', async () => { const buffer = new Uint8Array([ 123, 4, 10, 5, 100, 255, 244, 45, 56, 67, 43, 124, 67, 89, 100, 20, diff --git a/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMForm-test.js b/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMForm-test.js index f98b79dd8a890..0b4549d5bac47 100644 --- a/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMForm-test.js +++ b/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMForm-test.js @@ -972,7 +972,6 @@ describe('ReactFlightDOMForm', () => { expect(form2.firstChild.tagName).toBe('DIV'); }); - // @gate enableBinaryFlight it('useActionState can return binary state during MPA form submission', async () => { const serverAction = serverExports( async function action(prevState, formData) { diff --git a/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMNode-test.js b/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMNode-test.js index ada19fb1fc44b..4278c220d8b83 100644 --- a/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMNode-test.js +++ b/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMNode-test.js @@ -197,7 +197,6 @@ describe('ReactFlightDOMNode', () => { expect(result.text).toBe(testString); }); - // @gate enableBinaryFlight it('should be able to serialize any kind of typed array', async () => { const buffer = new Uint8Array([ 123, 4, 10, 5, 100, 255, 244, 45, 56, 67, 43, 124, 67, 89, 100, 20, diff --git a/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMReplyEdge-test.js b/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMReplyEdge-test.js index a02d2b0c0fd81..2697d3eeb2dc8 100644 --- a/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMReplyEdge-test.js +++ b/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMReplyEdge-test.js @@ -53,7 +53,6 @@ describe('ReactFlightDOMReplyEdge', () => { expect(decoded).toEqual({some: 'object'}); }); - // @gate enableBinaryFlight it('should be able to serialize any kind of typed array', async () => { const buffer = new Uint8Array([ 123, 4, 10, 5, 100, 255, 244, 45, 56, 67, 43, 124, 67, 89, 100, 20, @@ -85,7 +84,6 @@ describe('ReactFlightDOMReplyEdge', () => { expect(new Uint8Array(result[0])).toEqual(new Uint8Array(buffers[0])); }); - // @gate enableBinaryFlight it('should be able to serialize a typed array inside a Map', async () => { const array = new Uint8Array([ 123, 4, 10, 5, 100, 255, 244, 45, 56, 67, 43, 124, 67, 89, 100, 20, @@ -102,7 +100,6 @@ describe('ReactFlightDOMReplyEdge', () => { expect(result.get('array')).toEqual(array); }); - // @gate enableBinaryFlight it('should be able to serialize a blob', async () => { const bytes = new Uint8Array([ 123, 4, 10, 5, 100, 255, 244, 45, 56, 67, 43, 124, 67, 89, 100, 20, @@ -150,7 +147,7 @@ describe('ReactFlightDOMReplyEdge', () => { expect(await resultBlob.arrayBuffer()).toEqual(await blob.arrayBuffer()); }); - // @gate enableFlightReadableStream && enableBinaryFlight + // @gate enableFlightReadableStream it('should supports ReadableStreams with typed arrays', async () => { const buffer = new Uint8Array([ 123, 4, 10, 5, 100, 255, 244, 45, 56, 67, 43, 124, 67, 89, 100, 20, @@ -197,7 +194,7 @@ describe('ReactFlightDOMReplyEdge', () => { expect(streamedBuffers).toEqual(buffers); }); - // @gate enableFlightReadableStream && enableBinaryFlight + // @gate enableFlightReadableStream it('should support BYOB binary ReadableStreams', async () => { const buffer = new Uint8Array([ 123, 4, 10, 5, 100, 255, 244, 45, 56, 67, 43, 124, 67, 89, 100, 20, diff --git a/packages/react-server/src/ReactFlightReplyServer.js b/packages/react-server/src/ReactFlightReplyServer.js index 95746e6e16464..d47a28d49d506 100644 --- a/packages/react-server/src/ReactFlightReplyServer.js +++ b/packages/react-server/src/ReactFlightReplyServer.js @@ -30,10 +30,7 @@ import { createTemporaryReference, registerTemporaryReference, } from './ReactFlightServerTemporaryReferences'; -import { - enableBinaryFlight, - enableFlightReadableStream, -} from 'shared/ReactFeatureFlags'; +import {enableFlightReadableStream} from 'shared/ReactFeatureFlags'; import {ASYNC_ITERATOR} from 'shared/ReactSymbols'; import hasOwnProperty from 'shared/hasOwnProperty'; @@ -1019,51 +1016,42 @@ function parseModelString( return BigInt(value.slice(2)); } } - if (enableBinaryFlight) { - switch (value[1]) { - case 'A': - return parseTypedArray(response, value, ArrayBuffer, 1, obj, key); - case 'O': - return parseTypedArray(response, value, Int8Array, 1, obj, key); - case 'o': - return parseTypedArray(response, value, Uint8Array, 1, obj, key); - case 'U': - return parseTypedArray( - response, - value, - Uint8ClampedArray, - 1, - obj, - key, - ); - case 'S': - return parseTypedArray(response, value, Int16Array, 2, obj, key); - case 's': - return parseTypedArray(response, value, Uint16Array, 2, obj, key); - case 'L': - return parseTypedArray(response, value, Int32Array, 4, obj, key); - case 'l': - return parseTypedArray(response, value, Uint32Array, 4, obj, key); - case 'G': - return parseTypedArray(response, value, Float32Array, 4, obj, key); - case 'g': - return parseTypedArray(response, value, Float64Array, 8, obj, key); - case 'M': - return parseTypedArray(response, value, BigInt64Array, 8, obj, key); - case 'm': - return parseTypedArray(response, value, BigUint64Array, 8, obj, key); - case 'V': - return parseTypedArray(response, value, DataView, 1, obj, key); - case 'B': { - // Blob - const id = parseInt(value.slice(2), 16); - const prefix = response._prefix; - const blobKey = prefix + id; - // We should have this backingEntry in the store already because we emitted - // it before referencing it. It should be a Blob. - const backingEntry: Blob = (response._formData.get(blobKey): any); - return backingEntry; - } + switch (value[1]) { + case 'A': + return parseTypedArray(response, value, ArrayBuffer, 1, obj, key); + case 'O': + return parseTypedArray(response, value, Int8Array, 1, obj, key); + case 'o': + return parseTypedArray(response, value, Uint8Array, 1, obj, key); + case 'U': + return parseTypedArray(response, value, Uint8ClampedArray, 1, obj, key); + case 'S': + return parseTypedArray(response, value, Int16Array, 2, obj, key); + case 's': + return parseTypedArray(response, value, Uint16Array, 2, obj, key); + case 'L': + return parseTypedArray(response, value, Int32Array, 4, obj, key); + case 'l': + return parseTypedArray(response, value, Uint32Array, 4, obj, key); + case 'G': + return parseTypedArray(response, value, Float32Array, 4, obj, key); + case 'g': + return parseTypedArray(response, value, Float64Array, 8, obj, key); + case 'M': + return parseTypedArray(response, value, BigInt64Array, 8, obj, key); + case 'm': + return parseTypedArray(response, value, BigUint64Array, 8, obj, key); + case 'V': + return parseTypedArray(response, value, DataView, 1, obj, key); + case 'B': { + // Blob + const id = parseInt(value.slice(2), 16); + const prefix = response._prefix; + const blobKey = prefix + id; + // We should have this backingEntry in the store already because we emitted + // it before referencing it. It should be a Blob. + const backingEntry: Blob = (response._formData.get(blobKey): any); + return backingEntry; } } if (enableFlightReadableStream) { diff --git a/packages/react-server/src/ReactFlightServer.js b/packages/react-server/src/ReactFlightServer.js index 860ff3cd0d898..7f8dd32a99921 100644 --- a/packages/react-server/src/ReactFlightServer.js +++ b/packages/react-server/src/ReactFlightServer.js @@ -14,7 +14,6 @@ import type {Postpone} from 'react/src/ReactPostpone'; import type {TemporaryReferenceSet} from './ReactFlightServerTemporaryReferences'; import { - enableBinaryFlight, enablePostpone, enableHalt, enableTaint, @@ -2696,63 +2695,60 @@ function renderModelDestructive( if (value instanceof Error) { return serializeErrorValue(request, value); } - - if (enableBinaryFlight) { - if (value instanceof ArrayBuffer) { - return serializeTypedArray(request, 'A', new Uint8Array(value)); - } - if (value instanceof Int8Array) { - // char - return serializeTypedArray(request, 'O', value); - } - if (value instanceof Uint8Array) { - // unsigned char - return serializeTypedArray(request, 'o', value); - } - if (value instanceof Uint8ClampedArray) { - // unsigned clamped char - return serializeTypedArray(request, 'U', value); - } - if (value instanceof Int16Array) { - // sort - return serializeTypedArray(request, 'S', value); - } - if (value instanceof Uint16Array) { - // unsigned short - return serializeTypedArray(request, 's', value); - } - if (value instanceof Int32Array) { - // long - return serializeTypedArray(request, 'L', value); - } - if (value instanceof Uint32Array) { - // unsigned long - return serializeTypedArray(request, 'l', value); - } - if (value instanceof Float32Array) { - // float - return serializeTypedArray(request, 'G', value); - } - if (value instanceof Float64Array) { - // double - return serializeTypedArray(request, 'g', value); - } - if (value instanceof BigInt64Array) { - // number - return serializeTypedArray(request, 'M', value); - } - if (value instanceof BigUint64Array) { - // unsigned number - // We use "m" instead of "n" since JSON can start with "null" - return serializeTypedArray(request, 'm', value); - } - if (value instanceof DataView) { - return serializeTypedArray(request, 'V', value); - } - // TODO: Blob is not available in old Node. Remove the typeof check later. - if (typeof Blob === 'function' && value instanceof Blob) { - return serializeBlob(request, value); - } + if (value instanceof ArrayBuffer) { + return serializeTypedArray(request, 'A', new Uint8Array(value)); + } + if (value instanceof Int8Array) { + // char + return serializeTypedArray(request, 'O', value); + } + if (value instanceof Uint8Array) { + // unsigned char + return serializeTypedArray(request, 'o', value); + } + if (value instanceof Uint8ClampedArray) { + // unsigned clamped char + return serializeTypedArray(request, 'U', value); + } + if (value instanceof Int16Array) { + // sort + return serializeTypedArray(request, 'S', value); + } + if (value instanceof Uint16Array) { + // unsigned short + return serializeTypedArray(request, 's', value); + } + if (value instanceof Int32Array) { + // long + return serializeTypedArray(request, 'L', value); + } + if (value instanceof Uint32Array) { + // unsigned long + return serializeTypedArray(request, 'l', value); + } + if (value instanceof Float32Array) { + // float + return serializeTypedArray(request, 'G', value); + } + if (value instanceof Float64Array) { + // double + return serializeTypedArray(request, 'g', value); + } + if (value instanceof BigInt64Array) { + // number + return serializeTypedArray(request, 'M', value); + } + if (value instanceof BigUint64Array) { + // unsigned number + // We use "m" instead of "n" since JSON can start with "null" + return serializeTypedArray(request, 'm', value); + } + if (value instanceof DataView) { + return serializeTypedArray(request, 'V', value); + } + // TODO: Blob is not available in old Node. Remove the typeof check later. + if (typeof Blob === 'function' && value instanceof Blob) { + return serializeBlob(request, value); } const iteratorFn = getIteratorFn(value); @@ -3532,63 +3528,60 @@ function renderConsoleValue( if (value instanceof Error) { return serializeErrorValue(request, value); } - - if (enableBinaryFlight) { - if (value instanceof ArrayBuffer) { - return serializeTypedArray(request, 'A', new Uint8Array(value)); - } - if (value instanceof Int8Array) { - // char - return serializeTypedArray(request, 'O', value); - } - if (value instanceof Uint8Array) { - // unsigned char - return serializeTypedArray(request, 'o', value); - } - if (value instanceof Uint8ClampedArray) { - // unsigned clamped char - return serializeTypedArray(request, 'U', value); - } - if (value instanceof Int16Array) { - // sort - return serializeTypedArray(request, 'S', value); - } - if (value instanceof Uint16Array) { - // unsigned short - return serializeTypedArray(request, 's', value); - } - if (value instanceof Int32Array) { - // long - return serializeTypedArray(request, 'L', value); - } - if (value instanceof Uint32Array) { - // unsigned long - return serializeTypedArray(request, 'l', value); - } - if (value instanceof Float32Array) { - // float - return serializeTypedArray(request, 'G', value); - } - if (value instanceof Float64Array) { - // double - return serializeTypedArray(request, 'g', value); - } - if (value instanceof BigInt64Array) { - // number - return serializeTypedArray(request, 'M', value); - } - if (value instanceof BigUint64Array) { - // unsigned number - // We use "m" instead of "n" since JSON can start with "null" - return serializeTypedArray(request, 'm', value); - } - if (value instanceof DataView) { - return serializeTypedArray(request, 'V', value); - } - // TODO: Blob is not available in old Node. Remove the typeof check later. - if (typeof Blob === 'function' && value instanceof Blob) { - return serializeBlob(request, value); - } + if (value instanceof ArrayBuffer) { + return serializeTypedArray(request, 'A', new Uint8Array(value)); + } + if (value instanceof Int8Array) { + // char + return serializeTypedArray(request, 'O', value); + } + if (value instanceof Uint8Array) { + // unsigned char + return serializeTypedArray(request, 'o', value); + } + if (value instanceof Uint8ClampedArray) { + // unsigned clamped char + return serializeTypedArray(request, 'U', value); + } + if (value instanceof Int16Array) { + // sort + return serializeTypedArray(request, 'S', value); + } + if (value instanceof Uint16Array) { + // unsigned short + return serializeTypedArray(request, 's', value); + } + if (value instanceof Int32Array) { + // long + return serializeTypedArray(request, 'L', value); + } + if (value instanceof Uint32Array) { + // unsigned long + return serializeTypedArray(request, 'l', value); + } + if (value instanceof Float32Array) { + // float + return serializeTypedArray(request, 'G', value); + } + if (value instanceof Float64Array) { + // double + return serializeTypedArray(request, 'g', value); + } + if (value instanceof BigInt64Array) { + // number + return serializeTypedArray(request, 'M', value); + } + if (value instanceof BigUint64Array) { + // unsigned number + // We use "m" instead of "n" since JSON can start with "null" + return serializeTypedArray(request, 'm', value); + } + if (value instanceof DataView) { + return serializeTypedArray(request, 'V', value); + } + // TODO: Blob is not available in old Node. Remove the typeof check later. + if (typeof Blob === 'function' && value instanceof Blob) { + return serializeBlob(request, value); } const iteratorFn = getIteratorFn(value); @@ -3878,71 +3871,69 @@ function emitChunk( emitTextChunk(request, id, value); return; } - if (enableBinaryFlight) { - if (value instanceof ArrayBuffer) { - emitTypedArrayChunk(request, id, 'A', new Uint8Array(value)); - return; - } - if (value instanceof Int8Array) { - // char - emitTypedArrayChunk(request, id, 'O', value); - return; - } - if (value instanceof Uint8Array) { - // unsigned char - emitTypedArrayChunk(request, id, 'o', value); - return; - } - if (value instanceof Uint8ClampedArray) { - // unsigned clamped char - emitTypedArrayChunk(request, id, 'U', value); - return; - } - if (value instanceof Int16Array) { - // sort - emitTypedArrayChunk(request, id, 'S', value); - return; - } - if (value instanceof Uint16Array) { - // unsigned short - emitTypedArrayChunk(request, id, 's', value); - return; - } - if (value instanceof Int32Array) { - // long - emitTypedArrayChunk(request, id, 'L', value); - return; - } - if (value instanceof Uint32Array) { - // unsigned long - emitTypedArrayChunk(request, id, 'l', value); - return; - } - if (value instanceof Float32Array) { - // float - emitTypedArrayChunk(request, id, 'G', value); - return; - } - if (value instanceof Float64Array) { - // double - emitTypedArrayChunk(request, id, 'g', value); - return; - } - if (value instanceof BigInt64Array) { - // number - emitTypedArrayChunk(request, id, 'M', value); - return; - } - if (value instanceof BigUint64Array) { - // unsigned number - // We use "m" instead of "n" since JSON can start with "null" - emitTypedArrayChunk(request, id, 'm', value); - return; - } - if (value instanceof DataView) { - emitTypedArrayChunk(request, id, 'V', value); - return; - } + if (value instanceof ArrayBuffer) { + emitTypedArrayChunk(request, id, 'A', new Uint8Array(value)); + return; + } + if (value instanceof Int8Array) { + // char + emitTypedArrayChunk(request, id, 'O', value); + return; + } + if (value instanceof Uint8Array) { + // unsigned char + emitTypedArrayChunk(request, id, 'o', value); + return; + } + if (value instanceof Uint8ClampedArray) { + // unsigned clamped char + emitTypedArrayChunk(request, id, 'U', value); + return; + } + if (value instanceof Int16Array) { + // sort + emitTypedArrayChunk(request, id, 'S', value); + return; + } + if (value instanceof Uint16Array) { + // unsigned short + emitTypedArrayChunk(request, id, 's', value); + return; + } + if (value instanceof Int32Array) { + // long + emitTypedArrayChunk(request, id, 'L', value); + return; + } + if (value instanceof Uint32Array) { + // unsigned long + emitTypedArrayChunk(request, id, 'l', value); + return; + } + if (value instanceof Float32Array) { + // float + emitTypedArrayChunk(request, id, 'G', value); + return; + } + if (value instanceof Float64Array) { + // double + emitTypedArrayChunk(request, id, 'g', value); + return; + } + if (value instanceof BigInt64Array) { + // number + emitTypedArrayChunk(request, id, 'M', value); + return; + } + if (value instanceof BigUint64Array) { + // unsigned number + // We use "m" instead of "n" since JSON can start with "null" + emitTypedArrayChunk(request, id, 'm', value); + return; + } + if (value instanceof DataView) { + emitTypedArrayChunk(request, id, 'V', value); + return; } // For anything else we need to try to serialize it using JSON. // $FlowFixMe[incompatible-type] stringify can return null for undefined but we never do diff --git a/packages/react/src/ReactTaint.js b/packages/react/src/ReactTaint.js index 1664578317238..99bf73ac25448 100644 --- a/packages/react/src/ReactTaint.js +++ b/packages/react/src/ReactTaint.js @@ -7,7 +7,7 @@ * @flow */ -import {enableTaint, enableBinaryFlight} from 'shared/ReactFeatureFlags'; +import {enableTaint} from 'shared/ReactFeatureFlags'; import getPrototypeOf from 'shared/getPrototypeOf'; @@ -76,8 +76,8 @@ export function taintUniqueValue( // Use as is. entryValue = value; } else if ( - enableBinaryFlight && - (value instanceof TypedArrayConstructor || value instanceof DataView) + value instanceof TypedArrayConstructor || + value instanceof DataView ) { // For now, we just convert binary data to a string so that we can just use the native // hashing in the Map implementation. It doesn't really matter what form the string diff --git a/packages/shared/ReactFeatureFlags.js b/packages/shared/ReactFeatureFlags.js index a96d0e1917434..ccf9310ba5805 100644 --- a/packages/shared/ReactFeatureFlags.js +++ b/packages/shared/ReactFeatureFlags.js @@ -78,7 +78,6 @@ export const enableLegacyFBSupport = false; export const enableCache = true; export const enableLegacyCache = __EXPERIMENTAL__; -export const enableBinaryFlight = true; export const enableFlightReadableStream = true; export const enableAsyncIterableChildren = __EXPERIMENTAL__; diff --git a/packages/shared/forks/ReactFeatureFlags.native-fb.js b/packages/shared/forks/ReactFeatureFlags.native-fb.js index eb3f5f3cd5553..0d13fe48058af 100644 --- a/packages/shared/forks/ReactFeatureFlags.native-fb.js +++ b/packages/shared/forks/ReactFeatureFlags.native-fb.js @@ -44,7 +44,6 @@ export const disableSchedulerTimeoutInWorkLoop = false; export const disableTextareaChildren = false; export const enableAsyncDebugInfo = false; export const enableAsyncIterableChildren = false; -export const enableBinaryFlight = true; export const enableCache = true; export const enableComponentStackLocations = true; export const enableCPUSuspense = true; diff --git a/packages/shared/forks/ReactFeatureFlags.native-oss.js b/packages/shared/forks/ReactFeatureFlags.native-oss.js index d725ecba679ce..a3ac1e88c2a97 100644 --- a/packages/shared/forks/ReactFeatureFlags.native-oss.js +++ b/packages/shared/forks/ReactFeatureFlags.native-oss.js @@ -31,7 +31,6 @@ export const disableSchedulerTimeoutInWorkLoop = false; export const disableTextareaChildren = false; export const enableAsyncDebugInfo = false; export const enableAsyncIterableChildren = false; -export const enableBinaryFlight = true; export const enableCache = true; export const enableComponentStackLocations = true; export const enableCPUSuspense = false; diff --git a/packages/shared/forks/ReactFeatureFlags.test-renderer.js b/packages/shared/forks/ReactFeatureFlags.test-renderer.js index 2c6892de26d96..7d3502cb1cac0 100644 --- a/packages/shared/forks/ReactFeatureFlags.test-renderer.js +++ b/packages/shared/forks/ReactFeatureFlags.test-renderer.js @@ -21,7 +21,6 @@ export const enableComponentPerformanceTrack = false; export const enableUpdaterTracking = false; export const enableCache = true; export const enableLegacyCache = __EXPERIMENTAL__; -export const enableBinaryFlight = true; export const enableFlightReadableStream = true; export const enableAsyncIterableChildren = false; export const enableTaint = true; diff --git a/packages/shared/forks/ReactFeatureFlags.test-renderer.native-fb.js b/packages/shared/forks/ReactFeatureFlags.test-renderer.native-fb.js index eff87c5683fc8..92034467fd72b 100644 --- a/packages/shared/forks/ReactFeatureFlags.test-renderer.native-fb.js +++ b/packages/shared/forks/ReactFeatureFlags.test-renderer.native-fb.js @@ -23,7 +23,6 @@ export const disableSchedulerTimeoutInWorkLoop = false; export const disableTextareaChildren = false; export const enableAsyncDebugInfo = false; export const enableAsyncIterableChildren = false; -export const enableBinaryFlight = true; export const enableCache = true; export const enableComponentStackLocations = true; export const enableCPUSuspense = true; diff --git a/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js b/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js index 00a0463353dda..b093ebf81b202 100644 --- a/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js +++ b/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js @@ -21,7 +21,6 @@ export const enableComponentPerformanceTrack = false; export const enableUpdaterTracking = false; export const enableCache = true; export const enableLegacyCache = true; -export const enableBinaryFlight = true; export const enableFlightReadableStream = true; export const enableAsyncIterableChildren = false; export const enableTaint = true; diff --git a/packages/shared/forks/ReactFeatureFlags.www.js b/packages/shared/forks/ReactFeatureFlags.www.js index 65edbea8e153a..8abe581e7989c 100644 --- a/packages/shared/forks/ReactFeatureFlags.www.js +++ b/packages/shared/forks/ReactFeatureFlags.www.js @@ -76,7 +76,6 @@ export const enableGetInspectorDataForInstanceInProduction = false; export const enableCache = true; export const enableLegacyCache = true; -export const enableBinaryFlight = true; export const enableFlightReadableStream = true; export const enableAsyncIterableChildren = false;