[Fizz/Flight] Don't use default args (#21681)
* Don't use default args * Hoist out creation for better inlining The closures prevent inlining otherwise.
Sebastian Markbåge committed
Jun 14, 2021 at 18:28 UTC
502f8a2a07bb8e8923ead71166fbe599f94a42ae
3 files changed
+25
-14
packages/react-dom/src/server/ReactDOMFizzServerNode.js
+12
-4
@@ -42,12 +42,12 @@ type Controls = {|
42
startWriting(): void,
43
|};
44
45
-function pipeToNodeWritable(
45
+function createRequestImpl(
46
children: ReactNodeList,
47
destination: Writable,
48
- options?: Options,
49
-): Controls {
50
- const request = createRequest(
48
+ options: void | Options,
49
+) {
50
+ return createRequest(
51
children,
52
destination,
53
createResponseState(options ? options.identifierPrefix : undefined),
@@ -57,6 +57,14 @@ function pipeToNodeWritable(
57
options ? options.onCompleteAll : undefined,
58
options ? options.onReadyToStream : undefined,
59
);
60
+}
61
+
62
+function pipeToNodeWritable(
63
+ children: ReactNodeList,
64
+ destination: Writable,
65
+ options?: Options,
66
+): Controls {
67
+ const request = createRequestImpl(children, destination, options);
68
let hasStartedFlowing = false;
69
startWork(request);
70
return {
packages/react-server/src/ReactFizzServer.js
+11
-8
@@ -222,17 +222,20 @@ export function createRequest(
222
destination: Destination,
223
responseState: ResponseState,
224
rootFormatContext: FormatContext,
225
- progressiveChunkSize: number = DEFAULT_PROGRESSIVE_CHUNK_SIZE,
226
- onError: (error: mixed) => void = defaultErrorHandler,
227
- onCompleteAll: () => void = noop,
228
- onReadyToStream: () => void = noop,
225
+ progressiveChunkSize: void | number,
226
+ onError: void | ((error: mixed) => void),
227
+ onCompleteAll: void | (() => void),
228
+ onReadyToStream: void | (() => void),
229
): Request {
230
const pingedTasks = [];
231
const abortSet: Set<Task> = new Set();
232
const request = {
233
destination,
234
responseState,
235
- progressiveChunkSize,
235
+ progressiveChunkSize:
236
+ progressiveChunkSize === undefined
237
+ ? DEFAULT_PROGRESSIVE_CHUNK_SIZE
238
+ : progressiveChunkSize,
239
status: BUFFERING,
240
nextSegmentId: 0,
241
allPendingTasks: 0,
@@ -243,9 +246,9 @@ export function createRequest(
246
clientRenderedBoundaries: [],
247
completedBoundaries: [],
248
partialBoundaries: [],
246
- onError,
247
- onCompleteAll,
248
- onReadyToStream,
249
+ onError: onError === undefined ? defaultErrorHandler : onError,
250
+ onCompleteAll: onCompleteAll === undefined ? noop : onCompleteAll,
251
+ onReadyToStream: onReadyToStream === undefined ? noop : onReadyToStream,
252
};
253
// This segment represents the root fallback.
254
const rootSegment = createPendingSegment(request, 0, null, rootFormatContext);
packages/react-server/src/ReactFlightServer.js
+2
-2
@@ -98,7 +98,7 @@ export function createRequest(
98
model: ReactModel,
99
destination: Destination,
100
bundlerConfig: BundlerConfig,
101
- onError: (error: mixed) => void = defaultErrorHandler,
101
+ onError: void | ((error: mixed) => void),
102
): Request {
103
const pingedSegments = [];
104
const request = {
@@ -113,7 +113,7 @@ export function createRequest(
113
completedErrorChunks: [],
114
writtenSymbols: new Map(),
115
writtenModules: new Map(),
116
- onError,
116
+ onError: onError === undefined ? defaultErrorHandler : onError,
117
flowing: false,
118
toJSON: function(key: string, value: ReactModel): ReactJSONValue {
119
return resolveModelToJSON(request, this, key, value);