Skip to content

Commit 502f8a2

Browse files
authored
[Fizz/Flight] Don't use default args (#21681)
* Don't use default args * Hoist out creation for better inlining The closures prevent inlining otherwise.
1 parent bd45ad0 commit 502f8a2

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ type Controls = {|
4242
startWriting(): void,
4343
|};
4444

45-
function pipeToNodeWritable(
45+
function createRequestImpl(
4646
children: ReactNodeList,
4747
destination: Writable,
48-
options?: Options,
49-
): Controls {
50-
const request = createRequest(
48+
options: void | Options,
49+
) {
50+
return createRequest(
5151
children,
5252
destination,
5353
createResponseState(options ? options.identifierPrefix : undefined),
@@ -57,6 +57,14 @@ function pipeToNodeWritable(
5757
options ? options.onCompleteAll : undefined,
5858
options ? options.onReadyToStream : undefined,
5959
);
60+
}
61+
62+
function pipeToNodeWritable(
63+
children: ReactNodeList,
64+
destination: Writable,
65+
options?: Options,
66+
): Controls {
67+
const request = createRequestImpl(children, destination, options);
6068
let hasStartedFlowing = false;
6169
startWork(request);
6270
return {

packages/react-server/src/ReactFizzServer.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -222,17 +222,20 @@ export function createRequest(
222222
destination: Destination,
223223
responseState: ResponseState,
224224
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),
229229
): Request {
230230
const pingedTasks = [];
231231
const abortSet: Set<Task> = new Set();
232232
const request = {
233233
destination,
234234
responseState,
235-
progressiveChunkSize,
235+
progressiveChunkSize:
236+
progressiveChunkSize === undefined
237+
? DEFAULT_PROGRESSIVE_CHUNK_SIZE
238+
: progressiveChunkSize,
236239
status: BUFFERING,
237240
nextSegmentId: 0,
238241
allPendingTasks: 0,
@@ -243,9 +246,9 @@ export function createRequest(
243246
clientRenderedBoundaries: [],
244247
completedBoundaries: [],
245248
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,
249252
};
250253
// This segment represents the root fallback.
251254
const rootSegment = createPendingSegment(request, 0, null, rootFormatContext);

packages/react-server/src/ReactFlightServer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export function createRequest(
9898
model: ReactModel,
9999
destination: Destination,
100100
bundlerConfig: BundlerConfig,
101-
onError: (error: mixed) => void = defaultErrorHandler,
101+
onError: void | ((error: mixed) => void),
102102
): Request {
103103
const pingedSegments = [];
104104
const request = {
@@ -113,7 +113,7 @@ export function createRequest(
113113
completedErrorChunks: [],
114114
writtenSymbols: new Map(),
115115
writtenModules: new Map(),
116-
onError,
116+
onError: onError === undefined ? defaultErrorHandler : onError,
117117
flowing: false,
118118
toJSON: function(key: string, value: ReactModel): ReactJSONValue {
119119
return resolveModelToJSON(request, this, key, value);

0 commit comments

Comments
 (0)