Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fizz]: Unify preload queue #27190

Merged
merged 1 commit into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 10 additions & 46 deletions packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -4250,20 +4250,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;
Expand Down Expand Up @@ -4330,14 +4318,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;
Expand Down Expand Up @@ -4882,10 +4864,7 @@ export type Resources = {
stylePrecedences: Map<string, StyleTagResource>,
bootstrapScripts: Set<PreloadResource>,
scripts: Set<ScriptResource>,
explicitStylesheetPreloads: Set<PreloadResource>,
// explicitImagePreloads: Set<PreloadResource>,
explicitScriptPreloads: Set<PreloadResource>,
explicitOtherPreloads: Set<PreloadResource>,
explicitPreloads: Set<PreloadResource>,

// Module-global-like reference for current boundary resources
boundaryResources: ?BoundaryResources,
Expand All @@ -4909,10 +4888,7 @@ export function createResources(): Resources {
stylePrecedences: new Map(),
bootstrapScripts: new Set(),
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,
Expand Down Expand Up @@ -5199,22 +5175,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);
}
Expand Down
24 changes: 12 additions & 12 deletions packages/react-dom/src/__tests__/ReactDOMFloat-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4131,6 +4131,12 @@ body {
expect(getMeaningfulChildren(document)).toEqual(
<html>
<head>
<link
rel="preload"
as="script"
href="highserver"
fetchpriority="high"
/>
<link
rel="preload"
as="style"
Expand All @@ -4143,12 +4149,6 @@ body {
href="autoserver"
fetchpriority="auto"
/>
<link
rel="preload"
as="script"
href="highserver"
fetchpriority="high"
/>
</head>
<body>hello</body>
</html>,
Expand All @@ -4166,6 +4166,12 @@ body {
expect(getMeaningfulChildren(document)).toEqual(
<html>
<head>
<link
rel="preload"
as="script"
href="highserver"
fetchpriority="high"
/>
<link
rel="preload"
as="style"
Expand All @@ -4178,12 +4184,6 @@ body {
href="autoserver"
fetchpriority="auto"
/>
<link
rel="preload"
as="script"
href="highserver"
fetchpriority="high"
/>
<link
rel="preload"
as="script"
Expand Down