From d8d9b2c985d576500821508b92c6e18a50be5df7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20Born=C3=B6?= Date: Tue, 22 Nov 2022 00:52:12 +0100 Subject: [PATCH] Remove app routes from _devPagesManifest (#43188) 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) --- packages/next/server/dev/next-dev-server.ts | 4 +++- .../app-dir/page.js | 7 ++++++ .../pages/dynamic-pages-route-app-overlap.js | 9 ++++++++ .../dynamic-pages-route-app-overlap/[slug].js | 7 ++++++ test/e2e/app-dir/index.test.ts | 23 +++++++++++++++++++ 5 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 test/e2e/app-dir/app/app/dynamic-pages-route-app-overlap/app-dir/page.js create mode 100644 test/e2e/app-dir/app/pages/dynamic-pages-route-app-overlap.js create mode 100644 test/e2e/app-dir/app/pages/dynamic-pages-route-app-overlap/[slug].js diff --git a/packages/next/server/dev/next-dev-server.ts b/packages/next/server/dev/next-dev-server.ts index 967d7103a58d6..a372f49a336ed 100644 --- a/packages/next/server/dev/next-dev-server.ts +++ b/packages/next/server/dev/next-dev-server.ts @@ -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() diff --git a/test/e2e/app-dir/app/app/dynamic-pages-route-app-overlap/app-dir/page.js b/test/e2e/app-dir/app/app/dynamic-pages-route-app-overlap/app-dir/page.js new file mode 100644 index 0000000000000..2b529331402f7 --- /dev/null +++ b/test/e2e/app-dir/app/app/dynamic-pages-route-app-overlap/app-dir/page.js @@ -0,0 +1,7 @@ +export default function Page() { + return ( +

+ hello from app/dynamic-pages-route-app-overlap/app-dir/page +

+ ) +} diff --git a/test/e2e/app-dir/app/pages/dynamic-pages-route-app-overlap.js b/test/e2e/app-dir/app/pages/dynamic-pages-route-app-overlap.js new file mode 100644 index 0000000000000..725caae598137 --- /dev/null +++ b/test/e2e/app-dir/app/pages/dynamic-pages-route-app-overlap.js @@ -0,0 +1,9 @@ +import Link from 'next/link' + +export default function Page() { + return ( + + To /dynamic-pages-route-app-overlap/app-dir + + ) +} diff --git a/test/e2e/app-dir/app/pages/dynamic-pages-route-app-overlap/[slug].js b/test/e2e/app-dir/app/pages/dynamic-pages-route-app-overlap/[slug].js new file mode 100644 index 0000000000000..80f7029a0281e --- /dev/null +++ b/test/e2e/app-dir/app/pages/dynamic-pages-route-app-overlap/[slug].js @@ -0,0 +1,7 @@ +export default function Page() { + return ( +

+ hello from pages/dynamic-pages-route-app-overlap/[slug] +

+ ) +} diff --git a/test/e2e/app-dir/index.test.ts b/test/e2e/app-dir/index.test.ts index 5b0a2e34d72d2..af5fa3044f754 100644 --- a/test/e2e/app-dir/index.test.ts +++ b/test/e2e/app-dir/index.test.ts @@ -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', () => {