Skip to content

Commit 522f473

Browse files
authored
Move the Error creation to be lazy (#24728)
Creating an Error captures a stack trace which can be somewhat expensive. We shouldn't do tthat always for every render. This also ensures that the stack trace is more useful because you can follow through the Node.js code to see the cause.
1 parent 256aefb commit 522f473

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

packages/react-dom/src/server/ReactDOMFizzServerNode.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ function createDrainHandler(destination, request) {
2929
}
3030

3131
function createAbortHandler(request, reason) {
32-
return () => abort(request, reason);
32+
// eslint-disable-next-line react-internal/prod-error-codes
33+
return () => abort(request, new Error(reason));
3334
}
3435

3536
type Options = {|
@@ -49,7 +50,7 @@ type Options = {|
4950
type PipeableStream = {|
5051
// Cancel any pending I/O and put anything remaining into
5152
// client rendered mode.
52-
abort(): void,
53+
abort(reason: mixed): void,
5354
pipe<T: Writable>(destination: T): T,
5455
|};
5556

@@ -94,21 +95,16 @@ function renderToPipeableStream(
9495
'error',
9596
createAbortHandler(
9697
request,
97-
// eslint-disable-next-line react-internal/prod-error-codes
98-
new Error('The destination stream errored while writing data.'),
98+
'The destination stream errored while writing data.',
9999
),
100100
);
101101
destination.on(
102102
'close',
103-
createAbortHandler(
104-
request,
105-
// eslint-disable-next-line react-internal/prod-error-codes
106-
new Error('The destination stream closed early.'),
107-
),
103+
createAbortHandler(request, 'The destination stream closed early.'),
108104
);
109105
return destination;
110106
},
111-
abort(reason) {
107+
abort(reason: mixed) {
112108
abort(request, reason);
113109
},
114110
};

0 commit comments

Comments
 (0)