Skip to content

Commit 5bc4b36

Browse files
authored
[backport] Ensure setAssetPrefix updates config instance (#82165)
Backports #82160 to our next-15-4 release branch
1 parent 717dfb6 commit 5bc4b36

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

packages/next/src/server/base-server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1707,7 +1707,8 @@ export default abstract class Server<
17071707
): Promise<void>
17081708

17091709
public setAssetPrefix(prefix?: string): void {
1710-
this.renderOpts.assetPrefix = prefix ? prefix.replace(/\/$/, '') : ''
1710+
this.nextConfig.assetPrefix = prefix ? prefix.replace(/\/$/, '') : ''
1711+
this.renderOpts.assetPrefix = this.nextConfig.assetPrefix
17111712
}
17121713

17131714
protected prepared: boolean = false
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { nextTestSetup } from 'e2e-utils'
2+
3+
describe('app-dir absolute assetPrefix', () => {
4+
const { next } = nextTestSetup({
5+
files: __dirname,
6+
nextConfig: {
7+
assetPrefix: 'https://example.vercel.sh/',
8+
},
9+
})
10+
11+
it('bundles should return 200 on served assetPrefix', async () => {
12+
const $ = await next.render$('/')
13+
14+
let bundles = []
15+
for (const script of $('script').toArray()) {
16+
const { src } = script.attribs
17+
if (src?.includes('https://example.vercel.sh/_next/static')) {
18+
bundles.push(src)
19+
}
20+
}
21+
22+
expect(bundles.length).toBeGreaterThan(0)
23+
24+
for (const src of bundles) {
25+
// Remove hostname to check if pathname is still used for serving the bundles
26+
const bundlePathWithoutHost = decodeURI(new URL(src).pathname)
27+
const { status } = await next.fetch(bundlePathWithoutHost)
28+
29+
expect(status).toBe(200)
30+
}
31+
})
32+
})

test/e2e/app-dir/asset-prefix-absolute/asset-prefix-absolute.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import { nextTestSetup } from 'e2e-utils'
33
describe('app-dir absolute assetPrefix', () => {
44
const { next } = nextTestSetup({
55
files: __dirname,
6+
nextConfig: {
7+
assetPrefix: 'https://example.vercel.sh/custom-asset-prefix',
8+
},
69
})
710

811
it('bundles should return 200 on served assetPrefix', async () => {

test/e2e/app-dir/asset-prefix-absolute/next.config.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)