GeezerVison is showing github.com — [Fizz/Flight] Pass in Destination lazily to startFlowing instead of i… · react/react@7843b14
File treeExpand file treeCollapse file tree Open diff view settings react-server-dom-relay/src react-server-dom-webpack/src react-server-native-relay/src
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/__tests__/ReactDOMFizzServerNode-test.js +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -154,7 +154,7 @@ describe('ReactDOMFizzServer', () => { | 154 | 154 | it('should error the stream when an error is thrown at the root', async () => { | 155 | 155 | const reportedErrors = []; | 156 | 156 | const {writable, output, completed} = getTestWritable(); | 157 | | - ReactDOMFizzServer.pipeToNodeWritable( | | 157 | + const {startWriting} = ReactDOMFizzServer.pipeToNodeWritable( | 158 | 158 | <div> | 159 | 159 | <Throw /> | 160 | 160 | </div>, | @@ -166,7 +166,8 @@ describe('ReactDOMFizzServer', () => { | 166 | 166 | }, | 167 | 167 | ); | 168 | 168 |
| 169 | | - // The stream is errored even if we haven't started writing. | | 169 | + // The stream is errored once we start writing. | | 170 | + startWriting(); | 170 | 171 |
| 171 | 172 | await completed; | 172 | 173 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/server/ReactDOMFizzServerBrowser.js +10-12Lines changed: 10 additions & 12 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -37,7 +37,15 @@ function renderToReadableStream( | 37 | 37 | children: ReactNodeList, | 38 | 38 | options?: Options, | 39 | 39 | ): ReadableStream { | 40 | | - let request; | | 40 | + const request = createRequest( | | 41 | + children, | | 42 | + createResponseState(options ? options.identifierPrefix : undefined), | | 43 | + createRootFormatContext(options ? options.namespaceURI : undefined), | | 44 | + options ? options.progressiveChunkSize : undefined, | | 45 | + options ? options.onError : undefined, | | 46 | + options ? options.onCompleteAll : undefined, | | 47 | + options ? options.onCompleteShell : undefined, | | 48 | + ); | 41 | 49 | if (options && options.signal) { | 42 | 50 | const signal = options.signal; | 43 | 51 | const listener = () => { | @@ -48,16 +56,6 @@ function renderToReadableStream( | 48 | 56 | } | 49 | 57 | const stream = new ReadableStream({ | 50 | 58 | start(controller) { | 51 | | - request = createRequest( | 52 | | - children, | 53 | | - controller, | 54 | | - createResponseState(options ? options.identifierPrefix : undefined), | 55 | | - createRootFormatContext(options ? options.namespaceURI : undefined), | 56 | | - options ? options.progressiveChunkSize : undefined, | 57 | | - options ? options.onError : undefined, | 58 | | - options ? options.onCompleteAll : undefined, | 59 | | - options ? options.onCompleteShell : undefined, | 60 | | - ); | 61 | 59 | startWork(request); | 62 | 60 | }, | 63 | 61 | pull(controller) { | @@ -66,7 +64,7 @@ function renderToReadableStream( | 66 | 64 | // is actually used by something so we can give it the best result possible | 67 | 65 | // at that point. | 68 | 66 | if (stream.locked) { | 69 | | - startFlowing(request); | | 67 | + startFlowing(request, controller); | 70 | 68 | } | 71 | 69 | }, | 72 | 70 | cancel(reason) {}, | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/server/ReactDOMFizzServerNode.js +4-9Lines changed: 4 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -25,7 +25,7 @@ import { | 25 | 25 | } from './ReactDOMServerFormatConfig'; | 26 | 26 |
| 27 | 27 | function createDrainHandler(destination, request) { | 28 | | - return () => startFlowing(request); | | 28 | + return () => startFlowing(request, destination); | 29 | 29 | } | 30 | 30 |
| 31 | 31 | type Options = {| | @@ -44,14 +44,9 @@ type Controls = {| | 44 | 44 | startWriting(): void, | 45 | 45 | |}; | 46 | 46 |
| 47 | | -function createRequestImpl( | 48 | | - children: ReactNodeList, | 49 | | - destination: Writable, | 50 | | - options: void | Options, | 51 | | -) { | | 47 | +function createRequestImpl(children: ReactNodeList, options: void | Options) { | 52 | 48 | return createRequest( | 53 | 49 | children, | 54 | | - destination, | 55 | 50 | createResponseState(options ? options.identifierPrefix : undefined), | 56 | 51 | createRootFormatContext(options ? options.namespaceURI : undefined), | 57 | 52 | options ? options.progressiveChunkSize : undefined, | @@ -66,7 +61,7 @@ function pipeToNodeWritable( | 66 | 61 | destination: Writable, | 67 | 62 | options?: Options, | 68 | 63 | ): Controls { | 69 | | - const request = createRequestImpl(children, destination, options); | | 64 | + const request = createRequestImpl(children, options); | 70 | 65 | let hasStartedFlowing = false; | 71 | 66 | startWork(request); | 72 | 67 | return { | @@ -75,7 +70,7 @@ function pipeToNodeWritable( | 75 | 70 | return; | 76 | 71 | } | 77 | 72 | hasStartedFlowing = true; | 78 | | - startFlowing(request); | | 73 | + startFlowing(request, destination); | 79 | 74 | destination.on('drain', createDrainHandler(destination, request)); | 80 | 75 | }, | 81 | 76 | abort() { | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/server/ReactDOMLegacyServerBrowser.js +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -59,7 +59,6 @@ function renderToStringImpl( | 59 | 59 | } | 60 | 60 | const request = createRequest( | 61 | 61 | children, | 62 | | - destination, | 63 | 62 | createResponseState( | 64 | 63 | generateStaticMarkup, | 65 | 64 | options ? options.identifierPrefix : undefined, | @@ -74,7 +73,7 @@ function renderToStringImpl( | 74 | 73 | // If anything suspended and is still pending, we'll abort it before writing. | 75 | 74 | // That way we write only client-rendered boundaries from the start. | 76 | 75 | abort(request); | 77 | | - startFlowing(request); | | 76 | + startFlowing(request, destination); | 78 | 77 | if (didFatal) { | 79 | 78 | throw fatalError; | 80 | 79 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/server/ReactDOMLegacyServerNode.js +2-3Lines changed: 2 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -54,7 +54,7 @@ class ReactMarkupReadableStream extends Readable { | 54 | 54 |
| 55 | 55 | _read(size) { | 56 | 56 | if (this.startedFlowing) { | 57 | | - startFlowing(this.request); | | 57 | + startFlowing(this.request, this); | 58 | 58 | } | 59 | 59 | } | 60 | 60 | } | @@ -72,12 +72,11 @@ function renderToNodeStreamImpl( | 72 | 72 | // We wait until everything has loaded before starting to write. | 73 | 73 | // That way we only end up with fully resolved HTML even if we suspend. | 74 | 74 | destination.startedFlowing = true; | 75 | | - startFlowing(request); | | 75 | + startFlowing(request, destination); | 76 | 76 | } | 77 | 77 | const destination = new ReactMarkupReadableStream(); | 78 | 78 | const request = createRequest( | 79 | 79 | children, | 80 | | - destination, | 81 | 80 | createResponseState(false, options ? options.identifierPrefix : undefined), | 82 | 81 | createRootFormatContext(), | 83 | 82 | Infinity, | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-noop-renderer/src/ReactNoopFlightServer.js +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -63,12 +63,11 @@ function render(model: ReactModel, options?: Options): Destination { | 63 | 63 | const bundlerConfig = undefined; | 64 | 64 | const request = ReactNoopFlightServer.createRequest( | 65 | 65 | model, | 66 | | - destination, | 67 | 66 | bundlerConfig, | 68 | 67 | options ? options.onError : undefined, | 69 | 68 | ); | 70 | 69 | ReactNoopFlightServer.startWork(request); | 71 | | - ReactNoopFlightServer.startFlowing(request); | | 70 | + ReactNoopFlightServer.startFlowing(request, destination); | 72 | 71 | return destination; | 73 | 72 | } | 74 | 73 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/react-noop-renderer/src/ReactNoopServer.js +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -259,7 +259,6 @@ function render(children: React$Element<any>, options?: Options): Destination { | 259 | 259 | }; | 260 | 260 | const request = ReactNoopServer.createRequest( | 261 | 261 | children, | 262 | | - destination, | 263 | 262 | null, | 264 | 263 | null, | 265 | 264 | options ? options.progressiveChunkSize : undefined, | @@ -268,7 +267,7 @@ function render(children: React$Element<any>, options?: Options): Destination { | 268 | 267 | options ? options.onCompleteShell : undefined, | 269 | 268 | ); | 270 | 269 | ReactNoopServer.startWork(request); | 271 | | - ReactNoopServer.startFlowing(request); | | 270 | + ReactNoopServer.startFlowing(request, destination); | 272 | 271 | return destination; | 273 | 272 | } | 274 | 273 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/react-server-dom-relay/src/ReactDOMServerFB.js +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -46,7 +46,6 @@ function renderToStream(children: ReactNodeList, options: Options): Stream { | 46 | 46 | }; | 47 | 47 | const request = createRequest( | 48 | 48 | children, | 49 | | - destination, | 50 | 49 | createResponseState(options ? options.identifierPrefix : undefined), | 51 | 50 | createRootFormatContext(undefined), | 52 | 51 | options ? options.progressiveChunkSize : undefined, | @@ -71,7 +70,7 @@ function abortStream(stream: Stream): void { | 71 | 70 | function renderNextChunk(stream: Stream): string { | 72 | 71 | const {request, destination} = stream; | 73 | 72 | performWork(request); | 74 | | - startFlowing(request); | | 73 | + startFlowing(request, destination); | 75 | 74 | if (destination.fatal) { | 76 | 75 | throw destination.error; | 77 | 76 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-server-dom-relay/src/ReactFlightDOMRelayServer.js +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -31,12 +31,11 @@ function render( | 31 | 31 | ): void { | 32 | 32 | const request = createRequest( | 33 | 33 | model, | 34 | | - destination, | 35 | 34 | config, | 36 | 35 | options ? options.onError : undefined, | 37 | 36 | ); | 38 | 37 | startWork(request); | 39 | | - startFlowing(request); | | 38 | + startFlowing(request, destination); | 40 | 39 | } | 41 | 40 |
| 42 | 41 | export {render}; |
Collapse file Copy file name to clipboardExpand all lines: packages/react-server-dom-webpack/src/ReactFlightDOMServerBrowser.js +6-8Lines changed: 6 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -25,15 +25,13 @@ function renderToReadableStream( | 25 | 25 | webpackMap: BundlerConfig, | 26 | 26 | options?: Options, | 27 | 27 | ): ReadableStream { | 28 | | - let request; | | 28 | + const request = createRequest( | | 29 | + model, | | 30 | + webpackMap, | | 31 | + options ? options.onError : undefined, | | 32 | + ); | 29 | 33 | const stream = new ReadableStream({ | 30 | 34 | start(controller) { | 31 | | - request = createRequest( | 32 | | - model, | 33 | | - controller, | 34 | | - webpackMap, | 35 | | - options ? options.onError : undefined, | 36 | | - ); | 37 | 35 | startWork(request); | 38 | 36 | }, | 39 | 37 | pull(controller) { | @@ -42,7 +40,7 @@ function renderToReadableStream( | 42 | 40 | // is actually used by something so we can give it the best result possible | 43 | 41 | // at that point. | 44 | 42 | if (stream.locked) { | 45 | | - startFlowing(request); | | 43 | + startFlowing(request, controller); | 46 | 44 | } | 47 | 45 | }, | 48 | 46 | cancel(reason) {}, | |
|