Files
react/packages/react-server-dom-webpack/src/ReactFlightDOMServerNode.js
Sebastian Markbåge d1294c9d40 [Flight] Add global onError handler (#21129)
* 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
2021-03-29 19:36:16 -07:00

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};