237
componentStack: null | ComponentStackNode, // stack frame description of the currently rendering component
238
thenableState: null | ThenableState,
239
isFallback: boolean, // whether this task is rendering inside a fallback tree
240
+ // DON'T ANY MORE FIELDS. We at 16 already which otherwise requires converting to a constructor.
241
+ // Consider splitting into multiple objects or consolidating some fields.
242
};
243
244
type ReplaySet = {
266
componentStack: null | ComponentStackNode, // stack frame description of the currently rendering component
267
thenableState: null | ThenableState,
268
isFallback: boolean, // whether this task is rendering inside a fallback tree
269
+ // DON'T ANY MORE FIELDS. We at 16 already which otherwise requires converting to a constructor.
270
+ // Consider splitting into multiple objects or consolidating some fields.
271
};
272
273
export type Task = RenderTask | ReplayTask;
369
370
function noop(): void {}
371
368
-export function createRequest(
372
+function RequestInstance(
373
+ this: $FlowFixMe,
374
children: ReactNodeList,
375
resumableState: ResumableState,
376
renderState: RenderState,
383
onFatalError: void | ((error: mixed) => void),
384
onPostpone: void | ((reason: string, postponeInfo: PostponeInfo) => void),
385
formState: void | null | ReactFormState<any, any>,
381
-): Request {
386
+) {
387
const pingedTasks: Array<Task> = [];
388
const abortSet: Set<Task> = new Set();
384
- const request: Request = {
385
- destination: null,
386
- flushScheduled: false,
387
- resumableState,
388
- renderState,
389
- rootFormatContext,
390
- progressiveChunkSize:
391
- progressiveChunkSize === undefined
392
- ? DEFAULT_PROGRESSIVE_CHUNK_SIZE
393
- : progressiveChunkSize,
394
- status: OPEN,
395
- fatalError: null,
396
- nextSegmentId: 0,
397
- allPendingTasks: 0,
398
- pendingRootTasks: 0,
399
- completedRootSegment: null,
400
- abortableTasks: abortSet,
401
- pingedTasks: pingedTasks,
402
- clientRenderedBoundaries: ([]: Array<SuspenseBoundary>),
403
- completedBoundaries: ([]: Array<SuspenseBoundary>),
404
- partialBoundaries: ([]: Array<SuspenseBoundary>),
405
- trackedPostpones: null,
406
- onError: onError === undefined ? defaultErrorHandler : onError,
407
- onPostpone: onPostpone === undefined ? noop : onPostpone,
408
- onAllReady: onAllReady === undefined ? noop : onAllReady,
409
- onShellReady: onShellReady === undefined ? noop : onShellReady,
410
- onShellError: onShellError === undefined ? noop : onShellError,
411
- onFatalError: onFatalError === undefined ? noop : onFatalError,
412
- formState: formState === undefined ? null : formState,
413
- };
389
+ this.destination = null;
390
+ this.flushScheduled = false;
391
+ this.resumableState = resumableState;
392
+ this.renderState = renderState;
393
+ this.rootFormatContext = rootFormatContext;
394
+ this.progressiveChunkSize =
395
+ progressiveChunkSize === undefined
396
+ ? DEFAULT_PROGRESSIVE_CHUNK_SIZE
397
+ : progressiveChunkSize;
398
+ this.status = OPEN;
399
+ this.fatalError = null;
400
+ this.nextSegmentId = 0;
401
+ this.allPendingTasks = 0;
402
+ this.pendingRootTasks = 0;
403
+ this.completedRootSegment = null;
404
+ this.abortableTasks = abortSet;
405
+ this.pingedTasks = pingedTasks;
406
+ this.clientRenderedBoundaries = ([]: Array<SuspenseBoundary>);
407
+ this.completedBoundaries = ([]: Array<SuspenseBoundary>);
408
+ this.partialBoundaries = ([]: Array<SuspenseBoundary>);
409
+ this.trackedPostpones = null;
410
+ this.onError = onError === undefined ? defaultErrorHandler : onError;
411
+ this.onPostpone = onPostpone === undefined ? noop : onPostpone;
412
+ this.onAllReady = onAllReady === undefined ? noop : onAllReady;
413
+ this.onShellReady = onShellReady === undefined ? noop : onShellReady;
414
+ this.onShellError = onShellError === undefined ? noop : onShellError;
415
+ this.onFatalError = onFatalError === undefined ? noop : onFatalError;
416
+ this.formState = formState === undefined ? null : formState;
417
if (__DEV__) {
415
- request.didWarnForKey = null;
418
+ this.didWarnForKey = null;
419
}
420
// This segment represents the root fallback.
421
const rootSegment = createPendingSegment(
419
- request,
422
+ this,
423
0,
424
null,
425
rootFormatContext,
430
// There is no parent so conceptually, we're unblocked to flush this segment.
431
rootSegment.parentFlushed = true;
432
const rootTask = createRenderTask(
430
- request,
433
+ this,
434
null,
435
children,
436
-1,
447
false,
448
);
449
pingedTasks.push(rootTask);
447
- return request;
450
+}
451
+
452
+export function createRequest(
453
+ children: ReactNodeList,
454
+ resumableState: ResumableState,
455
+ renderState: RenderState,
456
+ rootFormatContext: FormatContext,
457
+ progressiveChunkSize: void | number,
458
+ onError: void | ((error: mixed, errorInfo: ErrorInfo) => ?string),
459
+ onAllReady: void | (() => void),
460
+ onShellReady: void | (() => void),
461
+ onShellError: void | ((error: mixed) => void),
462
+ onFatalError: void | ((error: mixed) => void),
463
+ onPostpone: void | ((reason: string, postponeInfo: PostponeInfo) => void),
464
+ formState: void | null | ReactFormState<any, any>,
465
+): Request {
466
+ // $FlowFixMe[invalid-constructor]: the shapes are exact here but Flow doesn't like constructors
467
+ return new RequestInstance(
468
+ children,
469
+ resumableState,
470
+ renderState,
471
+ rootFormatContext,
472
+ progressiveChunkSize,
473
+ onError,
474
+ onAllReady,
475
+ onShellReady,
476
+ onShellError,
477
+ onFatalError,
478
+ onPostpone,
479
+ formState,
480
+ );
481
}
482
483
export function createPrerenderRequest(