@samitouri / QOS-React-2 / commits / 1cf9978d89

Don't pass internals to callbacks (#21161)

I noticed that I accidentally pass the request object to public API callbacks as "this".

Sebastian Markbåge committed Apr 1, 2021 at 11:43 UTC 1cf9978d897334d09edac0782ebfb4eca4f3f406
2 files changed +12 -6
packages/react-server/src/ReactFizzServer.js
+10 -5
@@ -263,7 +263,8 @@ function createPendingSegment(
263 function reportError(request: Request, error: mixed): void {
264 // If this callback errors, we intentionally let that error bubble up to become a fatal error
265 // so that someone fixes the error reporting instead of hiding it.
266 - request.onError(error);
266 + const onError = request.onError;
267 + onError(error);
268 }
269
270 function fatalError(request: Request, error: mixed): void {
@@ -485,7 +486,8 @@ function erroredTask(
486
487 request.allPendingTasks--;
488 if (request.allPendingTasks === 0) {
488 - request.onCompleteAll();
489 + const onCompleteAll = request.onCompleteAll;
490 + onCompleteAll();
491 }
492 }
493
@@ -532,7 +534,8 @@ function abortTask(task: Task): void {
534 }
535
536 if (request.allPendingTasks === 0) {
535 - request.onCompleteAll();
537 + const onCompleteAll = request.onCompleteAll;
538 + onCompleteAll();
539 }
540 }
541 }
@@ -552,7 +555,8 @@ function finishedTask(
555 }
556 request.pendingRootTasks--;
557 if (request.pendingRootTasks === 0) {
555 - request.onReadyToStream();
558 + const onReadyToStream = request.onReadyToStream;
559 + onReadyToStream();
560 }
561 } else {
562 boundary.pendingTasks--;
@@ -593,7 +597,8 @@ function finishedTask(
597 if (request.allPendingTasks === 0) {
598 // This needs to be called at the very end so that we can synchronously write the result
599 // in the callback if needed.
596 - request.onCompleteAll();
600 + const onCompleteAll = request.onCompleteAll;
601 + onCompleteAll();
602 }
603 }
604
packages/react-server/src/ReactFlightServer.js
+2 -1
@@ -599,7 +599,8 @@ export function resolveModelToJSON(
599 }
600
601 function reportError(request: Request, error: mixed): void {
602 - request.onError(error);
602 + const onError = request.onError;
603 + onError(error);
604 }
605
606 function fatalError(request: Request, error: mixed): void {