diff --git a/packages/react-transport-dom-relay/src/ReactFlightDOMRelayClient.js b/packages/react-transport-dom-relay/src/ReactFlightDOMRelayClient.js index 4355f1aaa5e8e..73efb45ab98c8 100644 --- a/packages/react-transport-dom-relay/src/ReactFlightDOMRelayClient.js +++ b/packages/react-transport-dom-relay/src/ReactFlightDOMRelayClient.js @@ -22,11 +22,12 @@ import { export {createResponse, close}; export function resolveRow(response: Response, chunk: RowEncoding): void { - if (chunk.type === 'json') { - resolveModel(response, chunk.id, chunk.json); - } else if (chunk.type === 'module') { - resolveModule(response, chunk.id, chunk.json); - } else { - resolveError(response, chunk.id, chunk.json.message, chunk.json.stack); + if (chunk[0] === 'J') { + resolveModel(response, chunk[1], chunk[2]); + } else if (chunk[0] === 'M') { + resolveModule(response, chunk[1], chunk[2]); + } else if (chunk[0] === 'E') { + // $FlowFixMe: Flow doesn't support disjoint unions on tuples. + resolveError(response, chunk[1], chunk[2].message, chunk[2].stack); } } diff --git a/packages/react-transport-dom-relay/src/ReactFlightDOMRelayProtocol.js b/packages/react-transport-dom-relay/src/ReactFlightDOMRelayProtocol.js index efbf82ed25c1a..263161d53852d 100644 --- a/packages/react-transport-dom-relay/src/ReactFlightDOMRelayProtocol.js +++ b/packages/react-transport-dom-relay/src/ReactFlightDOMRelayProtocol.js @@ -18,22 +18,14 @@ export type JSONValue = | Array; export type RowEncoding = - | { - type: 'json', - id: number, - json: JSONValue, - } - | { - type: 'module', - id: number, - json: ModuleMetaData, - } - | { - type: 'error', - id: number, - json: { + | ['J', number, JSONValue] + | ['M', number, ModuleMetaData] + | [ + 'E', + number, + { message: string, stack: string, ... }, - }; + ]; diff --git a/packages/react-transport-dom-relay/src/ReactFlightDOMRelayServerHostConfig.js b/packages/react-transport-dom-relay/src/ReactFlightDOMRelayServerHostConfig.js index f995116ce30bc..d3fc134176a96 100644 --- a/packages/react-transport-dom-relay/src/ReactFlightDOMRelayServerHostConfig.js +++ b/packages/react-transport-dom-relay/src/ReactFlightDOMRelayServerHostConfig.js @@ -53,14 +53,14 @@ export function processErrorChunk( message: string, stack: string, ): Chunk { - return { - type: 'error', - id: id, - json: { + return [ + 'E', + id, + { message, stack, }, - }; + ]; } function convertModelToJSON( @@ -99,11 +99,7 @@ export function processModelChunk( model: ReactModel, ): Chunk { const json = convertModelToJSON(request, {}, '', model); - return { - type: 'json', - id: id, - json: json, - }; + return ['J', id, json]; } export function processModuleChunk( @@ -112,11 +108,7 @@ export function processModuleChunk( moduleMetaData: ModuleMetaData, ): Chunk { // The moduleMetaData is already a JSON serializable value. - return { - type: 'module', - id: id, - json: moduleMetaData, - }; + return ['M', id, moduleMetaData]; } export function scheduleWork(callback: () => void) { diff --git a/packages/react-transport-native-relay/src/ReactFlightNativeRelayClient.js b/packages/react-transport-native-relay/src/ReactFlightNativeRelayClient.js index f023b0dc15a8c..872411f97a790 100644 --- a/packages/react-transport-native-relay/src/ReactFlightNativeRelayClient.js +++ b/packages/react-transport-native-relay/src/ReactFlightNativeRelayClient.js @@ -22,11 +22,12 @@ import { export {createResponse, close}; export function resolveRow(response: Response, chunk: RowEncoding): void { - if (chunk.type === 'json') { - resolveModel(response, chunk.id, chunk.json); - } else if (chunk.type === 'module') { - resolveModule(response, chunk.id, chunk.json); - } else { - resolveError(response, chunk.id, chunk.json.message, chunk.json.stack); + if (chunk[0] === 'J') { + resolveModel(response, chunk[1], chunk[2]); + } else if (chunk[0] === 'M') { + resolveModule(response, chunk[1], chunk[2]); + } else if (chunk[0] === 'E') { + // $FlowFixMe: Flow doesn't support disjoint unions on tuples. + resolveError(response, chunk[1], chunk[2].message, chunk[2].stack); } } diff --git a/packages/react-transport-native-relay/src/ReactFlightNativeRelayProtocol.js b/packages/react-transport-native-relay/src/ReactFlightNativeRelayProtocol.js index 9f59b3040d911..5689f8c0f974c 100644 --- a/packages/react-transport-native-relay/src/ReactFlightNativeRelayProtocol.js +++ b/packages/react-transport-native-relay/src/ReactFlightNativeRelayProtocol.js @@ -18,22 +18,14 @@ export type JSONValue = | Array; export type RowEncoding = - | { - type: 'json', - id: number, - json: JSONValue, - } - | { - type: 'module', - id: number, - json: ModuleMetaData, - } - | { - type: 'error', - id: number, - json: { + | ['J', number, JSONValue] + | ['M', number, ModuleMetaData] + | [ + 'E', + number, + { message: string, stack: string, ... }, - }; + ]; diff --git a/packages/react-transport-native-relay/src/ReactFlightNativeRelayServerHostConfig.js b/packages/react-transport-native-relay/src/ReactFlightNativeRelayServerHostConfig.js index b2a12efb4a0b0..bd28ee0337521 100644 --- a/packages/react-transport-native-relay/src/ReactFlightNativeRelayServerHostConfig.js +++ b/packages/react-transport-native-relay/src/ReactFlightNativeRelayServerHostConfig.js @@ -53,14 +53,14 @@ export function processErrorChunk( message: string, stack: string, ): Chunk { - return { - type: 'error', - id: id, - json: { + return [ + 'E', + id, + { message, stack, }, - }; + ]; } function convertModelToJSON( @@ -99,11 +99,7 @@ export function processModelChunk( model: ReactModel, ): Chunk { const json = convertModelToJSON(request, {}, '', model); - return { - type: 'json', - id: id, - json: json, - }; + return ['J', id, json]; } export function processModuleChunk( @@ -112,11 +108,7 @@ export function processModuleChunk( moduleMetaData: ModuleMetaData, ): Chunk { // The moduleMetaData is already a JSON serializable value. - return { - type: 'module', - id: id, - json: moduleMetaData, - }; + return ['M', id, moduleMetaData]; } export function scheduleWork(callback: () => void) {