Files
react/packages/react-server-dom-fb/src/ReactFlightDOMServerFB.js
T
Andrey Lunyov c17a27ef49 FB-specific builds of Flight Server, Flight Client, and React Shared Subset (#27579)
This PR adds a new FB-specific configuration of Flight. We also need to
bundle a version of ReactSharedSubset that will be used for running
Flight on the server.

This initial implementation does not support server actions yet.

The FB-Flight still uses the text protocol on the server (the flag
`enableBinaryFlight` is set to false). It looks like we need some
changes in Hermes to properly support this binary format.
2023-11-27 18:34:58 -05:00

69 lines
1.6 KiB
JavaScript

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
import type {ReactClientValue} from 'react-server/src/ReactFlightServer';
import type {
Destination,
Chunk,
PrecomputedChunk,
} from 'react-server/src/ReactServerStreamConfig';
import type {ClientManifest} from './ReactFlightReferencesFB';
import {
createRequest,
startWork,
startFlowing,
} from 'react-server/src/ReactFlightServer';
import {setByteLengthOfChunkImplementation} from 'react-server/src/ReactServerStreamConfig';
export {
registerClientReference,
registerServerReference,
getRequestedClientReferencesKeys,
clearRequestedClientReferencesKeysSet,
} from './ReactFlightReferencesFB';
type Options = {
onError?: (error: mixed) => void,
};
function renderToDestination(
destination: Destination,
model: ReactClientValue,
bundlerConfig: ClientManifest,
options?: Options,
): void {
if (!configured) {
throw new Error(
'Please make sure to call `setConfig(...)` before calling `renderToDestination`.',
);
}
const request = createRequest(
model,
bundlerConfig,
options ? options.onError : undefined,
);
startWork(request);
startFlowing(request, destination);
}
type Config = {
byteLength: (chunk: Chunk | PrecomputedChunk) => number,
};
let configured = false;
function setConfig(config: Config): void {
setByteLengthOfChunkImplementation(config.byteLength);
configured = true;
}
export {renderToDestination, setConfig};