|
8 | 8 | */ |
9 | 9 |
|
10 | 10 | 'use strict'; |
| 11 | +import * as fs from 'fs'; |
11 | 12 |
|
12 | 13 | let JSDOM; |
13 | 14 | let Stream; |
@@ -91,17 +92,7 @@ describe('ReactDOMFizzServer', () => { |
91 | 92 |
|
92 | 93 | renderOptions = {}; |
93 | 94 | if (gate(flags => flags.enableFizzNoScriptExecution)) { |
94 | | - window.__init_instruction_observer__ = () => { |
95 | | - global.testDocument = document; |
96 | | - global.MutationObserver = jsdom.window.MutationObserver; |
97 | | - reactInstructionObserver = ReactDOMFizzServer.getReactDOMClientMutationObserver(); |
98 | | - reactInstructionObserver.observe(container, { |
99 | | - childList: true, |
100 | | - subtree: true, |
101 | | - }); |
102 | | - }; |
103 | | - |
104 | | - renderOptions.bootstrapScriptContent = '__init_instruction_observer__();'; |
| 95 | + renderOptions.bootstrapModules = ['../server/ReactDOMClientInstructionObserver.js']; |
105 | 96 | renderOptions.disableInstructionScriptExecution = true; |
106 | 97 | } |
107 | 98 | }); |
@@ -138,7 +129,13 @@ describe('ReactDOMFizzServer', () => { |
138 | 129 | (CSPnonce === null || inner.getAttribute('nonce') === CSPnonce) |
139 | 130 | ) { |
140 | 131 | const script = document.createElement('SCRIPT'); |
141 | | - script.textContent = inner.textContent; |
| 132 | + const scriptSrc = inner.getAttribute("src"); |
| 133 | + if (scriptSrc) { |
| 134 | + script.textContent = fs.readFileSync(require.resolve(scriptSrc)); |
| 135 | + console.log("got script src"); |
| 136 | + } else { |
| 137 | + script.textContent = inner.textContent; |
| 138 | + } |
142 | 139 | node.replaceChild(script, inner); |
143 | 140 | } else { |
144 | 141 | replaceScripts(inner); |
@@ -172,7 +169,12 @@ describe('ReactDOMFizzServer', () => { |
172 | 169 | (CSPnonce === null || node.getAttribute('nonce') === CSPnonce) |
173 | 170 | ) { |
174 | 171 | const script = document.createElement('SCRIPT'); |
175 | | - script.textContent = node.textContent; |
| 172 | + const scriptSrc = node.getAttribute("src"); |
| 173 | + if (scriptSrc) { |
| 174 | + script.textContent = fs.readFileSync(require.resolve(scriptSrc)); |
| 175 | + } else { |
| 176 | + script.textContent = inner.textContent; |
| 177 | + } |
176 | 178 | fakeBody.removeChild(node); |
177 | 179 | parent.appendChild(script); |
178 | 180 | } else { |
@@ -330,13 +332,14 @@ describe('ReactDOMFizzServer', () => { |
330 | 332 | const mergedOptions = {...renderOptions}; |
331 | 333 | Object.entries(options).forEach(([key, value]) => { |
332 | 334 | if (mergedOptions[key]) { |
333 | | - if (key === 'bootstrapScriptContent') { |
334 | | - mergedOptions[key] += value; |
| 335 | + if (key === 'bootstrapModules') { |
| 336 | + mergedOptions[key].push(value); |
335 | 337 | } |
336 | 338 | } else { |
337 | 339 | mergedOptions[key] = value; |
338 | 340 | } |
339 | 341 | }); |
| 342 | + console.log(mergedOptions); |
340 | 343 | return ReactDOMFizzServer.renderToPipeableStream(jsx, mergedOptions); |
341 | 344 | } else { |
342 | 345 | return ReactDOMFizzServer.renderToPipeableStream(jsx, renderOptions); |
@@ -1849,7 +1852,6 @@ describe('ReactDOMFizzServer', () => { |
1849 | 1852 | await act(async () => { |
1850 | 1853 | controls = renderToPipeableStream( |
1851 | 1854 | <App isClient={false} />, |
1852 | | - |
1853 | 1855 | { |
1854 | 1856 | onError, |
1855 | 1857 | }, |
|
0 commit comments