From 29f352c34f1b8c9eeca61fc86bc63dd5ca8ff2b1 Mon Sep 17 00:00:00 2001 From: Josh Story Date: Fri, 4 Aug 2023 14:49:03 -0700 Subject: [PATCH] scripts should not be preloaded over other arbitrary preloads. The point is to allow a sort of prioritization by the user via fetchPriority and order of preload calls and by making them use different queues we limit how much control you can have it ordering preloads --- .../src/server/ReactFizzConfigDOM.js | 60 ++++--------------- .../src/__tests__/ReactDOMFloat-test.js | 24 ++++---- 2 files changed, 24 insertions(+), 60 deletions(-) diff --git a/packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js b/packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js index dac2075d09a23..c59b53b01e19d 100644 --- a/packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js +++ b/packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js @@ -4245,20 +4245,8 @@ export function writePreamble( resources.scripts.forEach(flushResourceInPreamble, destination); resources.scripts.clear(); - resources.explicitStylesheetPreloads.forEach( - flushResourceInPreamble, - destination, - ); - resources.explicitStylesheetPreloads.clear(); - - resources.explicitScriptPreloads.forEach( - flushResourceInPreamble, - destination, - ); - resources.explicitScriptPreloads.clear(); - - resources.explicitOtherPreloads.forEach(flushResourceInPreamble, destination); - resources.explicitOtherPreloads.clear(); + resources.explicitPreloads.forEach(flushResourceInPreamble, destination); + resources.explicitPreloads.clear(); // Write embedding preloadChunks const preloadChunks = responseState.preloadChunks; @@ -4322,14 +4310,8 @@ export function writeHoistables( resources.scripts.forEach(flushResourceLate, destination); resources.scripts.clear(); - resources.explicitStylesheetPreloads.forEach(flushResourceLate, destination); - resources.explicitStylesheetPreloads.clear(); - - resources.explicitScriptPreloads.forEach(flushResourceLate, destination); - resources.explicitScriptPreloads.clear(); - - resources.explicitOtherPreloads.forEach(flushResourceLate, destination); - resources.explicitOtherPreloads.clear(); + resources.explicitPreloads.forEach(flushResourceLate, destination); + resources.explicitPreloads.clear(); // Write embedding preloadChunks const preloadChunks = responseState.preloadChunks; @@ -4873,10 +4855,7 @@ export type Resources = { precedences: Map>, stylePrecedences: Map, scripts: Set, - explicitStylesheetPreloads: Set, - // explicitImagePreloads: Set, - explicitScriptPreloads: Set, - explicitOtherPreloads: Set, + explicitPreloads: Set, // Module-global-like reference for current boundary resources boundaryResources: ?BoundaryResources, @@ -4899,10 +4878,7 @@ export function createResources(): Resources { precedences: new Map(), stylePrecedences: new Map(), scripts: new Set(), - explicitStylesheetPreloads: new Set(), - // explicitImagePreloads: new Set(), - explicitScriptPreloads: new Set(), - explicitOtherPreloads: new Set(), + explicitPreloads: new Set(), // like a module global for currently rendering boundary boundaryResources: null, @@ -5189,22 +5165,10 @@ export function preload(href: string, options: PreloadOptions) { pushLinkImpl(resource.chunks, resource.props); } - switch (as) { - case 'font': { - resources.fontPreloads.add(resource); - break; - } - case 'style': { - resources.explicitStylesheetPreloads.add(resource); - break; - } - case 'script': { - resources.explicitScriptPreloads.add(resource); - break; - } - default: { - resources.explicitOtherPreloads.add(resource); - } + if (as === 'font') { + resources.fontPreloads.add(resource); + } else { + resources.explicitPreloads.add(resource); } flushResources(request); } @@ -5479,7 +5443,7 @@ function preloadBootstrapScript( props, }; resources.preloadsMap.set(key, resource); - resources.explicitScriptPreloads.add(resource); + resources.explicitPreloads.add(resource); pushLinkImpl(resource.chunks, props); } @@ -5521,7 +5485,7 @@ function preloadBootstrapModule( props, }; resources.preloadsMap.set(key, resource); - resources.explicitScriptPreloads.add(resource); + resources.explicitPreloads.add(resource); pushLinkImpl(resource.chunks, props); return; } diff --git a/packages/react-dom/src/__tests__/ReactDOMFloat-test.js b/packages/react-dom/src/__tests__/ReactDOMFloat-test.js index 2ee581f850689..fd8a183f248c2 100644 --- a/packages/react-dom/src/__tests__/ReactDOMFloat-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMFloat-test.js @@ -4131,6 +4131,12 @@ body { expect(getMeaningfulChildren(document)).toEqual( + - hello , @@ -4166,6 +4166,12 @@ body { expect(getMeaningfulChildren(document)).toEqual( + -