Skip to content

Commit 87ad433

Browse files
committed
Track PreloadsProps on the resumable map
We have to ensure these are serializable. We transfer them to the resume so that they can be applied to resources discovered during the resume.
1 parent 505584f commit 87ad433

File tree

1 file changed

+32
-29
lines changed

1 file changed

+32
-29
lines changed

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

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ export type ResumableState = {
189189
hasHtml: boolean,
190190

191191
// Resources - Request local cache
192-
preloadsMap: {[key: string]: null},
192+
preloadsMap: {[key: string]: PreloadProps},
193193
preconnectsMap: {[key: string]: null},
194194
stylesMap: {[key: string]: null},
195195
scriptsMap: {[key: string]: null},
@@ -2139,23 +2139,23 @@ function pushLink(
21392139
let stylesInPrecedence = renderState.precedences.get(precedence);
21402140
if (!resumableState.stylesMap.hasOwnProperty(key)) {
21412141
const resourceProps = stylesheetPropsFromRawProps(props);
2142-
const preloadResource = renderState.preloadsMap.get(key);
21432142
let state = NoState;
2144-
if (preloadResource) {
2145-
// If we already had a preload we don't want that resource to flush directly.
2146-
// We let the newly created resource govern flushing.
2147-
preloadResource.state |= Blocked;
2148-
adoptPreloadPropsForStylesheetProps(
2149-
resourceProps,
2150-
preloadResource.props,
2151-
);
2152-
if (preloadResource.state & Flushed) {
2143+
if (resumableState.preloadsMap.hasOwnProperty(key)) {
2144+
const preloadProps: PreloadProps = resumableState.preloadsMap[key];
2145+
adoptPreloadPropsForStylesheetProps(resourceProps, preloadProps);
2146+
const preloadResource = renderState.preloadsMap.get(key);
2147+
if (preloadResource) {
2148+
// If we already had a preload we don't want that resource to flush directly.
2149+
// We let the newly created resource govern flushing.
2150+
preloadResource.state |= Blocked;
2151+
if (preloadResource.state & Flushed) {
2152+
state = PreloadFlushed;
2153+
}
2154+
} else {
2155+
// If we resumed then we assume that this was already flushed
2156+
// by the shell.
21532157
state = PreloadFlushed;
21542158
}
2155-
} else if (resumableState.preloadsMap.hasOwnProperty(key)) {
2156-
// If we resumed then we assume that this was already flushed
2157-
// by the shell.
2158-
state = PreloadFlushed;
21592159
}
21602160
const resource = {
21612161
type: 'stylesheet',
@@ -2551,7 +2551,7 @@ function pushImg(
25512551
state: NoState,
25522552
props: preloadProps,
25532553
};
2554-
resumableState.preloadsMap[key] = null;
2554+
resumableState.preloadsMap[key] = preloadProps;
25552555
renderState.preloadsMap.set(key, resource);
25562556
pushLinkImpl(resource.chunks, preloadProps);
25572557
} else {
@@ -2913,13 +2913,16 @@ function pushScript(
29132913
renderState.scripts.add(resource);
29142914

29152915
let scriptProps = props;
2916-
const preloadResource = renderState.preloadsMap.get(key);
2917-
if (preloadResource) {
2918-
// If we already had a preload we don't want that resource to flush directly.
2919-
// We let the newly created resource govern flushing.
2920-
preloadResource.state |= Blocked;
2916+
if (resumableState.preloadsMap.hasOwnProperty(key)) {
2917+
const preloadProps: PreloadProps = resumableState.preloadsMap[key];
29212918
scriptProps = {...props};
2922-
adoptPreloadPropsForScriptProps(scriptProps, preloadResource.props);
2919+
adoptPreloadPropsForScriptProps(scriptProps, preloadProps);
2920+
const preloadResource = renderState.preloadsMap.get(key);
2921+
if (preloadResource) {
2922+
// If we already had a preload we don't want that resource to flush directly.
2923+
// We let the newly created resource govern flushing.
2924+
preloadResource.state |= Blocked;
2925+
}
29232926
}
29242927
// encode the tag as Chunks
29252928
pushScriptImpl(resource.chunks, scriptProps);
@@ -4964,12 +4967,12 @@ type PreloadAsProps = {
49644967
rel: 'preload',
49654968
as: string,
49664969
href: ?string,
4967-
[string]: mixed,
4970+
[string]: ?string,
49684971
};
49694972
type PreloadModuleProps = {
49704973
rel: 'modulepreload',
49714974
href: ?string,
4972-
[string]: mixed,
4975+
[string]: ?string,
49734976
};
49744977
type PreloadProps = PreloadAsProps | PreloadModuleProps;
49754978
type PreloadResource = TResource<'preload', PreloadProps>;
@@ -5141,9 +5144,9 @@ function preload(href: string, as: string, options?: ?PreloadImplOptions) {
51415144
state: NoState,
51425145
props,
51435146
};
5144-
resumableState.preloadsMap[key] = null;
5147+
resumableState.preloadsMap[key] = props;
51455148
renderState.preloadsMap.set(key, resource);
5146-
pushLinkImpl(resource.chunks, resource.props);
5149+
pushLinkImpl(resource.chunks, props);
51475150
if (as === 'font') {
51485151
renderState.fontPreloads.add(resource);
51495152
} else if (as === 'image' && resource.props.fetchPriority === 'high') {
@@ -5192,7 +5195,7 @@ function preloadModule(
51925195
state: NoState,
51935196
props,
51945197
};
5195-
resumableState.preloadsMap[key] = null;
5198+
resumableState.preloadsMap[key] = props;
51965199
renderState.preloadsMap.set(key, resource);
51975200
pushLinkImpl(resource.chunks, resource.props);
51985201
renderState.bulkPreloads.add(resource);
@@ -5403,7 +5406,7 @@ function preloadBootstrapScript(
54035406
state: NoState,
54045407
props,
54055408
};
5406-
resumableState.preloadsMap[key] = null;
5409+
resumableState.preloadsMap[key] = props;
54075410
renderState.preloadsMap.set(key, resource);
54085411
renderState.bootstrapScripts.add(resource);
54095412
pushLinkImpl(resource.chunks, props);
@@ -5447,7 +5450,7 @@ function preloadBootstrapModule(
54475450
state: NoState,
54485451
props,
54495452
};
5450-
resumableState.preloadsMap[key] = null;
5453+
resumableState.preloadsMap[key] = props;
54515454
renderState.preloadsMap.set(key, resource);
54525455
renderState.bootstrapScripts.add(resource);
54535456
pushLinkImpl(resource.chunks, props);

0 commit comments

Comments
 (0)