Skip to content

Commit

Permalink
Don't pass internals to callbacks (#21161)
Browse files Browse the repository at this point in the history
I noticed that I accidentally pass the request object to public API callbacks
as "this".
  • Loading branch information
sebmarkbage authored Apr 1, 2021
1 parent a423a01 commit 1cf9978
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
15 changes: 10 additions & 5 deletions packages/react-server/src/ReactFizzServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -485,7 +486,8 @@ function erroredTask(

request.allPendingTasks--;
if (request.allPendingTasks === 0) {
request.onCompleteAll();
const onCompleteAll = request.onCompleteAll;
onCompleteAll();
}
}

Expand Down Expand Up @@ -532,7 +534,8 @@ function abortTask(task: Task): void {
}

if (request.allPendingTasks === 0) {
request.onCompleteAll();
const onCompleteAll = request.onCompleteAll;
onCompleteAll();
}
}
}
Expand All @@ -552,7 +555,8 @@ function finishedTask(
}
request.pendingRootTasks--;
if (request.pendingRootTasks === 0) {
request.onReadyToStream();
const onReadyToStream = request.onReadyToStream;
onReadyToStream();
}
} else {
boundary.pendingTasks--;
Expand Down Expand Up @@ -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();
}
}

Expand Down
3 changes: 2 additions & 1 deletion packages/react-server/src/ReactFlightServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 1cf9978

Please sign in to comment.