( children: ReactNodeList, postponedState: PostponedState, options?: WebStreamsResumeOptions, )
| 368 | > & {signal: AbortSignal}; |
| 369 | |
| 370 | function resume( |
| 371 | children: ReactNodeList, |
| 372 | postponedState: PostponedState, |
| 373 | options?: WebStreamsResumeOptions, |
| 374 | ): Promise<ReactDOMServerReadableStream> { |
| 375 | return new Promise((resolve, reject) => { |
| 376 | let onFatalError; |
| 377 | let onAllReady; |
| 378 | const allReady = new Promise<void>((res, rej) => { |
| 379 | onAllReady = res; |
| 380 | onFatalError = rej; |
| 381 | }); |
| 382 | |
| 383 | function onShellReady() { |
| 384 | let writable: Writable; |
| 385 | const stream: ReactDOMServerReadableStream = (new ReadableStream( |
| 386 | { |
| 387 | type: 'bytes', |
| 388 | start: (controller): ?Promise<void> => { |
| 389 | writable = |
| 390 | createFakeWritableFromReadableStreamController(controller); |
| 391 | }, |
| 392 | pull: (controller): ?Promise<void> => { |
| 393 | startFlowing(request, writable); |
| 394 | }, |
| 395 | cancel: (reason): ?Promise<void> => { |
| 396 | stopFlowing(request); |
| 397 | abort(request, reason); |
| 398 | }, |
| 399 | }, |
| 400 | // $FlowFixMe[prop-missing] size() methods are not allowed on byte streams. |
| 401 | {highWaterMark: 0}, |
| 402 | ): any); |
| 403 | // TODO: Move to sub-classing ReadableStream. |
| 404 | stream.allReady = allReady; |
| 405 | resolve(stream); |
| 406 | } |
| 407 | function onShellError(error: mixed) { |
| 408 | // If the shell errors the caller of `renderToReadableStream` won't have access to `allReady`. |
| 409 | // However, `allReady` will be rejected by `onFatalError` as well. |
| 410 | // So we need to catch the duplicate, uncatchable fatal error in `allReady` to prevent a `UnhandledPromiseRejection`. |
| 411 | allReady.catch(() => {}); |
| 412 | reject(error); |
| 413 | } |
| 414 | const request = resumeRequest( |
| 415 | children, |
| 416 | postponedState, |
| 417 | resumeRenderState( |
| 418 | postponedState.resumableState, |
| 419 | options ? options.nonce : undefined, |
| 420 | ), |
| 421 | options ? options.onError : undefined, |
| 422 | onAllReady, |
| 423 | onShellReady, |
| 424 | onShellError, |
| 425 | onFatalError, |
| 426 | options ? options.onPostpone : undefined, |
| 427 | ); |
nothing calls this directly
no test coverage detected