From 137a4b1d7f3c95c2d59768a5569493bde0d2854d Mon Sep 17 00:00:00 2001 From: Sebastian Markbage Date: Tue, 19 Oct 2021 22:18:28 -0400 Subject: [PATCH] Add option to FB renderer too --- .../src/ReactDOMServerFB.js | 11 ++++++++++- .../__tests__/ReactDOMServerFB-test.internal.js | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/packages/react-server-dom-relay/src/ReactDOMServerFB.js b/packages/react-server-dom-relay/src/ReactDOMServerFB.js index b5b6ba84e77d4..35a8143125d74 100644 --- a/packages/react-server-dom-relay/src/ReactDOMServerFB.js +++ b/packages/react-server-dom-relay/src/ReactDOMServerFB.js @@ -28,6 +28,9 @@ import { type Options = { identifierPrefix?: string, + bootstrapScriptContent?: string, + bootstrapScripts: Array, + bootstrapModules: Array, progressiveChunkSize?: number, onError: (error: mixed) => void, }; @@ -46,7 +49,13 @@ function renderToStream(children: ReactNodeList, options: Options): Stream { }; const request = createRequest( children, - createResponseState(options ? options.identifierPrefix : undefined), + createResponseState( + options ? options.identifierPrefix : undefined, + undefined, + options ? options.bootstrapScriptContent : undefined, + options ? options.bootstrapScripts : undefined, + options ? options.bootstrapModules : undefined, + ), createRootFormatContext(undefined), options ? options.progressiveChunkSize : undefined, options.onError, diff --git a/packages/react-server-dom-relay/src/__tests__/ReactDOMServerFB-test.internal.js b/packages/react-server-dom-relay/src/__tests__/ReactDOMServerFB-test.internal.js index 4cf8bb8f7bf66..7444ae6f90934 100644 --- a/packages/react-server-dom-relay/src/__tests__/ReactDOMServerFB-test.internal.js +++ b/packages/react-server-dom-relay/src/__tests__/ReactDOMServerFB-test.internal.js @@ -48,6 +48,21 @@ describe('ReactDOMServerFB', () => { expect(result).toMatchInlineSnapshot(`"
hello world
"`); }); + it('should emit bootstrap script src at the end', () => { + const stream = ReactDOMServer.renderToStream(
hello world
, { + bootstrapScriptContent: 'INIT();', + bootstrapScripts: ['init.js'], + bootstrapModules: ['init.mjs'], + onError(x) { + console.error(x); + }, + }); + const result = readResult(stream); + expect(result).toMatchInlineSnapshot( + `"
hello world
"`, + ); + }); + it('emits all HTML as one unit if we wait until the end to start', async () => { let hasLoaded = false; let resolve;