From 3947db0d9df62e2ad41224376a2735d92d61c1a4 Mon Sep 17 00:00:00 2001 From: Sebastian Markbage Date: Thu, 1 Apr 2021 11:35:16 -0400 Subject: [PATCH] Don't pass internals to callbacks I noticed that I accidentally pass the request object to public API callbacks as "this". --- packages/react-server/src/ReactFizzServer.js | 15 ++++++++++----- packages/react-server/src/ReactFlightServer.js | 3 ++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/react-server/src/ReactFizzServer.js b/packages/react-server/src/ReactFizzServer.js index df5d4858bc6f9..66a6c9238ab30 100644 --- a/packages/react-server/src/ReactFizzServer.js +++ b/packages/react-server/src/ReactFizzServer.js @@ -263,7 +263,8 @@ function createPendingSegment( function reportError(request: Request, error: mixed): void { // If this callback errors, we intentionally let that error bubble up to become a fatal error // so that someone fixes the error reporting instead of hiding it. - request.onError(error); + const onError = request.onError; + onError(error); } function fatalError(request: Request, error: mixed): void { @@ -485,7 +486,8 @@ function erroredTask( request.allPendingTasks--; if (request.allPendingTasks === 0) { - request.onCompleteAll(); + const onCompleteAll = request.onCompleteAll; + onCompleteAll(); } } @@ -532,7 +534,8 @@ function abortTask(task: Task): void { } if (request.allPendingTasks === 0) { - request.onCompleteAll(); + const onCompleteAll = request.onCompleteAll; + onCompleteAll(); } } } @@ -552,7 +555,8 @@ function finishedTask( } request.pendingRootTasks--; if (request.pendingRootTasks === 0) { - request.onReadyToStream(); + const onReadyToStream = request.onReadyToStream; + onReadyToStream(); } } else { boundary.pendingTasks--; @@ -593,7 +597,8 @@ function finishedTask( if (request.allPendingTasks === 0) { // This needs to be called at the very end so that we can synchronously write the result // in the callback if needed. - request.onCompleteAll(); + const onCompleteAll = request.onCompleteAll; + onCompleteAll(); } } diff --git a/packages/react-server/src/ReactFlightServer.js b/packages/react-server/src/ReactFlightServer.js index d4fa3bd0623cd..dfbe3c55f9b64 100644 --- a/packages/react-server/src/ReactFlightServer.js +++ b/packages/react-server/src/ReactFlightServer.js @@ -599,7 +599,8 @@ export function resolveModelToJSON( } function reportError(request: Request, error: mixed): void { - request.onError(error); + const onError = request.onError; + onError(error); } function fatalError(request: Request, error: mixed): void {