[Fizz] Deduplicate <link rel="preload"> from Flight preload hints#35892
[Fizz] Deduplicate <link rel="preload"> from Flight preload hints#35892lllomh wants to merge 1 commit intofacebook:mainfrom
<link rel="preload"> from Flight preload hints#35892Conversation
…nt preload duplication
|
Hi @lllomh! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
There was a problem hiding this comment.
Can you removed the unrelated code changes (package.json formatting, .yarnrc.yaml etc.)? The rest looks legit at glance but hard to validate with the other unrelated changes that we can't merge.
The Contributor License Agreement must also be signed before we can accept this change.
<link rel="preload"> from Flight preload hints
Summary
Fixes #35889
<link rel="preload" as="font" />(and other preload types) renderedinside an RSC component was appearing twice in SSR HTML when used
with Fizz SSR. This regression was introduced in 19.2.
Root cause:
When the RSC Flight server processes a
<link rel="preload">element, itdoes two things:
'L'row) viaprocessLink()inReactFlightServerConfigDOM.js<link>element in the serialized component outputDuring Fizz SSR, the Flight hint is received and dispatched to the Fizz
preload()function, which registers the resource inresumableStateand adds it to
renderState.fontPreloads. Later, the same<link>element from the component output is processed by
pushLink(), whichfell through to
pushLinkImpl(renderState.hoistableChunks, props)withno deduplication check — producing a second identical link tag.
Fix:
In
pushLink(), before emitting a<link rel="preload">tohoistableChunks, check whether the resource is already registered inresumableState(using the same per-as-type tracking thatpreload()uses:
imageResources,styleResources,scriptResources, andunknownResourcesfor fonts and others). If already registered, returnnull. If not yet registered, register it so futurepreload()callswill also deduplicate correctly.
Test plan
does not duplicate font preload links from Flight hints during Fizz SSRinReactFlightDOM-test.jsthat rendersa
<link rel="preload" as="font">inside an RSC component through FizzSSR and asserts the link appears exactly once in the HTML output.