Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: App Router with assetPrefix: / #49622

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/next/src/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1810,7 +1810,13 @@ export default async function getBaseWebpackConfig(
output: {
// we must set publicPath to an empty value to override the default of
// auto which doesn't work in IE11
publicPath: `${config.assetPrefix || ''}/_next/`,
publicPath: `${
config.assetPrefix
? config.assetPrefix.endsWith('/')
? config.assetPrefix.slice(0, -1)
: config.assetPrefix
: ''
}/_next/`,
path: !dev && isNodeServer ? path.join(outputPath, 'chunks') : outputPath,
// On the server we don't use hashes
filename:
Expand Down
12 changes: 12 additions & 0 deletions test/integration/app-config-asset-prefix/app/layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const metadata = {
title: 'Next.js',
description: 'Generated by Next.js',
}

export default function RootLayout({ children }) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}
3 changes: 3 additions & 0 deletions test/integration/app-config-asset-prefix/app/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Index(props) {
return <p id="title">IndexPage</p>
}
3 changes: 3 additions & 0 deletions test/integration/app-config-asset-prefix/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
assetPrefix: '/',
}
35 changes: 35 additions & 0 deletions test/integration/app-config-asset-prefix/test/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* eslint-env jest */
import { join } from 'path'
import {
killApp,
findPort,
launchApp,
hasRedbox,
waitFor,
} from 'next-test-utils'
import webdriver from 'next-webdriver'

const appDir = join(__dirname, '../')

describe('App assetPrefix config', () => {
let appPort
let app

beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))

it('should render correctly with assetPrefix: "/"', async () => {
const browser = await webdriver(appPort, '/')
try {
await waitFor(2000)
expect(await hasRedbox(browser, false)).toBe(false)
const title = await browser.elementById('title').text()
expect(title).toBe('IndexPage')
} finally {
await browser.close()
}
})
})