You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using react's preload method, the preload link tag is not created in certain cases.
It works correctly with two link tags (OnlyLinkTags component).
Code example
constfs=require('node:fs');const{ createElement }=require('react');const{ preload, preinit }=require('react-dom');const{ renderToString }=require('react-dom/server');constCSS='/some.css';constLINK_PROPS={rel: 'stylesheet',href: CSS,};/** * Doesn't create the preload link tag */constPreloadAndPreinit=()=>{preload(CSS,{as: 'style'});preinit(CSS,{as: 'style'});returnnull;};/** * Doesn't create the preload link tag */constPreloadAndLinkWithPrecedence=()=>{preload(CSS,{as: 'style'});returncreateElement('link',{ ...LINK_PROPS,precedence: 'custom'});};/** * Creates the preload link tag correctly into the head * The stylesheet link tag stays in the body, because it doesn't have precedence */constPreloadAndLinkWithoutPrecedence=()=>{preload(CSS,{as: 'style'});returncreateElement('link',LINK_PROPS);};/** * Moves both tags into the head */constOnlyLinkTags=()=>[createElement('link',{key: 'preload',rel: 'preload',as: 'style',href: CSS,}),createElement('link',{ ...LINK_PROPS,key: 'link',precedence: 'custom'}),];[PreloadAndPreinit,PreloadAndLinkWithPrecedence,PreloadAndLinkWithoutPrecedence,OnlyLinkTags,].forEach((Component)=>{fs.writeFileSync(`_${Component.name}.html`,renderToString(createElement('html',null,createElement('head'),createElement('body',null,createElement(Component)),),),);});
Thank you for the details. Could you include the expected behavior for each case? It's not clear at a glance which cases work as expected and which don't.
Thank you for the details. Could you include the expected behavior for each case? It's not clear at a glance which cases work as expected and which don't.
Summary
19.0.0-rc-3563387fe3-20240621
20.14.0
When using react's preload method, the preload link tag is not created in certain cases.
It works correctly with two link tags (
OnlyLinkTags
component).Code example
Outputs:
PreloadAndPreinit:
Current:
Expected:
PreloadAndLinkWithPrecedence:
Current:
Expected:
PreloadAndLinkWithoutPrecedence:
Current:
Expected:
The same as current.
OnlyLinkTags:
Current:
Expected:
The same as current.
The text was updated successfully, but these errors were encountered: