Skip to content

Commit

Permalink
[Fizz/Flight] Don't use default args (#21681)
Browse files Browse the repository at this point in the history
* Don't use default args

* Hoist out creation for better inlining

The closures prevent inlining otherwise.
  • Loading branch information
sebmarkbage committed Jun 14, 2021
1 parent bd45ad0 commit 502f8a2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
16 changes: 12 additions & 4 deletions packages/react-dom/src/server/ReactDOMFizzServerNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ type Controls = {|
startWriting(): void,
|};

function pipeToNodeWritable(
function createRequestImpl(
children: ReactNodeList,
destination: Writable,
options?: Options,
): Controls {
const request = createRequest(
options: void | Options,
) {
return createRequest(
children,
destination,
createResponseState(options ? options.identifierPrefix : undefined),
Expand All @@ -57,6 +57,14 @@ function pipeToNodeWritable(
options ? options.onCompleteAll : undefined,
options ? options.onReadyToStream : undefined,
);
}

function pipeToNodeWritable(
children: ReactNodeList,
destination: Writable,
options?: Options,
): Controls {
const request = createRequestImpl(children, destination, options);
let hasStartedFlowing = false;
startWork(request);
return {
Expand Down
19 changes: 11 additions & 8 deletions packages/react-server/src/ReactFizzServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,17 +222,20 @@ export function createRequest(
destination: Destination,
responseState: ResponseState,
rootFormatContext: FormatContext,
progressiveChunkSize: number = DEFAULT_PROGRESSIVE_CHUNK_SIZE,
onError: (error: mixed) => void = defaultErrorHandler,
onCompleteAll: () => void = noop,
onReadyToStream: () => void = noop,
progressiveChunkSize: void | number,
onError: void | ((error: mixed) => void),
onCompleteAll: void | (() => void),
onReadyToStream: void | (() => void),
): Request {
const pingedTasks = [];
const abortSet: Set<Task> = new Set();
const request = {
destination,
responseState,
progressiveChunkSize,
progressiveChunkSize:
progressiveChunkSize === undefined
? DEFAULT_PROGRESSIVE_CHUNK_SIZE
: progressiveChunkSize,
status: BUFFERING,
nextSegmentId: 0,
allPendingTasks: 0,
Expand All @@ -243,9 +246,9 @@ export function createRequest(
clientRenderedBoundaries: [],
completedBoundaries: [],
partialBoundaries: [],
onError,
onCompleteAll,
onReadyToStream,
onError: onError === undefined ? defaultErrorHandler : onError,
onCompleteAll: onCompleteAll === undefined ? noop : onCompleteAll,
onReadyToStream: onReadyToStream === undefined ? noop : onReadyToStream,
};
// This segment represents the root fallback.
const rootSegment = createPendingSegment(request, 0, null, rootFormatContext);
Expand Down
4 changes: 2 additions & 2 deletions packages/react-server/src/ReactFlightServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export function createRequest(
model: ReactModel,
destination: Destination,
bundlerConfig: BundlerConfig,
onError: (error: mixed) => void = defaultErrorHandler,
onError: void | ((error: mixed) => void),
): Request {
const pingedSegments = [];
const request = {
Expand All @@ -113,7 +113,7 @@ export function createRequest(
completedErrorChunks: [],
writtenSymbols: new Map(),
writtenModules: new Map(),
onError,
onError: onError === undefined ? defaultErrorHandler : onError,
flowing: false,
toJSON: function(key: string, value: ReactModel): ReactJSONValue {
return resolveModelToJSON(request, this, key, value);
Expand Down

0 comments on commit 502f8a2

Please sign in to comment.