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 data route ordering in dev #54364

Merged
merged 2 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion packages/next/src/server/lib/router-utils/setup-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1246,10 +1246,12 @@ async function startWatcher(opts: SetupOpts) {
})
.filter(Boolean) as any

const dataRoutes: typeof opts.fsChecker.dynamicRoutes = []

for (const page of sortedRoutes) {
const route = buildDataRoute(page, 'development')
const routeRegex = getRouteRegex(route.page)
opts.fsChecker.dynamicRoutes.push({
dataRoutes.push({
...route,
regex: routeRegex.re.toString(),
match: getRouteMatcher({
Expand All @@ -1267,6 +1269,7 @@ async function startWatcher(opts: SetupOpts) {
}),
})
}
opts.fsChecker.dynamicRoutes.unshift(...dataRoutes)

if (!prevSortedRoutes?.every((val, idx) => val === sortedRoutes[idx])) {
// emit the change so clients fetch the update
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// this checks priority issues with catch-all routes that
// can match `_next/data/build-id/path.json

export function getServerSideProps() {
return {
notFound: true,
}
}

export default function Page() {
return <p>nested catch-all</p>
}
30 changes: 30 additions & 0 deletions test/integration/dynamic-routing/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1318,6 +1318,22 @@ function runTests({ dev }) {
nxtPrest: 'nxtPrest',
},
},
{
dataRouteRegex: normalizeRegEx(
`^\\/_next\\/data\\/${escapeRegex(
buildId
)}\\/([^\\/]+?)\\/([^\\/]+?)\\/(.+?)\\.json$`
),
namedDataRouteRegex: `^/_next/data/${escapeRegex(
buildId
)}/(?<nxtPname>[^/]+?)/(?<nxtPcomment>[^/]+?)/(?<nxtPrest>.+?)\\.json$`,
page: '/[name]/[comment]/[...rest]',
routeKeys: {
nxtPcomment: 'nxtPcomment',
nxtPname: 'nxtPname',
nxtPrest: 'nxtPrest',
},
},
],
dynamicRoutes: [
{
Expand Down Expand Up @@ -1458,6 +1474,19 @@ function runTests({ dev }) {
nxtPcomment: 'nxtPcomment',
},
},
{
namedRegex:
'^/(?<nxtPname>[^/]+?)/(?<nxtPcomment>[^/]+?)/(?<nxtPrest>.+?)(?:/)?$',
page: '/[name]/[comment]/[...rest]',
regex: normalizeRegEx(
'^\\/([^\\/]+?)\\/([^\\/]+?)\\/(.+?)(?:\\/)?$'
),
routeKeys: {
nxtPcomment: 'nxtPcomment',
nxtPname: 'nxtPname',
nxtPrest: 'nxtPrest',
},
},
],
rsc: {
header: 'RSC',
Expand All @@ -1475,6 +1504,7 @@ function runTests({ dev }) {

expect(manifest).toEqual({
'/[name]/[comment]': 'pages/[name]/[comment].js',
'/[name]/[comment]/[...rest]': 'pages/[name]/[comment]/[...rest].js',
'/[name]/comments': 'pages/[name]/comments.js',
'/[name]': 'pages/[name].js',
'/[name]/on-mount-redir': 'pages/[name]/on-mount-redir.html',
Expand Down