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 intercepted segments with basepath #60485

Merged
merged 4 commits into from
Jan 10, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/next/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,9 @@ export default async function build(

const appPaths = Array.from(appPageKeys)
// Interception routes are modelled as beforeFiles rewrites
rewrites.beforeFiles.push(...generateInterceptionRoutesRewrites(appPaths))
rewrites.beforeFiles.push(
...generateInterceptionRoutesRewrites(appPaths, config.basePath)
)

const totalAppPagesCount = appPaths.length

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ function voidParamsBeforeInterceptionMarker(path: string): string {
}

export function generateInterceptionRoutesRewrites(
appPaths: string[]
appPaths: string[],
basePath = ''
): Rewrite[] {
const rewrites: Rewrite[] = []

Expand All @@ -70,8 +71,8 @@ export function generateInterceptionRoutesRewrites(
.slice(2, -3)

rewrites.push({
source: normalizedInterceptedRoute,
destination: normalizedAppPath,
source: `${basePath}${normalizedInterceptedRoute}`,
destination: `${basePath}${normalizedAppPath}`,
has: [
{
type: 'header',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2270,7 +2270,10 @@ async function startWatcher(opts: SetupOpts) {
: undefined

opts.fsChecker.interceptionRoutes =
generateInterceptionRoutesRewrites(Object.keys(appPaths))?.map((item) =>
generateInterceptionRoutesRewrites(
Object.keys(appPaths),
opts.nextConfig.basePath
)?.map((item) =>
buildCustomRoute(
'before_files_rewrite',
item,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Page() {
return <div id="nested-page-slot">Nested Page Slot</div>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Default() {
return null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Default() {
return null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export default function Layout(props: {
children: React.ReactNode
slot: React.ReactNode
}) {
return (
<html>
<body>
<div id="children">{props.children}</div>
{props.slot}
</body>
</html>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Page() {
return <div id="nested-page-full">Nested Page Full</div>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Link from 'next/link'

export default function Page() {
return (
<div>
<div id="home-page">Home page</div>
<br />
<Link id="link-to-nested" href="/nested">
To Nested
</Link>
</div>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
basePath: '/base',
}

module.exports = nextConfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { createNextDescribe } from 'e2e-utils'

createNextDescribe(
'parallel-routes-and-interception-basepath',
{
files: __dirname,
},
({ next }) => {
it('should show parallel intercepted slot with basepath', async () => {
const browser = await next.browser('/base')
await browser.elementByCss('#link-to-nested').click()
const homePage = await browser.elementByCss('#home-page').text()
const slot = await browser.elementByCss('#nested-page-slot').text()
expect(homePage).toBe('Home page')
expect(slot).toBe('Nested Page Slot')
})
it('should show normal route via direct link with basepath when parallel intercepted slot exist', async () => {
const browser = await next.browser('/base/nested')
const nestedPageFull = await browser
.elementByCss('#nested-page-full')
.text()
expect(nestedPageFull).toBe('Nested Page Full')
})
}
)