Unverified Commit 7c0a504a authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Handle assetPrefix in app (#39236)

This ensures we properly leverage the `assetPrefix` for `app`. Note for reviewing the test changes are mostly spacing so hiding that may help. 

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

Fixes: [slack thread](https://vercel.slack.com/archives/C035J346QQL/p1659387244559979)
parent d56aadae
......@@ -33,7 +33,8 @@ self.__next_require__ = __webpack_require__
;(self as any).__next_chunk_load__ = (chunk: string) => {
if (!chunk) return Promise.resolve()
if (chunk.endsWith('.css')) {
const chunkPath = `/_next/${chunk}`
// @ts-expect-error __webpack_public_path__ is inlined by webpack
const chunkPath = `${__webpack_public_path__ || ''}${chunk}`
const existingTag = document.querySelector(`link[href="${chunkPath}"]`)
if (!existingTag) {
const link = document.createElement('link')
......
......@@ -37,6 +37,7 @@ export type RenderOptsPartial = {
supportsDynamicHTML?: boolean
runtime?: ServerRuntime
serverComponents?: boolean
assetPrefix?: string
}
export type RenderOpts = LoadComponentsReturnType & RenderOptsPartial
......@@ -962,7 +963,11 @@ export async function renderToHTMLOrFlight(
return (
<AppRouter
hotReloader={HotReloader && <HotReloader assetPrefix="" />}
hotReloader={
HotReloader && (
<HotReloader assetPrefix={renderOpts.assetPrefix || ''} />
)
}
initialCanonicalUrl={initialCanonicalUrl}
initialTree={initialTree}
initialStylesheets={initialStylesheets}
......@@ -1021,7 +1026,7 @@ export async function renderToHTMLOrFlight(
streamOptions: {
// Include hydration scripts in the HTML
bootstrapScripts: buildManifest.rootMainFiles.map(
(src) => '/_next/' + src
(src) => `${renderOpts.assetPrefix || ''}/_next/` + src
),
},
})
......
......@@ -6,12 +6,16 @@ module.exports = {
legacyBrowsers: false,
browsersListForSwc: true,
},
// assetPrefix: '/assets',
rewrites: async () => {
return [
{
source: '/rewritten-to-dashboard',
destination: '/dashboard',
},
]
return {
// beforeFiles: [ { source: '/assets/:path*', destination: '/:path*' } ],
afterFiles: [
{
source: '/rewritten-to-dashboard',
destination: '/dashboard',
},
],
}
},
}
This diff is collapsed.
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