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

interception routes: fix rewrites order #49615

Merged
merged 2 commits into from
May 11, 2023
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
2 changes: 1 addition & 1 deletion packages/next/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ export default async function build(
}

// Interception routes are modelled as beforeFiles rewrites
rewrites.beforeFiles.unshift(
rewrites.beforeFiles.push(
...generateInterceptionRoutesRewrites(appPageKeys)
)

Expand Down
6 changes: 4 additions & 2 deletions packages/next/src/server/dev/next-dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -793,10 +793,12 @@ export default class DevServer extends Server {
: undefined

this.customRoutes = await loadCustomRoutes(this.nextConfig)
this.customRoutes.rewrites.beforeFiles.unshift(
const { rewrites } = this.customRoutes

this.customRoutes.rewrites.beforeFiles.push(
...generateInterceptionRoutesRewrites(Object.keys(appPaths))
)
const { rewrites } = this.customRoutes

if (
rewrites.beforeFiles.length ||
rewrites.afterFiles.length ||
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Page() {
return <div id="intercepted">intercepted</div>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use client'

import Link from 'next/link'

export default function Page() {
return (
<div>
<div id="foo">FOO</div>
<Link href="/photos">To photos</Link>
</div>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Page() {
return 'non intercepted'
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {}
const nextConfig = {
async rewrites() {
return {
beforeFiles: [
{
source: '/foo',
destination: '/en/foo',
},
{
source: '/photos',
destination: '/en/photos',
},
],
}
},
}

module.exports = nextConfig
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,20 @@ createNextDescribe(
next.url + '/intercepting-parallel-modal/photo/2'
)
})

it('should support intercepting with beforeFiles rewrites', async () => {
const browser = await next.browser('/foo')

await check(
() =>
browser
.elementByCss('[href="/photos"]')
.click()
.waitForElementByCss('#intercepted')
.text(),
'intercepted'
)
})
})
}
)