Skip to content

Commit

Permalink
Remove app routes from _devPagesManifest (#43188)
Browse files Browse the repository at this point in the history
Currently in dev the `_devPagesManifest` includes the `/app` routes as
well. However, In production, the `_buildManifest.js` does not include
the `/app` routes. This causes the `/pages` router to behave differently
in the two environments.

This change excludes the `/app` routes from `_devPagesManifest` to make
it work the same in dev/prod.

Fixes #42513
Fixes #42532

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
  • Loading branch information
Hannes Bornö authored Nov 21, 2022
1 parent ee969ea commit d8d9b2c
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/next/server/dev/next-dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,9 @@ export default class DevServer extends Server {
res
.body(
JSON.stringify({
pages: this.sortedRoutes,
pages: this.sortedRoutes?.filter(
(route) => !this.appPathRoutes![route]
),
})
)
.send()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function Page() {
return (
<p id="app-text">
hello from app/dynamic-pages-route-app-overlap/app-dir/page
</p>
)
}
9 changes: 9 additions & 0 deletions test/e2e/app-dir/app/pages/dynamic-pages-route-app-overlap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Link from 'next/link'

export default function Page() {
return (
<Link id="pages-link" href="/dynamic-pages-route-app-overlap/app-dir">
To /dynamic-pages-route-app-overlap/app-dir
</Link>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function Page() {
return (
<p id="pages-text">
hello from pages/dynamic-pages-route-app-overlap/[slug]
</p>
)
}
23 changes: 23 additions & 0 deletions test/e2e/app-dir/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,29 @@ describe('app dir', () => {
await browser.close()
}
})

it('should navigate to pages dynamic route from pages page if it overlaps with an app page', async () => {
const browser = await webdriver(
next.url,
'/dynamic-pages-route-app-overlap'
)

try {
// Click the link.
await browser.elementById('pages-link').click()
expect(await browser.waitForElementByCss('#pages-text').text()).toBe(
'hello from pages/dynamic-pages-route-app-overlap/[slug]'
)

// When refreshing the browser, the app page should be rendered
await browser.refresh()
expect(await browser.waitForElementByCss('#app-text').text()).toBe(
'hello from app/dynamic-pages-route-app-overlap/app-dir/page'
)
} finally {
await browser.close()
}
})
})

describe('server components', () => {
Expand Down

0 comments on commit d8d9b2c

Please sign in to comment.