Unverified Commit 7c2fd345 authored by Sukka's avatar Sukka Committed by GitHub

fix(app-render): make css and font respect assetPrefix (#41455)

Add missing `assetPrefix` for link tags (`@next/font` and CSS).
The PR also merges multiple duplicated `renderOpt.assetPrefix || ''`.
parent 1d37afb3
...@@ -872,6 +872,8 @@ export async function renderToHTMLOrFlight( ...@@ -872,6 +872,8 @@ export async function renderToHTMLOrFlight(
ComponentMod.pages ComponentMod.pages
) )
const assetPrefix = renderOpts.assetPrefix || ''
/** /**
* Use the provided loader tree to create the React Component tree. * Use the provided loader tree to create the React Component tree.
*/ */
...@@ -1105,7 +1107,7 @@ export async function renderToHTMLOrFlight( ...@@ -1105,7 +1107,7 @@ export async function renderToHTMLOrFlight(
<link <link
key={fontFile} key={fontFile}
rel="preload" rel="preload"
href={`/_next/${fontFile}`} href={`${assetPrefix}/_next/${fontFile}`}
as="font" as="font"
type={`font/${ext}`} type={`font/${ext}`}
crossOrigin="anonymous" crossOrigin="anonymous"
...@@ -1116,7 +1118,7 @@ export async function renderToHTMLOrFlight( ...@@ -1116,7 +1118,7 @@ export async function renderToHTMLOrFlight(
? stylesheets.map((href) => ( ? stylesheets.map((href) => (
<link <link
rel="stylesheet" rel="stylesheet"
href={`/_next/${href}${cacheBustingUrlSuffix}`} href={`${assetPrefix}/_next/${href}${cacheBustingUrlSuffix}`}
// `Precedence` is an opt-in signal for React to handle // `Precedence` is an opt-in signal for React to handle
// resource loading and deduplication, etc: // resource loading and deduplication, etc:
// https://github.com/facebook/react/pull/25060 // https://github.com/facebook/react/pull/25060
...@@ -1351,7 +1353,7 @@ export async function renderToHTMLOrFlight( ...@@ -1351,7 +1353,7 @@ export async function renderToHTMLOrFlight(
return ( return (
<AppRouter <AppRouter
assetPrefix={renderOpts.assetPrefix || ''} assetPrefix={assetPrefix}
initialCanonicalUrl={initialCanonicalUrl} initialCanonicalUrl={initialCanonicalUrl}
initialTree={initialTree} initialTree={initialTree}
> >
...@@ -1397,7 +1399,7 @@ export async function renderToHTMLOrFlight( ...@@ -1397,7 +1399,7 @@ export async function renderToHTMLOrFlight(
polyfill.endsWith('.js') && !polyfill.endsWith('.module.js') polyfill.endsWith('.js') && !polyfill.endsWith('.module.js')
) )
.map((polyfill) => ({ .map((polyfill) => ({
src: `${renderOpts.assetPrefix || ''}/_next/${polyfill}`, src: `${assetPrefix}/_next/${polyfill}`,
integrity: subresourceIntegrityManifest?.[polyfill], integrity: subresourceIntegrityManifest?.[polyfill],
})) }))
...@@ -1444,11 +1446,11 @@ export async function renderToHTMLOrFlight( ...@@ -1444,11 +1446,11 @@ export async function renderToHTMLOrFlight(
bootstrapScripts: [ bootstrapScripts: [
...(subresourceIntegrityManifest ...(subresourceIntegrityManifest
? buildManifest.rootMainFiles.map((src) => ({ ? buildManifest.rootMainFiles.map((src) => ({
src: `${renderOpts.assetPrefix || ''}/_next/` + src, src: `${assetPrefix}/_next/` + src,
integrity: subresourceIntegrityManifest[src], integrity: subresourceIntegrityManifest[src],
})) }))
: buildManifest.rootMainFiles.map( : buildManifest.rootMainFiles.map(
(src) => `${renderOpts.assetPrefix || ''}/_next/` + src (src) => `${assetPrefix}/_next/` + src
)), )),
], ],
}, },
...@@ -1476,11 +1478,11 @@ export async function renderToHTMLOrFlight( ...@@ -1476,11 +1478,11 @@ export async function renderToHTMLOrFlight(
// Include hydration scripts in the HTML // Include hydration scripts in the HTML
bootstrapScripts: subresourceIntegrityManifest bootstrapScripts: subresourceIntegrityManifest
? buildManifest.rootMainFiles.map((src) => ({ ? buildManifest.rootMainFiles.map((src) => ({
src: `${renderOpts.assetPrefix || ''}/_next/` + src, src: `${assetPrefix}/_next/` + src,
integrity: subresourceIntegrityManifest[src], integrity: subresourceIntegrityManifest[src],
})) }))
: buildManifest.rootMainFiles.map( : buildManifest.rootMainFiles.map(
(src) => `${renderOpts.assetPrefix || ''}/_next/` + src (src) => `${assetPrefix}/_next/` + src
), ),
}, },
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment