mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
629541bcc0
A Flight Server can be a consumer of a stream from another Server. In this case the meta data is attached to debugInfo properties on lazy, Promises, Arrays or Elements that might in turn get forwarded to the next stream. In this case we want to forward this debug information to the client in the stream. I also added a DEV only `environmentName` option to the Flight Server. This lets you name the server that is producing the debug info so that you can trace the origin of where that component is executing. This defaults to `"server"`. DevTools could use this for badges or different colors.
74 lines
1.7 KiB
JavaScript
74 lines
1.7 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 {setCheckIsClientReference} from './ReactFlightReferencesFB';
|
|
|
|
import {
|
|
createRequest,
|
|
startWork,
|
|
startFlowing,
|
|
} from 'react-server/src/ReactFlightServer';
|
|
|
|
import {setByteLengthOfChunkImplementation} from 'react-server/src/ReactServerStreamConfig';
|
|
|
|
export {
|
|
registerClientReference,
|
|
registerServerReference,
|
|
getRequestedClientReferencesKeys,
|
|
clearRequestedClientReferencesKeysSet,
|
|
setCheckIsClientReference,
|
|
} from './ReactFlightReferencesFB';
|
|
|
|
type Options = {
|
|
onError?: (error: mixed) => void,
|
|
};
|
|
|
|
function renderToDestination(
|
|
destination: Destination,
|
|
model: ReactClientValue,
|
|
options?: Options,
|
|
): void {
|
|
if (!configured) {
|
|
throw new Error(
|
|
'Please make sure to call `setConfig(...)` before calling `renderToDestination`.',
|
|
);
|
|
}
|
|
const request = createRequest(
|
|
model,
|
|
null,
|
|
options ? options.onError : undefined,
|
|
undefined,
|
|
undefined,
|
|
);
|
|
startWork(request);
|
|
startFlowing(request, destination);
|
|
}
|
|
|
|
type Config = {
|
|
byteLength: (chunk: Chunk | PrecomputedChunk) => number,
|
|
isClientReference: (reference: mixed) => boolean,
|
|
};
|
|
|
|
let configured = false;
|
|
|
|
function setConfig(config: Config): void {
|
|
setByteLengthOfChunkImplementation(config.byteLength);
|
|
setCheckIsClientReference(config.isClientReference);
|
|
configured = true;
|
|
}
|
|
|
|
export {renderToDestination, setConfig};
|