Skip to content

Commit c8add69

Browse files
committed
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
1 parent d7b2474 commit c8add69

File tree

2 files changed

+22
-58
lines changed

2 files changed

+22
-58
lines changed

packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js

Lines changed: 10 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4247,20 +4247,8 @@ export function writePreamble(
42474247
resources.scripts.forEach(flushResourceInPreamble, destination);
42484248
resources.scripts.clear();
42494249

4250-
resources.explicitStylesheetPreloads.forEach(
4251-
flushResourceInPreamble,
4252-
destination,
4253-
);
4254-
resources.explicitStylesheetPreloads.clear();
4255-
4256-
resources.explicitScriptPreloads.forEach(
4257-
flushResourceInPreamble,
4258-
destination,
4259-
);
4260-
resources.explicitScriptPreloads.clear();
4261-
4262-
resources.explicitOtherPreloads.forEach(flushResourceInPreamble, destination);
4263-
resources.explicitOtherPreloads.clear();
4250+
resources.explicitPreloads.forEach(flushResourceInPreamble, destination);
4251+
resources.explicitPreloads.clear();
42644252

42654253
// Write embedding preloadChunks
42664254
const preloadChunks = responseState.preloadChunks;
@@ -4327,14 +4315,8 @@ export function writeHoistables(
43274315
resources.scripts.forEach(flushResourceLate, destination);
43284316
resources.scripts.clear();
43294317

4330-
resources.explicitStylesheetPreloads.forEach(flushResourceLate, destination);
4331-
resources.explicitStylesheetPreloads.clear();
4332-
4333-
resources.explicitScriptPreloads.forEach(flushResourceLate, destination);
4334-
resources.explicitScriptPreloads.clear();
4335-
4336-
resources.explicitOtherPreloads.forEach(flushResourceLate, destination);
4337-
resources.explicitOtherPreloads.clear();
4318+
resources.explicitPreloads.forEach(flushResourceLate, destination);
4319+
resources.explicitPreloads.clear();
43384320

43394321
// Write embedding preloadChunks
43404322
const preloadChunks = responseState.preloadChunks;
@@ -4879,10 +4861,7 @@ export type Resources = {
48794861
stylePrecedences: Map<string, StyleTagResource>,
48804862
bootstrapScripts: Set<PreloadResource>,
48814863
scripts: Set<ScriptResource>,
4882-
explicitStylesheetPreloads: Set<PreloadResource>,
4883-
// explicitImagePreloads: Set<PreloadResource>,
4884-
explicitScriptPreloads: Set<PreloadResource>,
4885-
explicitOtherPreloads: Set<PreloadResource>,
4864+
explicitPreloads: Set<PreloadResource>,
48864865

48874866
// Module-global-like reference for current boundary resources
48884867
boundaryResources: ?BoundaryResources,
@@ -4906,10 +4885,7 @@ export function createResources(): Resources {
49064885
stylePrecedences: new Map(),
49074886
bootstrapScripts: new Set(),
49084887
scripts: new Set(),
4909-
explicitStylesheetPreloads: new Set(),
4910-
// explicitImagePreloads: new Set(),
4911-
explicitScriptPreloads: new Set(),
4912-
explicitOtherPreloads: new Set(),
4888+
explicitPreloads: new Set(),
49134889

49144890
// like a module global for currently rendering boundary
49154891
boundaryResources: null,
@@ -5196,22 +5172,10 @@ export function preload(href: string, options: PreloadOptions) {
51965172

51975173
pushLinkImpl(resource.chunks, resource.props);
51985174
}
5199-
switch (as) {
5200-
case 'font': {
5201-
resources.fontPreloads.add(resource);
5202-
break;
5203-
}
5204-
case 'style': {
5205-
resources.explicitStylesheetPreloads.add(resource);
5206-
break;
5207-
}
5208-
case 'script': {
5209-
resources.explicitScriptPreloads.add(resource);
5210-
break;
5211-
}
5212-
default: {
5213-
resources.explicitOtherPreloads.add(resource);
5214-
}
5175+
if (as === 'font') {
5176+
resources.fontPreloads.add(resource);
5177+
} else {
5178+
resources.explicitPreloads.add(resource);
52155179
}
52165180
flushResources(request);
52175181
}

packages/react-dom/src/__tests__/ReactDOMFloat-test.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4131,6 +4131,12 @@ body {
41314131
expect(getMeaningfulChildren(document)).toEqual(
41324132
<html>
41334133
<head>
4134+
<link
4135+
rel="preload"
4136+
as="script"
4137+
href="highserver"
4138+
fetchpriority="high"
4139+
/>
41344140
<link
41354141
rel="preload"
41364142
as="style"
@@ -4143,12 +4149,6 @@ body {
41434149
href="autoserver"
41444150
fetchpriority="auto"
41454151
/>
4146-
<link
4147-
rel="preload"
4148-
as="script"
4149-
href="highserver"
4150-
fetchpriority="high"
4151-
/>
41524152
</head>
41534153
<body>hello</body>
41544154
</html>,
@@ -4166,6 +4166,12 @@ body {
41664166
expect(getMeaningfulChildren(document)).toEqual(
41674167
<html>
41684168
<head>
4169+
<link
4170+
rel="preload"
4171+
as="script"
4172+
href="highserver"
4173+
fetchpriority="high"
4174+
/>
41694175
<link
41704176
rel="preload"
41714177
as="style"
@@ -4178,12 +4184,6 @@ body {
41784184
href="autoserver"
41794185
fetchpriority="auto"
41804186
/>
4181-
<link
4182-
rel="preload"
4183-
as="script"
4184-
href="highserver"
4185-
fetchpriority="high"
4186-
/>
41874187
<link
41884188
rel="preload"
41894189
as="script"

0 commit comments

Comments
 (0)