Skip to content

Commit b4d79d4

Browse files
committed
Add option to FB renderer too
1 parent 0a7455e commit b4d79d4

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

packages/react-server-dom-relay/src/ReactDOMServerFB.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ import {
2828

2929
type Options = {
3030
identifierPrefix?: string,
31+
bootstrapScriptContent?: string,
32+
bootstrapScripts: Array<string>,
33+
bootstrapModules: Array<string>,
3134
progressiveChunkSize?: number,
3235
onError: (error: mixed) => void,
3336
};
@@ -46,7 +49,13 @@ function renderToStream(children: ReactNodeList, options: Options): Stream {
4649
};
4750
const request = createRequest(
4851
children,
49-
createResponseState(options ? options.identifierPrefix : undefined),
52+
createResponseState(
53+
options ? options.identifierPrefix : undefined,
54+
undefined,
55+
options ? options.bootstrapScriptContent : undefined,
56+
options ? options.bootstrapScripts : undefined,
57+
options ? options.bootstrapModules : undefined,
58+
),
5059
createRootFormatContext(undefined),
5160
options ? options.progressiveChunkSize : undefined,
5261
options.onError,

packages/react-server-dom-relay/src/__tests__/ReactDOMServerFB-test.internal.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,21 @@ describe('ReactDOMServerFB', () => {
4848
expect(result).toMatchInlineSnapshot(`"<div>hello world</div>"`);
4949
});
5050

51+
it('should emit bootstrap script src at the end', () => {
52+
const stream = ReactDOMServer.renderToStream(<div>hello world</div>, {
53+
bootstrapScriptContent: 'INIT();',
54+
bootstrapScripts: ['init.js'],
55+
bootstrapModules: ['init.mjs'],
56+
onError(x) {
57+
console.error(x);
58+
},
59+
});
60+
const result = readResult(stream);
61+
expect(result).toMatchInlineSnapshot(
62+
`"<div>hello world</div><script>INIT();</script><script src=\\"init.js\\" async=\\"\\"></script><script type=\\"module\\" src=\\"init.mjs\\" async=\\"\\"></script>"`,
63+
);
64+
});
65+
5166
it('emits all HTML as one unit if we wait until the end to start', async () => {
5267
let hasLoaded = false;
5368
let resolve;

0 commit comments

Comments
 (0)