( children: ReactNodeList, postponedState: PostponedState, options?: ResumeOptions, )
| 170 | } |
| 171 | |
| 172 | function resume( |
| 173 | children: ReactNodeList, |
| 174 | postponedState: PostponedState, |
| 175 | options?: ResumeOptions, |
| 176 | ): Promise<ReactDOMServerReadableStream> { |
| 177 | return new Promise((resolve, reject) => { |
| 178 | let onFatalError; |
| 179 | let onAllReady; |
| 180 | const allReady = new Promise<void>((res, rej) => { |
| 181 | onAllReady = res; |
| 182 | onFatalError = rej; |
| 183 | }); |
| 184 | |
| 185 | function onShellReady() { |
| 186 | const stream: ReactDOMServerReadableStream = (new ReadableStream( |
| 187 | { |
| 188 | type: 'bytes', |
| 189 | pull: (controller): ?Promise<void> => { |
| 190 | startFlowing(request, controller); |
| 191 | }, |
| 192 | cancel: (reason): ?Promise<void> => { |
| 193 | stopFlowing(request); |
| 194 | abort(request, reason); |
| 195 | }, |
| 196 | }, |
| 197 | // $FlowFixMe[prop-missing] size() methods are not allowed on byte streams. |
| 198 | {highWaterMark: 0}, |
| 199 | ): any); |
| 200 | // TODO: Move to sub-classing ReadableStream. |
| 201 | stream.allReady = allReady; |
| 202 | resolve(stream); |
| 203 | } |
| 204 | function onShellError(error: mixed) { |
| 205 | // If the shell errors the caller of `renderToReadableStream` won't have access to `allReady`. |
| 206 | // However, `allReady` will be rejected by `onFatalError` as well. |
| 207 | // So we need to catch the duplicate, uncatchable fatal error in `allReady` to prevent a `UnhandledPromiseRejection`. |
| 208 | allReady.catch(() => {}); |
| 209 | reject(error); |
| 210 | } |
| 211 | const request = resumeRequest( |
| 212 | children, |
| 213 | postponedState, |
| 214 | resumeRenderState( |
| 215 | postponedState.resumableState, |
| 216 | options ? options.nonce : undefined, |
| 217 | ), |
| 218 | options ? options.onError : undefined, |
| 219 | onAllReady, |
| 220 | onShellReady, |
| 221 | onShellError, |
| 222 | onFatalError, |
| 223 | options ? options.onPostpone : undefined, |
| 224 | ); |
| 225 | if (options && options.signal) { |
| 226 | const signal = options.signal; |
| 227 | if (signal.aborted) { |
| 228 | abort(request, (signal: any).reason); |
| 229 | } else { |
nothing calls this directly
no test coverage detected