Skip to content

Commit

Permalink
Add option to FB renderer too
Browse files Browse the repository at this point in the history
  • Loading branch information
sebmarkbage committed Oct 20, 2021
1 parent 77c41b8 commit 137a4b1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/react-server-dom-relay/src/ReactDOMServerFB.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import {

type Options = {
identifierPrefix?: string,
bootstrapScriptContent?: string,
bootstrapScripts: Array<string>,
bootstrapModules: Array<string>,
progressiveChunkSize?: number,
onError: (error: mixed) => void,
};
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ describe('ReactDOMServerFB', () => {
expect(result).toMatchInlineSnapshot(`"<div>hello world</div>"`);
});

it('should emit bootstrap script src at the end', () => {
const stream = ReactDOMServer.renderToStream(<div>hello world</div>, {
bootstrapScriptContent: 'INIT();',
bootstrapScripts: ['init.js'],
bootstrapModules: ['init.mjs'],
onError(x) {
console.error(x);
},
});
const result = readResult(stream);
expect(result).toMatchInlineSnapshot(
`"<div>hello world</div><script>INIT();</script><script src=\\"init.js\\" async=\\"\\"></script><script type=\\"module\\" src=\\"init.mjs\\" async=\\"\\"></script>"`,
);
});

it('emits all HTML as one unit if we wait until the end to start', async () => {
let hasLoaded = false;
let resolve;
Expand Down

0 comments on commit 137a4b1

Please sign in to comment.