Unverified Commit 541902e3 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Ensure setAssetPrefix updates config instance (#82160)

This ensures we update `nextConfig.assetPrefix` instead of `renderOpts`
as we aren't relying on `renderOpts` for these values anymore.

Closes: https://github.com/vercel/next.js/issues/82150
parent e5c1dff8
......@@ -1652,7 +1652,7 @@ export default abstract class Server<
): Promise<void>
public setAssetPrefix(prefix?: string): void {
this.renderOpts.assetPrefix = prefix ? prefix.replace(/\/$/, '') : ''
this.nextConfig.assetPrefix = prefix ? prefix.replace(/\/$/, '') : ''
}
protected prepared: boolean = false
......
import { nextTestSetup } from 'e2e-utils'
describe('app-dir absolute assetPrefix', () => {
const { next } = nextTestSetup({
files: __dirname,
nextConfig: {
assetPrefix: 'https://example.vercel.sh/',
},
})
it('bundles should return 200 on served assetPrefix', async () => {
const $ = await next.render$('/')
let bundles = []
for (const script of $('script').toArray()) {
const { src } = script.attribs
if (src?.includes('https://example.vercel.sh/_next/static')) {
bundles.push(src)
}
}
expect(bundles.length).toBeGreaterThan(0)
for (const src of bundles) {
// Remove hostname to check if pathname is still used for serving the bundles
const bundlePathWithoutHost = decodeURI(new URL(src).pathname)
const { status } = await next.fetch(bundlePathWithoutHost)
expect(status).toBe(200)
}
})
})
......@@ -3,6 +3,9 @@ import { nextTestSetup } from 'e2e-utils'
describe('app-dir absolute assetPrefix', () => {
const { next } = nextTestSetup({
files: __dirname,
nextConfig: {
assetPrefix: 'https://example.vercel.sh/custom-asset-prefix',
},
})
it('bundles should return 200 on served assetPrefix', async () => {
......
module.exports = {
assetPrefix: 'https://example.vercel.sh/custom-asset-prefix',
}
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