From e842c1c487119aebf854f616f0ee71c58876f56c Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Wed, 28 Sep 2022 19:03:21 +0200 Subject: [PATCH] Skip creating virtual app client entry for pages (#41000) When there're only one edge route in `pages/` and one in `app/`, the virtual client entry is split into pages chunks which is not expected. We should only create client virtual entries for `app/`, not `pages/`, now we skip the `pages/` entries for client entry now ## Bug - [ ] Related issues linked using `fixes #number` - [x] Integration tests added - [ ] Errors have a helpful link attached, see `contributing.md` --- .../plugins/flight-client-entry-plugin.ts | 3 ++ test/e2e/app-dir/app-edge.test.ts | 40 +++++++++++++++++++ .../app-dir/app-edge/app/app-edge/page.tsx | 4 ++ test/e2e/app-dir/app-edge/app/layout.tsx | 8 ++++ test/e2e/app-dir/app-edge/next.config.js | 7 ++++ .../e2e/app-dir/app-edge/pages/pages-edge.tsx | 5 +++ test/e2e/app-dir/app-edge/tsconfig.json | 24 +++++++++++ 7 files changed, 91 insertions(+) create mode 100644 test/e2e/app-dir/app-edge.test.ts create mode 100644 test/e2e/app-dir/app-edge/app/app-edge/page.tsx create mode 100644 test/e2e/app-dir/app-edge/app/layout.tsx create mode 100644 test/e2e/app-dir/app-edge/next.config.js create mode 100644 test/e2e/app-dir/app-edge/pages/pages-edge.tsx create mode 100644 test/e2e/app-dir/app-edge/tsconfig.json diff --git a/packages/next/build/webpack/plugins/flight-client-entry-plugin.ts b/packages/next/build/webpack/plugins/flight-client-entry-plugin.ts index afccbb5e11294..1e16b917be012 100644 --- a/packages/next/build/webpack/plugins/flight-client-entry-plugin.ts +++ b/packages/next/build/webpack/plugins/flight-client-entry-plugin.ts @@ -96,6 +96,9 @@ export class FlightClientEntryPlugin { }) => void ) { for (const [name, entry] of compilation.entries.entries()) { + // Skip for entries under pages/ + if (name.startsWith('pages/')) continue + // Check if the page entry is a server component or not. const entryDependency: webpack.NormalModule | undefined = entry.dependencies?.[0] diff --git a/test/e2e/app-dir/app-edge.test.ts b/test/e2e/app-dir/app-edge.test.ts new file mode 100644 index 0000000000000..4d31daf0f7c5f --- /dev/null +++ b/test/e2e/app-dir/app-edge.test.ts @@ -0,0 +1,40 @@ +import { createNext, FileRef } from 'e2e-utils' +import { NextInstance } from 'test/lib/next-modes/base' +import { renderViaHTTP } from 'next-test-utils' +import path from 'path' + +describe('app-dir edge SSR', () => { + if ((global as any).isNextDeploy) { + it('should skip next deploy for now', () => {}) + return + } + + if (process.env.NEXT_TEST_REACT_VERSION === '^17') { + it('should skip for react v17', () => {}) + return + } + + let next: NextInstance + + beforeAll(async () => { + next = await createNext({ + files: new FileRef(path.join(__dirname, 'app-edge')), + dependencies: { + react: 'experimental', + 'react-dom': 'experimental', + typescript: 'latest', + '@types/react': 'latest', + '@types/node': 'latest', + }, + }) + }) + afterAll(() => next.destroy()) + + it('should handle edge only routes', async () => { + const appHtml = await renderViaHTTP(next.url, '/app-edge') + expect(appHtml).toContain('

app-edge-ssr

') + + const pageHtml = await renderViaHTTP(next.url, '/pages-edge') + expect(pageHtml).toContain('

pages-edge-ssr

') + }) +}) diff --git a/test/e2e/app-dir/app-edge/app/app-edge/page.tsx b/test/e2e/app-dir/app-edge/app/app-edge/page.tsx new file mode 100644 index 0000000000000..3aa83203566ab --- /dev/null +++ b/test/e2e/app-dir/app-edge/app/app-edge/page.tsx @@ -0,0 +1,4 @@ +export default function Page() { + return

app-edge-ssr

+} +export const config = { runtime: 'experimental-edge' } diff --git a/test/e2e/app-dir/app-edge/app/layout.tsx b/test/e2e/app-dir/app-edge/app/layout.tsx new file mode 100644 index 0000000000000..079c59e3e2581 --- /dev/null +++ b/test/e2e/app-dir/app-edge/app/layout.tsx @@ -0,0 +1,8 @@ +export default function Root({ children }: { children: React.ReactNode }) { + return ( + + + {children} + + ) +} diff --git a/test/e2e/app-dir/app-edge/next.config.js b/test/e2e/app-dir/app-edge/next.config.js new file mode 100644 index 0000000000000..a928ea943ce24 --- /dev/null +++ b/test/e2e/app-dir/app-edge/next.config.js @@ -0,0 +1,7 @@ +module.exports = { + experimental: { + appDir: true, + legacyBrowsers: false, + browsersListForSwc: true, + }, +} diff --git a/test/e2e/app-dir/app-edge/pages/pages-edge.tsx b/test/e2e/app-dir/app-edge/pages/pages-edge.tsx new file mode 100644 index 0000000000000..50056c63d620f --- /dev/null +++ b/test/e2e/app-dir/app-edge/pages/pages-edge.tsx @@ -0,0 +1,5 @@ +export default function Page() { + return

pages-edge-ssr

+} + +export const config = { runtime: 'experimental-edge' } diff --git a/test/e2e/app-dir/app-edge/tsconfig.json b/test/e2e/app-dir/app-edge/tsconfig.json new file mode 100644 index 0000000000000..da141694cc0c8 --- /dev/null +++ b/test/e2e/app-dir/app-edge/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "target": "ES6", + "lib": ["dom", "dom.iterable", "esnext"], + "allowJs": true, + "skipLibCheck": true, + "strict": true, + "forceConsistentCasingInFileNames": true, + "noEmit": true, + "esModuleInterop": true, + "module": "esnext", + "moduleResolution": "node", + "resolveJsonModule": true, + "isolatedModules": true, + "jsx": "preserve", + "incremental": true, + "baseUrl": ".", + "paths": { + "@/ui/*": ["ui/*"] + } + }, + "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"], + "exclude": ["node_modules"] +}