From d7e3b866180d8d5d75c6bbc03a0b35a2a1c2d94c Mon Sep 17 00:00:00 2001 From: Sebastian Markbage Date: Mon, 29 Mar 2021 15:58:20 -0400 Subject: [PATCH] Log all errors to console.error by default --- .../src/__tests__/ReactFlight-test.js | 19 ++++++++++++++----- packages/react-server/src/ReactFizzServer.js | 6 +++++- .../react-server/src/ReactFlightServer.js | 4 +++- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/packages/react-client/src/__tests__/ReactFlight-test.js b/packages/react-client/src/__tests__/ReactFlight-test.js index e0947c68811d2..4961cbcff72a0 100644 --- a/packages/react-client/src/__tests__/ReactFlight-test.js +++ b/packages/react-client/src/__tests__/ReactFlight-test.js @@ -156,10 +156,15 @@ describe('ReactFlight', () => { return
; } - const event = ReactNoopFlightServer.render(); - const fn = ReactNoopFlightServer.render(); - const symbol = ReactNoopFlightServer.render(); - const refs = ReactNoopFlightServer.render(); + const options = { + onError() { + // ignore + }, + }; + const event = ReactNoopFlightServer.render(, options); + const fn = ReactNoopFlightServer.render(, options); + const symbol = ReactNoopFlightServer.render(, options); + const refs = ReactNoopFlightServer.render(, options); function Client({transport}) { return ReactNoopFlightClient.read(transport); @@ -213,7 +218,11 @@ describe('ReactFlight', () => { ); } - const data = ReactNoopFlightServer.render(); + const data = ReactNoopFlightServer.render(, { + onError(x) { + // ignore + }, + }); function Client({transport}) { return ReactNoopFlightClient.read(transport); diff --git a/packages/react-server/src/ReactFizzServer.js b/packages/react-server/src/ReactFizzServer.js index 739ba0c436aa6..27ff2814ac105 100644 --- a/packages/react-server/src/ReactFizzServer.js +++ b/packages/react-server/src/ReactFizzServer.js @@ -142,13 +142,17 @@ type Request = { // 500 * 1024 / 8 * .8 * 0.5 / 2 const DEFAULT_PROGRESSIVE_CHUNK_SIZE = 12800; +function defaultErrorHandler(error: mixed) { + console['error'](error); // Don't transform to our wrapper +} + export function createRequest( children: ReactNodeList, destination: Destination, responseState: ResponseState, rootContext: FormatContext, progressiveChunkSize: number = DEFAULT_PROGRESSIVE_CHUNK_SIZE, - onError: (error: mixed) => void = noop, + onError: (error: mixed) => void = defaultErrorHandler, onCompleteAll: () => void = noop, onReadyToStream: () => void = noop, ): Request { diff --git a/packages/react-server/src/ReactFlightServer.js b/packages/react-server/src/ReactFlightServer.js index 2a09e21c89a00..d4fa3bd0623cd 100644 --- a/packages/react-server/src/ReactFlightServer.js +++ b/packages/react-server/src/ReactFlightServer.js @@ -91,7 +91,9 @@ export type Request = { const ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher; -function defaultErrorHandler() {} +function defaultErrorHandler(error: mixed) { + console['error'](error); // Don't transform to our wrapper +} export function createRequest( model: ReactModel,