Skip to content

Commit 1cf9978

Browse files
authored
Don't pass internals to callbacks (#21161)
I noticed that I accidentally pass the request object to public API callbacks as "this".
1 parent a423a01 commit 1cf9978

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

packages/react-server/src/ReactFizzServer.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,8 @@ function createPendingSegment(
263263
function reportError(request: Request, error: mixed): void {
264264
// If this callback errors, we intentionally let that error bubble up to become a fatal error
265265
// so that someone fixes the error reporting instead of hiding it.
266-
request.onError(error);
266+
const onError = request.onError;
267+
onError(error);
267268
}
268269

269270
function fatalError(request: Request, error: mixed): void {
@@ -485,7 +486,8 @@ function erroredTask(
485486

486487
request.allPendingTasks--;
487488
if (request.allPendingTasks === 0) {
488-
request.onCompleteAll();
489+
const onCompleteAll = request.onCompleteAll;
490+
onCompleteAll();
489491
}
490492
}
491493

@@ -532,7 +534,8 @@ function abortTask(task: Task): void {
532534
}
533535

534536
if (request.allPendingTasks === 0) {
535-
request.onCompleteAll();
537+
const onCompleteAll = request.onCompleteAll;
538+
onCompleteAll();
536539
}
537540
}
538541
}
@@ -552,7 +555,8 @@ function finishedTask(
552555
}
553556
request.pendingRootTasks--;
554557
if (request.pendingRootTasks === 0) {
555-
request.onReadyToStream();
558+
const onReadyToStream = request.onReadyToStream;
559+
onReadyToStream();
556560
}
557561
} else {
558562
boundary.pendingTasks--;
@@ -593,7 +597,8 @@ function finishedTask(
593597
if (request.allPendingTasks === 0) {
594598
// This needs to be called at the very end so that we can synchronously write the result
595599
// in the callback if needed.
596-
request.onCompleteAll();
600+
const onCompleteAll = request.onCompleteAll;
601+
onCompleteAll();
597602
}
598603
}
599604

packages/react-server/src/ReactFlightServer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,8 @@ export function resolveModelToJSON(
599599
}
600600

601601
function reportError(request: Request, error: mixed): void {
602-
request.onError(error);
602+
const onError = request.onError;
603+
onError(error);
603604
}
604605

605606
function fatalError(request: Request, error: mixed): void {

0 commit comments

Comments
 (0)