diff --git a/packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js b/packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js index e5f57505eb9b8..2333f366f50e5 100644 --- a/packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js @@ -32,7 +32,6 @@ let buffer = ''; let hasErrored = false; let fatalError = undefined; const renderOptions = {}; -const rollupCache: Map = new Map(); describe('ReactDOMFizzServer', () => { beforeEach(() => { @@ -137,7 +136,7 @@ describe('ReactDOMFizzServer', () => { container.nodeName === '#document' ? container.body : container; while (fakeBody.firstChild) { const node = fakeBody.firstChild; - await replaceScriptsAndMove(window, rollupCache, CSPnonce, node, parent); + await replaceScriptsAndMove(window, CSPnonce, node, parent); } } @@ -163,12 +162,7 @@ describe('ReactDOMFizzServer', () => { document = jsdom.window.document; container = document; buffer = ''; - await replaceScriptsAndMove( - window, - rollupCache, - CSPnonce, - document.documentElement, - ); + await replaceScriptsAndMove(window, CSPnonce, document.documentElement); } function getVisibleChildren(element) { diff --git a/packages/react-dom/src/__tests__/ReactDOMFloat-test.js b/packages/react-dom/src/__tests__/ReactDOMFloat-test.js index 615d615e1515e..2ead3001d9df9 100644 --- a/packages/react-dom/src/__tests__/ReactDOMFloat-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMFloat-test.js @@ -27,7 +27,6 @@ let buffer = ''; let hasErrored = false; let fatalError = undefined; const renderOptions = {}; -const rollupCache: Map = new Map(); describe('ReactDOMFloat', () => { beforeEach(() => { @@ -103,13 +102,7 @@ describe('ReactDOMFloat', () => { container.nodeName === '#document' ? container.body : container; while (fakeBody.firstChild) { const node = fakeBody.firstChild; - await replaceScriptsAndMove( - document.defaultView, - rollupCache, - CSPnonce, - node, - parent, - ); + await replaceScriptsAndMove(document.defaultView, CSPnonce, node, parent); } } @@ -134,12 +127,7 @@ describe('ReactDOMFloat', () => { document = jsdom.window.document; container = document; buffer = ''; - await replaceScriptsAndMove( - jsdom.window, - rollupCache, - null, - document.documentElement, - ); + await replaceScriptsAndMove(jsdom.window, null, document.documentElement); } function getMeaningfulChildren(element) { diff --git a/packages/react-dom/src/test-utils/FizzTestUtils.js b/packages/react-dom/src/test-utils/FizzTestUtils.js index 051a3d7ef02e0..bf4084dc13e59 100644 --- a/packages/react-dom/src/test-utils/FizzTestUtils.js +++ b/packages/react-dom/src/test-utils/FizzTestUtils.js @@ -13,11 +13,10 @@ import * as fs from 'fs'; import replace from 'rollup-plugin-replace'; import {rollup} from 'rollup'; +const rollupCache: Map = new Map(); + // Utility function to read and bundle a standalone browser script -async function getRollupResult( - scriptSrc: string, - rollupCache: Map, -): Promise { +async function getRollupResult(scriptSrc: string): Promise { const cachedResult = rollupCache.get(scriptSrc); if (cachedResult !== undefined) { return cachedResult; @@ -71,7 +70,6 @@ async function getRollupResult( // 2. Resolving scripts with sources async function replaceScriptsAndMove( window: any, - rollupCache: Map, CSPnonce: string | null, node: Node, parent: Node | null, @@ -85,7 +83,7 @@ async function replaceScriptsAndMove( const script = window.document.createElement('SCRIPT'); const scriptSrc = element.getAttribute('src'); if (scriptSrc) { - const rollupOutput = await getRollupResult(scriptSrc, rollupCache); + const rollupOutput = await getRollupResult(scriptSrc); if (rollupOutput) { // Manually call eval(...) here, since changing the HTML text content // may interfere with hydration @@ -107,7 +105,7 @@ async function replaceScriptsAndMove( } else { for (let i = 0; i < node.childNodes.length; i++) { const inner = node.childNodes[i]; - await replaceScriptsAndMove(window, rollupCache, CSPnonce, inner, null); + await replaceScriptsAndMove(window, CSPnonce, inner, null); } if (parent != null) { parent.appendChild(node);