mirror of
https://github.com/facebook/react.git
synced 2026-02-26 02:25:04 +00:00
* Add onError option to Flight Server The callback is called any time an error is generated in a server component. This allows it to be logged on a server if needed. It'll still be rethrown on the client so it can be logged there too but in case it never reaches the client, here's a way to make sure it doesn't get lost. * Add fatal error handling
45 lines
1019 B
JavaScript
45 lines
1019 B
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its 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 {ReactModel} from 'react-server/src/ReactFlightServer';
|
|
import type {BundlerConfig} from './ReactFlightServerWebpackBundlerConfig';
|
|
import type {Writable} from 'stream';
|
|
|
|
import {
|
|
createRequest,
|
|
startWork,
|
|
startFlowing,
|
|
} from 'react-server/src/ReactFlightServer';
|
|
|
|
function createDrainHandler(destination, request) {
|
|
return () => startFlowing(request);
|
|
}
|
|
|
|
type Options = {
|
|
onError?: (error: mixed) => void,
|
|
};
|
|
|
|
function pipeToNodeWritable(
|
|
model: ReactModel,
|
|
destination: Writable,
|
|
webpackMap: BundlerConfig,
|
|
options?: Options,
|
|
): void {
|
|
const request = createRequest(
|
|
model,
|
|
destination,
|
|
webpackMap,
|
|
options ? options.onError : undefined,
|
|
);
|
|
destination.on('drain', createDrainHandler(destination, request));
|
|
startWork(request);
|
|
}
|
|
|
|
export {pipeToNodeWritable};
|