From 2dfffa6271d1263eabc83eb6f64bdf84016f4092 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Tue, 3 May 2022 18:25:53 -0500 Subject: [PATCH 01/11] Tweak routing tests --- .../app/{root => views}/client-component-route.client.js | 0 test/e2e/root-dir/app/{root => views}/client-nested.client.js | 0 .../index.server.js => views/client-nested/page.js} | 0 .../[slug].server.js => views/conditional/[slug]/page.js} | 0 .../app/{root => views}/conditional/[slug]@team/index.js | 0 .../app/{root => views}/conditional/[slug]@team/members.js | 0 .../app/{root => views}/conditional/[slug]@user/index.js | 0 .../app/{root => views}/conditional/[slug]@user/teams.js | 0 .../root-dir/app/{root => views}/dashboard+changelog.server.js | 0 .../app/{root => views}/dashboard+rootonly/hello.server.js | 0 .../[id].server.js => views/dashboard/deployments/[id]/page.js} | 0 .../info.server.js => views/dashboard/deployments/info/page.js} | 0 .../dashboard/deployments/layout.js} | 0 .../app/{root => views}/dashboard/integrations/index.server.js | 0 .../app/{root/dashboard.server.js => views/dashboard/layout.js} | 0 .../{root/dashboard/index.server.js => views/dashboard/page.js} | 0 .../partial-match-[id]/page.js} | 0 .../shared-component-route/page.js} | 0 .../app/{root => views}/should-not-serve-client.client.js | 0 .../app/{root => views}/should-not-serve-server.server.js | 0 test/e2e/root-dir/index.test.ts | 2 +- 21 files changed, 1 insertion(+), 1 deletion(-) rename test/e2e/root-dir/app/{root => views}/client-component-route.client.js (100%) rename test/e2e/root-dir/app/{root => views}/client-nested.client.js (100%) rename test/e2e/root-dir/app/{root/client-nested/index.server.js => views/client-nested/page.js} (100%) rename test/e2e/root-dir/app/{root/conditional/[slug].server.js => views/conditional/[slug]/page.js} (100%) rename test/e2e/root-dir/app/{root => views}/conditional/[slug]@team/index.js (100%) rename test/e2e/root-dir/app/{root => views}/conditional/[slug]@team/members.js (100%) rename test/e2e/root-dir/app/{root => views}/conditional/[slug]@user/index.js (100%) rename test/e2e/root-dir/app/{root => views}/conditional/[slug]@user/teams.js (100%) rename test/e2e/root-dir/app/{root => views}/dashboard+changelog.server.js (100%) rename test/e2e/root-dir/app/{root => views}/dashboard+rootonly/hello.server.js (100%) rename test/e2e/root-dir/app/{root/dashboard/deployments/[id].server.js => views/dashboard/deployments/[id]/page.js} (100%) rename test/e2e/root-dir/app/{root/dashboard/deployments/info.server.js => views/dashboard/deployments/info/page.js} (100%) rename test/e2e/root-dir/app/{root/dashboard/deployments.server.js => views/dashboard/deployments/layout.js} (100%) rename test/e2e/root-dir/app/{root => views}/dashboard/integrations/index.server.js (100%) rename test/e2e/root-dir/app/{root/dashboard.server.js => views/dashboard/layout.js} (100%) rename test/e2e/root-dir/app/{root/dashboard/index.server.js => views/dashboard/page.js} (100%) rename test/e2e/root-dir/app/{root/partial-match-[id].server.js => views/partial-match-[id]/page.js} (100%) rename test/e2e/root-dir/app/{root/shared-component-route.js => views/shared-component-route/page.js} (100%) rename test/e2e/root-dir/app/{root => views}/should-not-serve-client.client.js (100%) rename test/e2e/root-dir/app/{root => views}/should-not-serve-server.server.js (100%) diff --git a/test/e2e/root-dir/app/root/client-component-route.client.js b/test/e2e/root-dir/app/views/client-component-route.client.js similarity index 100% rename from test/e2e/root-dir/app/root/client-component-route.client.js rename to test/e2e/root-dir/app/views/client-component-route.client.js diff --git a/test/e2e/root-dir/app/root/client-nested.client.js b/test/e2e/root-dir/app/views/client-nested.client.js similarity index 100% rename from test/e2e/root-dir/app/root/client-nested.client.js rename to test/e2e/root-dir/app/views/client-nested.client.js diff --git a/test/e2e/root-dir/app/root/client-nested/index.server.js b/test/e2e/root-dir/app/views/client-nested/page.js similarity index 100% rename from test/e2e/root-dir/app/root/client-nested/index.server.js rename to test/e2e/root-dir/app/views/client-nested/page.js diff --git a/test/e2e/root-dir/app/root/conditional/[slug].server.js b/test/e2e/root-dir/app/views/conditional/[slug]/page.js similarity index 100% rename from test/e2e/root-dir/app/root/conditional/[slug].server.js rename to test/e2e/root-dir/app/views/conditional/[slug]/page.js diff --git a/test/e2e/root-dir/app/root/conditional/[slug]@team/index.js b/test/e2e/root-dir/app/views/conditional/[slug]@team/index.js similarity index 100% rename from test/e2e/root-dir/app/root/conditional/[slug]@team/index.js rename to test/e2e/root-dir/app/views/conditional/[slug]@team/index.js diff --git a/test/e2e/root-dir/app/root/conditional/[slug]@team/members.js b/test/e2e/root-dir/app/views/conditional/[slug]@team/members.js similarity index 100% rename from test/e2e/root-dir/app/root/conditional/[slug]@team/members.js rename to test/e2e/root-dir/app/views/conditional/[slug]@team/members.js diff --git a/test/e2e/root-dir/app/root/conditional/[slug]@user/index.js b/test/e2e/root-dir/app/views/conditional/[slug]@user/index.js similarity index 100% rename from test/e2e/root-dir/app/root/conditional/[slug]@user/index.js rename to test/e2e/root-dir/app/views/conditional/[slug]@user/index.js diff --git a/test/e2e/root-dir/app/root/conditional/[slug]@user/teams.js b/test/e2e/root-dir/app/views/conditional/[slug]@user/teams.js similarity index 100% rename from test/e2e/root-dir/app/root/conditional/[slug]@user/teams.js rename to test/e2e/root-dir/app/views/conditional/[slug]@user/teams.js diff --git a/test/e2e/root-dir/app/root/dashboard+changelog.server.js b/test/e2e/root-dir/app/views/dashboard+changelog.server.js similarity index 100% rename from test/e2e/root-dir/app/root/dashboard+changelog.server.js rename to test/e2e/root-dir/app/views/dashboard+changelog.server.js diff --git a/test/e2e/root-dir/app/root/dashboard+rootonly/hello.server.js b/test/e2e/root-dir/app/views/dashboard+rootonly/hello.server.js similarity index 100% rename from test/e2e/root-dir/app/root/dashboard+rootonly/hello.server.js rename to test/e2e/root-dir/app/views/dashboard+rootonly/hello.server.js diff --git a/test/e2e/root-dir/app/root/dashboard/deployments/[id].server.js b/test/e2e/root-dir/app/views/dashboard/deployments/[id]/page.js similarity index 100% rename from test/e2e/root-dir/app/root/dashboard/deployments/[id].server.js rename to test/e2e/root-dir/app/views/dashboard/deployments/[id]/page.js diff --git a/test/e2e/root-dir/app/root/dashboard/deployments/info.server.js b/test/e2e/root-dir/app/views/dashboard/deployments/info/page.js similarity index 100% rename from test/e2e/root-dir/app/root/dashboard/deployments/info.server.js rename to test/e2e/root-dir/app/views/dashboard/deployments/info/page.js diff --git a/test/e2e/root-dir/app/root/dashboard/deployments.server.js b/test/e2e/root-dir/app/views/dashboard/deployments/layout.js similarity index 100% rename from test/e2e/root-dir/app/root/dashboard/deployments.server.js rename to test/e2e/root-dir/app/views/dashboard/deployments/layout.js diff --git a/test/e2e/root-dir/app/root/dashboard/integrations/index.server.js b/test/e2e/root-dir/app/views/dashboard/integrations/index.server.js similarity index 100% rename from test/e2e/root-dir/app/root/dashboard/integrations/index.server.js rename to test/e2e/root-dir/app/views/dashboard/integrations/index.server.js diff --git a/test/e2e/root-dir/app/root/dashboard.server.js b/test/e2e/root-dir/app/views/dashboard/layout.js similarity index 100% rename from test/e2e/root-dir/app/root/dashboard.server.js rename to test/e2e/root-dir/app/views/dashboard/layout.js diff --git a/test/e2e/root-dir/app/root/dashboard/index.server.js b/test/e2e/root-dir/app/views/dashboard/page.js similarity index 100% rename from test/e2e/root-dir/app/root/dashboard/index.server.js rename to test/e2e/root-dir/app/views/dashboard/page.js diff --git a/test/e2e/root-dir/app/root/partial-match-[id].server.js b/test/e2e/root-dir/app/views/partial-match-[id]/page.js similarity index 100% rename from test/e2e/root-dir/app/root/partial-match-[id].server.js rename to test/e2e/root-dir/app/views/partial-match-[id]/page.js diff --git a/test/e2e/root-dir/app/root/shared-component-route.js b/test/e2e/root-dir/app/views/shared-component-route/page.js similarity index 100% rename from test/e2e/root-dir/app/root/shared-component-route.js rename to test/e2e/root-dir/app/views/shared-component-route/page.js diff --git a/test/e2e/root-dir/app/root/should-not-serve-client.client.js b/test/e2e/root-dir/app/views/should-not-serve-client.client.js similarity index 100% rename from test/e2e/root-dir/app/root/should-not-serve-client.client.js rename to test/e2e/root-dir/app/views/should-not-serve-client.client.js diff --git a/test/e2e/root-dir/app/root/should-not-serve-server.server.js b/test/e2e/root-dir/app/views/should-not-serve-server.server.js similarity index 100% rename from test/e2e/root-dir/app/root/should-not-serve-server.server.js rename to test/e2e/root-dir/app/views/should-not-serve-server.server.js diff --git a/test/e2e/root-dir/index.test.ts b/test/e2e/root-dir/index.test.ts index 991f46ea10e6..14e214dc1b7a 100644 --- a/test/e2e/root-dir/index.test.ts +++ b/test/e2e/root-dir/index.test.ts @@ -5,7 +5,7 @@ import path from 'path' import cheerio from 'cheerio' import webdriver from 'next-webdriver' -describe('root dir', () => { +describe.skip('root dir', () => { let next: NextInstance beforeAll(async () => { From e2445e17b7ddf46e135bf9119086b317bf3185f5 Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Wed, 4 May 2022 14:02:32 +0200 Subject: [PATCH 02/11] Add loader --- packages/next/build/webpack-config.ts | 1 + .../build/webpack/loaders/next-view-loader.ts | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 packages/next/build/webpack/loaders/next-view-loader.ts diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index b7afc07101fe..2a20939e80b2 100644 --- a/packages/next/build/webpack-config.ts +++ b/packages/next/build/webpack-config.ts @@ -1190,6 +1190,7 @@ export default async function getBaseWebpackConfig( 'next-middleware-loader', 'next-middleware-ssr-loader', 'next-middleware-wasm-loader', + 'next-view-loader', ].reduce((alias, loader) => { // using multiple aliases to replace `resolveLoader.modules` alias[loader] = path.join(__dirname, 'webpack', 'loaders', loader) diff --git a/packages/next/build/webpack/loaders/next-view-loader.ts b/packages/next/build/webpack/loaders/next-view-loader.ts new file mode 100644 index 000000000000..af12ebee0070 --- /dev/null +++ b/packages/next/build/webpack/loaders/next-view-loader.ts @@ -0,0 +1,17 @@ +import type webpack from 'webpack5' + +const nextViewLoader: webpack.LoaderDefinitionFunction<{ + components: string[] +}> = function nextViewLoader() { + const loaderOptions = this.getOptions() || {} + + return ` + export const components = { + ${loaderOptions.components + .map((component) => `'${component}': () => import('${component}')`) + .join(',\n')} + } + ` +} + +export default nextViewLoader From 851eb6c59619587aea485989ae201ac127cb6952 Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Wed, 4 May 2022 14:22:25 +0200 Subject: [PATCH 03/11] Rename dir --- test/e2e/{root-dir => views-dir}/app/next.config.js | 0 test/e2e/{root-dir => views-dir}/app/pages/blog/[slug].js | 0 test/e2e/{root-dir => views-dir}/app/pages/index.js | 0 test/e2e/{root-dir => views-dir}/app/public/hello.txt | 0 test/e2e/{root-dir => views-dir}/app/root.server.js | 0 .../app/views/client-component-route.client.js | 0 .../e2e/{root-dir => views-dir}/app/views/client-nested.client.js | 0 test/e2e/{root-dir => views-dir}/app/views/client-nested/page.js | 0 .../{root-dir => views-dir}/app/views/conditional/[slug]/page.js | 0 .../app/views/conditional/[slug]@team/index.js | 0 .../app/views/conditional/[slug]@team/members.js | 0 .../app/views/conditional/[slug]@user/index.js | 0 .../app/views/conditional/[slug]@user/teams.js | 0 .../app/views/dashboard+changelog.server.js | 0 .../app/views/dashboard+rootonly/hello.server.js | 0 .../app/views/dashboard/deployments/[id]/page.js | 0 .../app/views/dashboard/deployments/info/page.js | 0 .../app/views/dashboard/deployments/layout.js | 0 .../app/views/dashboard/integrations/index.server.js | 0 test/e2e/{root-dir => views-dir}/app/views/dashboard/layout.js | 0 test/e2e/{root-dir => views-dir}/app/views/dashboard/page.js | 0 .../{root-dir => views-dir}/app/views/partial-match-[id]/page.js | 0 .../app/views/shared-component-route/page.js | 0 .../app/views/should-not-serve-client.client.js | 0 .../app/views/should-not-serve-server.server.js | 0 test/e2e/{root-dir => views-dir}/index.test.ts | 0 26 files changed, 0 insertions(+), 0 deletions(-) rename test/e2e/{root-dir => views-dir}/app/next.config.js (100%) rename test/e2e/{root-dir => views-dir}/app/pages/blog/[slug].js (100%) rename test/e2e/{root-dir => views-dir}/app/pages/index.js (100%) rename test/e2e/{root-dir => views-dir}/app/public/hello.txt (100%) rename test/e2e/{root-dir => views-dir}/app/root.server.js (100%) rename test/e2e/{root-dir => views-dir}/app/views/client-component-route.client.js (100%) rename test/e2e/{root-dir => views-dir}/app/views/client-nested.client.js (100%) rename test/e2e/{root-dir => views-dir}/app/views/client-nested/page.js (100%) rename test/e2e/{root-dir => views-dir}/app/views/conditional/[slug]/page.js (100%) rename test/e2e/{root-dir => views-dir}/app/views/conditional/[slug]@team/index.js (100%) rename test/e2e/{root-dir => views-dir}/app/views/conditional/[slug]@team/members.js (100%) rename test/e2e/{root-dir => views-dir}/app/views/conditional/[slug]@user/index.js (100%) rename test/e2e/{root-dir => views-dir}/app/views/conditional/[slug]@user/teams.js (100%) rename test/e2e/{root-dir => views-dir}/app/views/dashboard+changelog.server.js (100%) rename test/e2e/{root-dir => views-dir}/app/views/dashboard+rootonly/hello.server.js (100%) rename test/e2e/{root-dir => views-dir}/app/views/dashboard/deployments/[id]/page.js (100%) rename test/e2e/{root-dir => views-dir}/app/views/dashboard/deployments/info/page.js (100%) rename test/e2e/{root-dir => views-dir}/app/views/dashboard/deployments/layout.js (100%) rename test/e2e/{root-dir => views-dir}/app/views/dashboard/integrations/index.server.js (100%) rename test/e2e/{root-dir => views-dir}/app/views/dashboard/layout.js (100%) rename test/e2e/{root-dir => views-dir}/app/views/dashboard/page.js (100%) rename test/e2e/{root-dir => views-dir}/app/views/partial-match-[id]/page.js (100%) rename test/e2e/{root-dir => views-dir}/app/views/shared-component-route/page.js (100%) rename test/e2e/{root-dir => views-dir}/app/views/should-not-serve-client.client.js (100%) rename test/e2e/{root-dir => views-dir}/app/views/should-not-serve-server.server.js (100%) rename test/e2e/{root-dir => views-dir}/index.test.ts (100%) diff --git a/test/e2e/root-dir/app/next.config.js b/test/e2e/views-dir/app/next.config.js similarity index 100% rename from test/e2e/root-dir/app/next.config.js rename to test/e2e/views-dir/app/next.config.js diff --git a/test/e2e/root-dir/app/pages/blog/[slug].js b/test/e2e/views-dir/app/pages/blog/[slug].js similarity index 100% rename from test/e2e/root-dir/app/pages/blog/[slug].js rename to test/e2e/views-dir/app/pages/blog/[slug].js diff --git a/test/e2e/root-dir/app/pages/index.js b/test/e2e/views-dir/app/pages/index.js similarity index 100% rename from test/e2e/root-dir/app/pages/index.js rename to test/e2e/views-dir/app/pages/index.js diff --git a/test/e2e/root-dir/app/public/hello.txt b/test/e2e/views-dir/app/public/hello.txt similarity index 100% rename from test/e2e/root-dir/app/public/hello.txt rename to test/e2e/views-dir/app/public/hello.txt diff --git a/test/e2e/root-dir/app/root.server.js b/test/e2e/views-dir/app/root.server.js similarity index 100% rename from test/e2e/root-dir/app/root.server.js rename to test/e2e/views-dir/app/root.server.js diff --git a/test/e2e/root-dir/app/views/client-component-route.client.js b/test/e2e/views-dir/app/views/client-component-route.client.js similarity index 100% rename from test/e2e/root-dir/app/views/client-component-route.client.js rename to test/e2e/views-dir/app/views/client-component-route.client.js diff --git a/test/e2e/root-dir/app/views/client-nested.client.js b/test/e2e/views-dir/app/views/client-nested.client.js similarity index 100% rename from test/e2e/root-dir/app/views/client-nested.client.js rename to test/e2e/views-dir/app/views/client-nested.client.js diff --git a/test/e2e/root-dir/app/views/client-nested/page.js b/test/e2e/views-dir/app/views/client-nested/page.js similarity index 100% rename from test/e2e/root-dir/app/views/client-nested/page.js rename to test/e2e/views-dir/app/views/client-nested/page.js diff --git a/test/e2e/root-dir/app/views/conditional/[slug]/page.js b/test/e2e/views-dir/app/views/conditional/[slug]/page.js similarity index 100% rename from test/e2e/root-dir/app/views/conditional/[slug]/page.js rename to test/e2e/views-dir/app/views/conditional/[slug]/page.js diff --git a/test/e2e/root-dir/app/views/conditional/[slug]@team/index.js b/test/e2e/views-dir/app/views/conditional/[slug]@team/index.js similarity index 100% rename from test/e2e/root-dir/app/views/conditional/[slug]@team/index.js rename to test/e2e/views-dir/app/views/conditional/[slug]@team/index.js diff --git a/test/e2e/root-dir/app/views/conditional/[slug]@team/members.js b/test/e2e/views-dir/app/views/conditional/[slug]@team/members.js similarity index 100% rename from test/e2e/root-dir/app/views/conditional/[slug]@team/members.js rename to test/e2e/views-dir/app/views/conditional/[slug]@team/members.js diff --git a/test/e2e/root-dir/app/views/conditional/[slug]@user/index.js b/test/e2e/views-dir/app/views/conditional/[slug]@user/index.js similarity index 100% rename from test/e2e/root-dir/app/views/conditional/[slug]@user/index.js rename to test/e2e/views-dir/app/views/conditional/[slug]@user/index.js diff --git a/test/e2e/root-dir/app/views/conditional/[slug]@user/teams.js b/test/e2e/views-dir/app/views/conditional/[slug]@user/teams.js similarity index 100% rename from test/e2e/root-dir/app/views/conditional/[slug]@user/teams.js rename to test/e2e/views-dir/app/views/conditional/[slug]@user/teams.js diff --git a/test/e2e/root-dir/app/views/dashboard+changelog.server.js b/test/e2e/views-dir/app/views/dashboard+changelog.server.js similarity index 100% rename from test/e2e/root-dir/app/views/dashboard+changelog.server.js rename to test/e2e/views-dir/app/views/dashboard+changelog.server.js diff --git a/test/e2e/root-dir/app/views/dashboard+rootonly/hello.server.js b/test/e2e/views-dir/app/views/dashboard+rootonly/hello.server.js similarity index 100% rename from test/e2e/root-dir/app/views/dashboard+rootonly/hello.server.js rename to test/e2e/views-dir/app/views/dashboard+rootonly/hello.server.js diff --git a/test/e2e/root-dir/app/views/dashboard/deployments/[id]/page.js b/test/e2e/views-dir/app/views/dashboard/deployments/[id]/page.js similarity index 100% rename from test/e2e/root-dir/app/views/dashboard/deployments/[id]/page.js rename to test/e2e/views-dir/app/views/dashboard/deployments/[id]/page.js diff --git a/test/e2e/root-dir/app/views/dashboard/deployments/info/page.js b/test/e2e/views-dir/app/views/dashboard/deployments/info/page.js similarity index 100% rename from test/e2e/root-dir/app/views/dashboard/deployments/info/page.js rename to test/e2e/views-dir/app/views/dashboard/deployments/info/page.js diff --git a/test/e2e/root-dir/app/views/dashboard/deployments/layout.js b/test/e2e/views-dir/app/views/dashboard/deployments/layout.js similarity index 100% rename from test/e2e/root-dir/app/views/dashboard/deployments/layout.js rename to test/e2e/views-dir/app/views/dashboard/deployments/layout.js diff --git a/test/e2e/root-dir/app/views/dashboard/integrations/index.server.js b/test/e2e/views-dir/app/views/dashboard/integrations/index.server.js similarity index 100% rename from test/e2e/root-dir/app/views/dashboard/integrations/index.server.js rename to test/e2e/views-dir/app/views/dashboard/integrations/index.server.js diff --git a/test/e2e/root-dir/app/views/dashboard/layout.js b/test/e2e/views-dir/app/views/dashboard/layout.js similarity index 100% rename from test/e2e/root-dir/app/views/dashboard/layout.js rename to test/e2e/views-dir/app/views/dashboard/layout.js diff --git a/test/e2e/root-dir/app/views/dashboard/page.js b/test/e2e/views-dir/app/views/dashboard/page.js similarity index 100% rename from test/e2e/root-dir/app/views/dashboard/page.js rename to test/e2e/views-dir/app/views/dashboard/page.js diff --git a/test/e2e/root-dir/app/views/partial-match-[id]/page.js b/test/e2e/views-dir/app/views/partial-match-[id]/page.js similarity index 100% rename from test/e2e/root-dir/app/views/partial-match-[id]/page.js rename to test/e2e/views-dir/app/views/partial-match-[id]/page.js diff --git a/test/e2e/root-dir/app/views/shared-component-route/page.js b/test/e2e/views-dir/app/views/shared-component-route/page.js similarity index 100% rename from test/e2e/root-dir/app/views/shared-component-route/page.js rename to test/e2e/views-dir/app/views/shared-component-route/page.js diff --git a/test/e2e/root-dir/app/views/should-not-serve-client.client.js b/test/e2e/views-dir/app/views/should-not-serve-client.client.js similarity index 100% rename from test/e2e/root-dir/app/views/should-not-serve-client.client.js rename to test/e2e/views-dir/app/views/should-not-serve-client.client.js diff --git a/test/e2e/root-dir/app/views/should-not-serve-server.server.js b/test/e2e/views-dir/app/views/should-not-serve-server.server.js similarity index 100% rename from test/e2e/root-dir/app/views/should-not-serve-server.server.js rename to test/e2e/views-dir/app/views/should-not-serve-server.server.js diff --git a/test/e2e/root-dir/index.test.ts b/test/e2e/views-dir/index.test.ts similarity index 100% rename from test/e2e/root-dir/index.test.ts rename to test/e2e/views-dir/index.test.ts From 7281468dcabf2dc62b30f72f082151558e4d6fec Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Wed, 4 May 2022 15:32:53 +0200 Subject: [PATCH 04/11] Update tests --- .../dashboard/changelog/page.server.js} | 0 .../dashboard/hello/page.server.js} | 0 .../page.client.js} | 0 .../{page.js => index/page.server.js} | 0 .../layout.client.js} | 0 .../app/views/conditional/[slug]/page.js | 27 ----------- .../views/conditional/[slug]@team/index.js | 7 --- .../views/conditional/[slug]@team/members.js | 7 --- .../views/conditional/[slug]@user/index.js | 7 --- .../views/conditional/[slug]@user/teams.js | 7 --- .../[id]/{page.js => page.server.js} | 0 .../info/{page.js => page.server.js} | 0 .../{layout.js => layout.server.js} | 0 .../{page.js => index/page.server.js} | 0 .../{index.server.js => index/page.server.js} | 0 .../dashboard/{layout.js => layout.server.js} | 0 .../{page.js => page.server.js} | 0 .../page.client.js} | 0 .../page.server.js} | 0 test/e2e/views-dir/index.test.ts | 45 ------------------- 20 files changed, 100 deletions(-) rename test/e2e/views-dir/app/views/{dashboard+changelog.server.js => (rootonly)/dashboard/changelog/page.server.js} (100%) rename test/e2e/views-dir/app/views/{dashboard+rootonly/hello.server.js => (rootonly)/dashboard/hello/page.server.js} (100%) rename test/e2e/views-dir/app/views/{client-component-route.client.js => client-component-route/page.client.js} (100%) rename test/e2e/views-dir/app/views/client-nested/{page.js => index/page.server.js} (100%) rename test/e2e/views-dir/app/views/{client-nested.client.js => client-nested/layout.client.js} (100%) delete mode 100644 test/e2e/views-dir/app/views/conditional/[slug]/page.js delete mode 100644 test/e2e/views-dir/app/views/conditional/[slug]@team/index.js delete mode 100644 test/e2e/views-dir/app/views/conditional/[slug]@team/members.js delete mode 100644 test/e2e/views-dir/app/views/conditional/[slug]@user/index.js delete mode 100644 test/e2e/views-dir/app/views/conditional/[slug]@user/teams.js rename test/e2e/views-dir/app/views/dashboard/deployments/[id]/{page.js => page.server.js} (100%) rename test/e2e/views-dir/app/views/dashboard/deployments/info/{page.js => page.server.js} (100%) rename test/e2e/views-dir/app/views/dashboard/deployments/{layout.js => layout.server.js} (100%) rename test/e2e/views-dir/app/views/dashboard/{page.js => index/page.server.js} (100%) rename test/e2e/views-dir/app/views/dashboard/integrations/{index.server.js => index/page.server.js} (100%) rename test/e2e/views-dir/app/views/dashboard/{layout.js => layout.server.js} (100%) rename test/e2e/views-dir/app/views/partial-match-[id]/{page.js => page.server.js} (100%) rename test/e2e/views-dir/app/views/{should-not-serve-client.client.js => should-not-serve-client/page.client.js} (100%) rename test/e2e/views-dir/app/views/{should-not-serve-server.server.js => should-not-serve-server/page.server.js} (100%) diff --git a/test/e2e/views-dir/app/views/dashboard+changelog.server.js b/test/e2e/views-dir/app/views/(rootonly)/dashboard/changelog/page.server.js similarity index 100% rename from test/e2e/views-dir/app/views/dashboard+changelog.server.js rename to test/e2e/views-dir/app/views/(rootonly)/dashboard/changelog/page.server.js diff --git a/test/e2e/views-dir/app/views/dashboard+rootonly/hello.server.js b/test/e2e/views-dir/app/views/(rootonly)/dashboard/hello/page.server.js similarity index 100% rename from test/e2e/views-dir/app/views/dashboard+rootonly/hello.server.js rename to test/e2e/views-dir/app/views/(rootonly)/dashboard/hello/page.server.js diff --git a/test/e2e/views-dir/app/views/client-component-route.client.js b/test/e2e/views-dir/app/views/client-component-route/page.client.js similarity index 100% rename from test/e2e/views-dir/app/views/client-component-route.client.js rename to test/e2e/views-dir/app/views/client-component-route/page.client.js diff --git a/test/e2e/views-dir/app/views/client-nested/page.js b/test/e2e/views-dir/app/views/client-nested/index/page.server.js similarity index 100% rename from test/e2e/views-dir/app/views/client-nested/page.js rename to test/e2e/views-dir/app/views/client-nested/index/page.server.js diff --git a/test/e2e/views-dir/app/views/client-nested.client.js b/test/e2e/views-dir/app/views/client-nested/layout.client.js similarity index 100% rename from test/e2e/views-dir/app/views/client-nested.client.js rename to test/e2e/views-dir/app/views/client-nested/layout.client.js diff --git a/test/e2e/views-dir/app/views/conditional/[slug]/page.js b/test/e2e/views-dir/app/views/conditional/[slug]/page.js deleted file mode 100644 index 14dae08e2713..000000000000 --- a/test/e2e/views-dir/app/views/conditional/[slug]/page.js +++ /dev/null @@ -1,27 +0,0 @@ -export async function getServerSideProps({ params }) { - if (params.slug === 'nonexistent') { - return { - notFound: true, - } - } - return { - props: { - isUser: params.slug === 'tim', - isBoth: params.slug === 'both', - }, - } -} - -export default function UserOrTeam({ isUser, isBoth, user, team }) { - return ( - <> - {isUser && !isBoth ? user : team} - {isBoth ? ( - <> - {user} - {team} - - ) : null} - - ) -} diff --git a/test/e2e/views-dir/app/views/conditional/[slug]@team/index.js b/test/e2e/views-dir/app/views/conditional/[slug]@team/index.js deleted file mode 100644 index 02119380f338..000000000000 --- a/test/e2e/views-dir/app/views/conditional/[slug]@team/index.js +++ /dev/null @@ -1,7 +0,0 @@ -export default function TeamHomePage(props) { - return ( - <> -

hello from team homepage

- - ) -} diff --git a/test/e2e/views-dir/app/views/conditional/[slug]@team/members.js b/test/e2e/views-dir/app/views/conditional/[slug]@team/members.js deleted file mode 100644 index 2c3ba112bead..000000000000 --- a/test/e2e/views-dir/app/views/conditional/[slug]@team/members.js +++ /dev/null @@ -1,7 +0,0 @@ -export default function TeamMembersPage(props) { - return ( - <> -

hello from team/members

- - ) -} diff --git a/test/e2e/views-dir/app/views/conditional/[slug]@user/index.js b/test/e2e/views-dir/app/views/conditional/[slug]@user/index.js deleted file mode 100644 index 81100777dae2..000000000000 --- a/test/e2e/views-dir/app/views/conditional/[slug]@user/index.js +++ /dev/null @@ -1,7 +0,0 @@ -export default function UserHomePage(props) { - return ( - <> -

hello from user homepage

- - ) -} diff --git a/test/e2e/views-dir/app/views/conditional/[slug]@user/teams.js b/test/e2e/views-dir/app/views/conditional/[slug]@user/teams.js deleted file mode 100644 index 294c3bf316da..000000000000 --- a/test/e2e/views-dir/app/views/conditional/[slug]@user/teams.js +++ /dev/null @@ -1,7 +0,0 @@ -export default function UserTeamsPage(props) { - return ( - <> -

hello from user/teams

- - ) -} diff --git a/test/e2e/views-dir/app/views/dashboard/deployments/[id]/page.js b/test/e2e/views-dir/app/views/dashboard/deployments/[id]/page.server.js similarity index 100% rename from test/e2e/views-dir/app/views/dashboard/deployments/[id]/page.js rename to test/e2e/views-dir/app/views/dashboard/deployments/[id]/page.server.js diff --git a/test/e2e/views-dir/app/views/dashboard/deployments/info/page.js b/test/e2e/views-dir/app/views/dashboard/deployments/info/page.server.js similarity index 100% rename from test/e2e/views-dir/app/views/dashboard/deployments/info/page.js rename to test/e2e/views-dir/app/views/dashboard/deployments/info/page.server.js diff --git a/test/e2e/views-dir/app/views/dashboard/deployments/layout.js b/test/e2e/views-dir/app/views/dashboard/deployments/layout.server.js similarity index 100% rename from test/e2e/views-dir/app/views/dashboard/deployments/layout.js rename to test/e2e/views-dir/app/views/dashboard/deployments/layout.server.js diff --git a/test/e2e/views-dir/app/views/dashboard/page.js b/test/e2e/views-dir/app/views/dashboard/index/page.server.js similarity index 100% rename from test/e2e/views-dir/app/views/dashboard/page.js rename to test/e2e/views-dir/app/views/dashboard/index/page.server.js diff --git a/test/e2e/views-dir/app/views/dashboard/integrations/index.server.js b/test/e2e/views-dir/app/views/dashboard/integrations/index/page.server.js similarity index 100% rename from test/e2e/views-dir/app/views/dashboard/integrations/index.server.js rename to test/e2e/views-dir/app/views/dashboard/integrations/index/page.server.js diff --git a/test/e2e/views-dir/app/views/dashboard/layout.js b/test/e2e/views-dir/app/views/dashboard/layout.server.js similarity index 100% rename from test/e2e/views-dir/app/views/dashboard/layout.js rename to test/e2e/views-dir/app/views/dashboard/layout.server.js diff --git a/test/e2e/views-dir/app/views/partial-match-[id]/page.js b/test/e2e/views-dir/app/views/partial-match-[id]/page.server.js similarity index 100% rename from test/e2e/views-dir/app/views/partial-match-[id]/page.js rename to test/e2e/views-dir/app/views/partial-match-[id]/page.server.js diff --git a/test/e2e/views-dir/app/views/should-not-serve-client.client.js b/test/e2e/views-dir/app/views/should-not-serve-client/page.client.js similarity index 100% rename from test/e2e/views-dir/app/views/should-not-serve-client.client.js rename to test/e2e/views-dir/app/views/should-not-serve-client/page.client.js diff --git a/test/e2e/views-dir/app/views/should-not-serve-server.server.js b/test/e2e/views-dir/app/views/should-not-serve-server/page.server.js similarity index 100% rename from test/e2e/views-dir/app/views/should-not-serve-server.server.js rename to test/e2e/views-dir/app/views/should-not-serve-server/page.server.js diff --git a/test/e2e/views-dir/index.test.ts b/test/e2e/views-dir/index.test.ts index 14e214dc1b7a..6e346f4ce392 100644 --- a/test/e2e/views-dir/index.test.ts +++ b/test/e2e/views-dir/index.test.ts @@ -131,51 +131,6 @@ describe.skip('root dir', () => { expect(html).toContain('hello from root/partial-match-[id]. ID is: 123') }) - // TODO: Implement - describe.skip('parallel routes', () => { - describe('conditional routes', () => { - it('should serve user page', async () => { - const html = await renderViaHTTP(next.url, '/conditional/tim') - expect(html).toContain('hello from user homepage') - }) - - it('should serve user teams page', async () => { - const html = await renderViaHTTP(next.url, '/conditional/tim/teams') - expect(html).toContain('hello from user/teams') - }) - - it('should not serve teams page to user', async () => { - const html = await renderViaHTTP(next.url, '/conditional/tim/members') - expect(html).not.toContain('hello from team/members') - }) - - it('should serve team page', async () => { - const html = await renderViaHTTP(next.url, '/conditional/vercel') - expect(html).toContain('hello from team homepage') - }) - - it('should serve team members page', async () => { - const html = await renderViaHTTP( - next.url, - '/conditional/vercel/members' - ) - expect(html).toContain('hello from team/members') - }) - - it('should provide both matches if both paths match', async () => { - const html = await renderViaHTTP(next.url, '/conditional/both') - expect(html).toContain('hello from team homepage') - expect(html).toContain('hello from user homepage') - }) - - it('should 404 based on getServerSideProps', async () => { - const res = await fetchViaHTTP(next.url, '/conditional/nonexistent') - expect(res.status).toBe(404) - expect(await res.text()).toContain('This page could not be found') - }) - }) - }) - describe('server components', () => { // TODO: why is this not servable but /dashboard+rootonly/hello.server.js // should be? Seems like they both either should be servable or not From ec3fa0aad62612ef6ecdd3f1f015fd446139a098 Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Wed, 4 May 2022 15:43:14 +0200 Subject: [PATCH 05/11] Move file --- test/e2e/views-dir/app/{root.server.js => views/layout.server.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/e2e/views-dir/app/{root.server.js => views/layout.server.js} (100%) diff --git a/test/e2e/views-dir/app/root.server.js b/test/e2e/views-dir/app/views/layout.server.js similarity index 100% rename from test/e2e/views-dir/app/root.server.js rename to test/e2e/views-dir/app/views/layout.server.js From 01f9ca2d57b53c6a7f5811a01792c0750243f0d5 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Wed, 4 May 2022 19:20:44 -0500 Subject: [PATCH 06/11] Update views/layout handling --- packages/next/build/entries.ts | 2 +- .../webpack/plugins/pages-manifest-plugin.ts | 2 +- packages/next/lib/find-pages-dir.ts | 4 +-- packages/next/server/base-server.ts | 31 +++++++++++-------- .../server/dev/on-demand-entry-handler.ts | 2 +- .../next/server/get-route-from-entrypoint.ts | 2 +- packages/next/server/lib/find-page-file.ts | 2 +- packages/next/server/load-components.ts | 2 +- packages/next/server/root-render.tsx | 4 ++- .../shared/lib/router/utils/root-paths.ts | 19 +++++++----- packages/next/taskfile.js | 1 + test/e2e/views-dir/index.test.ts | 13 ++------ 12 files changed, 44 insertions(+), 40 deletions(-) diff --git a/packages/next/build/entries.ts b/packages/next/build/entries.ts index 440cd60c3dfd..4b8c822ef444 100644 --- a/packages/next/build/entries.ts +++ b/packages/next/build/entries.ts @@ -376,7 +376,7 @@ export async function createEntrypoints(params: CreateEntrypointsParams) { const bundleFile = normalizePagePath(page) const clientBundlePath = posix.join('pages', bundleFile) const serverBundlePath = posix.join( - isRoot ? (bundleFile === '/root' ? './' : 'root') : 'pages', + isRoot ? (bundleFile === '/root' ? './' : 'views') : 'pages', bundleFile ) diff --git a/packages/next/build/webpack/plugins/pages-manifest-plugin.ts b/packages/next/build/webpack/plugins/pages-manifest-plugin.ts index c68f7e944ad4..0ab61944adf7 100644 --- a/packages/next/build/webpack/plugins/pages-manifest-plugin.ts +++ b/packages/next/build/webpack/plugins/pages-manifest-plugin.ts @@ -74,7 +74,7 @@ export default class PagesManifestPlugin implements webpack.Plugin { } file = normalizePathSep(file) - if (entrypoint.name.startsWith('root/')) { + if (entrypoint.name.startsWith('views/')) { rootPaths[pagePath] = file } else { pages[pagePath] = file diff --git a/packages/next/lib/find-pages-dir.ts b/packages/next/lib/find-pages-dir.ts index 862849fd00de..8c8d7e36d84b 100644 --- a/packages/next/lib/find-pages-dir.ts +++ b/packages/next/lib/find-pages-dir.ts @@ -10,7 +10,7 @@ export const existsSync = (f: string): boolean => { } } -function findDir(dir: string, name: 'pages' | 'root'): string | null { +function findDir(dir: string, name: 'pages' | 'views'): string | null { // prioritize ./${name} over ./src/${name} let curDir = path.join(dir, name) if (existsSync(curDir)) return curDir @@ -29,7 +29,7 @@ export function findPagesDir( let rootDir: undefined | string if (root) { - rootDir = findDir(dir, 'root') || undefined + rootDir = findDir(dir, 'views') || undefined } // TODO: allow "root" dir without pages dir diff --git a/packages/next/server/base-server.ts b/packages/next/server/base-server.ts index 73a8413f9410..d6aaab3464d9 100644 --- a/packages/next/server/base-server.ts +++ b/packages/next/server/base-server.ts @@ -1030,14 +1030,16 @@ export default abstract class Server { const parts = pathname.split('/').filter(Boolean) for (let i = 1; i < parts.length; i++) { - const parentPath = `/${parts.slice(0, i).join('/')}` + const layoutPath = `/${parts.slice(0, i).join('/')}/layout` - if (paths.includes(parentPath)) { - layoutPaths.push(parentPath) + if (paths.includes(layoutPath)) { + layoutPaths.push(layoutPath) } } - // TODO: when should we bail on adding the root.js wrapper - layoutPaths.unshift('/_root') + + if (this.rootPathRoutes['/layout']) { + layoutPaths.unshift('/layout') + } } return layoutPaths } @@ -1758,20 +1760,23 @@ export default abstract class Server { const getOriginalRootPath = (rootPath: string) => { if (this.nextConfig.experimental.rootDir) { const originalRootPath = - this.rootPathRoutes?.[`${pathname}/index`] || - this.rootPathRoutes?.[pathname] + this.rootPathRoutes?.[`${rootPath}/index`] || + this.rootPathRoutes?.[`${rootPath}`] if (!originalRootPath) { return null } - const isRoutable = this.isRoutableRootPath(rootPath) + + // TODO: isRoutable check no longer needed as it will only + // find an originalRootPath if it is routable now + // const isRoutable = this.isRoutableRootPath(rootPath) // 404 when layout is hit and this isn't a routable path // e.g. root/hello.js with root/hello/another.js but // no root/hello/index.js - if (!isRoutable) { - return '' - } + // if (!isRoutable) { + // return '' + // } return originalRootPath } return null @@ -1786,7 +1791,7 @@ export default abstract class Server { layoutPaths.map(async (path) => { const layoutRes = await this.findPageComponents(path) return { - isRoot: path === '/_root', + isRoot: path === '/layout', Component: layoutRes?.components.Component!, getStaticProps: layoutRes?.components.getStaticProps, getServerSideProps: layoutRes?.components.getServerSideProps, @@ -1835,7 +1840,7 @@ export default abstract class Server { } const dynamicRouteResult = await this.findPageComponents( - dynamicRoute.page, + page, query, params ) diff --git a/packages/next/server/dev/on-demand-entry-handler.ts b/packages/next/server/dev/on-demand-entry-handler.ts index 6ca20c9b068c..48fa63957e5d 100644 --- a/packages/next/server/dev/on-demand-entry-handler.ts +++ b/packages/next/server/dev/on-demand-entry-handler.ts @@ -376,7 +376,7 @@ async function findPagePathData( bundlePath = 'root' absolutePagePath = join(rootDir!, '..', pagePath) } else { - bundlePath = posix.join(isRoot ? 'root' : 'pages', bundleFile) + bundlePath = posix.join(isRoot ? 'views' : 'pages', bundleFile) absolutePagePath = join(isRoot ? rootDir! : pagesDir, pagePath) } diff --git a/packages/next/server/get-route-from-entrypoint.ts b/packages/next/server/get-route-from-entrypoint.ts index ddeafbfff538..30e40e9858a3 100644 --- a/packages/next/server/get-route-from-entrypoint.ts +++ b/packages/next/server/get-route-from-entrypoint.ts @@ -3,7 +3,7 @@ import getRouteFromAssetPath from '../shared/lib/router/utils/get-route-from-ass // matches pages/:page*.js const SERVER_ROUTE_NAME_REGEX = /^pages[/\\](.*)$/ // matches root/:path*.js -const ROOT_ROUTE_NAME_REGEX = /^root[/\\](.*)$/ +const ROOT_ROUTE_NAME_REGEX = /^views[/\\](.*)$/ // matches static/pages/:page*.js const BROWSER_ROUTE_NAME_REGEX = /^static[/\\]pages[/\\](.*)$/ diff --git a/packages/next/server/lib/find-page-file.ts b/packages/next/server/lib/find-page-file.ts index 7c3e8bf838d3..517931fbde2a 100644 --- a/packages/next/server/lib/find-page-file.ts +++ b/packages/next/server/lib/find-page-file.ts @@ -20,7 +20,7 @@ export async function findPageFile( normalizedPagePath: string, pageExtensions: string[] ): Promise { - const isRootPaths = pagesDir.replace(/\\/g, '/').endsWith('/root') + const isRootPaths = pagesDir.replace(/\\/g, '/').endsWith('/views') const pagePaths = getPagePaths( normalizedPagePath, pageExtensions, diff --git a/packages/next/server/load-components.ts b/packages/next/server/load-components.ts index 862834e523f2..e236a222101c 100644 --- a/packages/next/server/load-components.ts +++ b/packages/next/server/load-components.ts @@ -145,7 +145,7 @@ export async function loadComponents( undefined, rootEnabled ) - isRootPath = !!pagePath?.match(/server[/\\]root[/\\]/) + isRootPath = !!pagePath?.match(/server[/\\]views[/\\]/) } return { diff --git a/packages/next/server/root-render.tsx b/packages/next/server/root-render.tsx index 6e9af6d9f7cd..e3deaafa6891 100644 --- a/packages/next/server/root-render.tsx +++ b/packages/next/server/root-render.tsx @@ -21,6 +21,7 @@ import { FlushEffectsContext } from '../shared/lib/flush-effects' import ReactDOMServer from 'react-dom/server.browser' import { isDynamicRoute } from '../shared/lib/router/utils' import { tryGetPreviewData } from './api-utils/node' +import DefaultRootLayout from '../pages/root' export type RenderOptsPartial = { err?: Error | null @@ -330,7 +331,8 @@ export async function renderToHTML( if (!RootLayout) { // TODO: fallback to our own root layout? - throw new Error('invariant RootLayout not loaded') + // throw new Error('invariant RootLayout not loaded') + RootLayout = DefaultRootLayout } const headChildren = buildManifest.rootMainFiles.map((src) => ( diff --git a/packages/next/shared/lib/router/utils/root-paths.ts b/packages/next/shared/lib/router/utils/root-paths.ts index 02b01d911d59..d9674f4fd81e 100644 --- a/packages/next/shared/lib/router/utils/root-paths.ts +++ b/packages/next/shared/lib/router/utils/root-paths.ts @@ -1,14 +1,17 @@ -// strip `@propName` from pathname and normalize `+` to `/` +// remove (name) from pathname as it's not considered for routing export function normalizeRootPath(pathname: string) { let normalized = '' + const segments = pathname.split('/') - pathname.split('/').forEach((segment) => { - segment.split('+').forEach((subSegment) => { - const value = subSegment.split('@').shift() - if (value) { - normalized += `/${value}` - } - }) + segments.forEach((segment, index) => { + if (!segment) return + if (segment.startsWith('(') && segment.endsWith(')')) { + return + } + if (segment === 'page' && index === segments.length - 1) { + return + } + normalized += `/${segment}` }) return normalized } diff --git a/packages/next/taskfile.js b/packages/next/taskfile.js index 445c3959d431..9b7d5f19bed8 100644 --- a/packages/next/taskfile.js +++ b/packages/next/taskfile.js @@ -1891,6 +1891,7 @@ export async function pages_root(task, opts) { await task .source('pages/root.tsx') .swc('server', { dev: opts.dev, keepImportAssertions: true }) + .target('dist/pages') } export async function pages(task, opts) { diff --git a/test/e2e/views-dir/index.test.ts b/test/e2e/views-dir/index.test.ts index 6e346f4ce392..b2177850afd0 100644 --- a/test/e2e/views-dir/index.test.ts +++ b/test/e2e/views-dir/index.test.ts @@ -5,7 +5,7 @@ import path from 'path' import cheerio from 'cheerio' import webdriver from 'next-webdriver' -describe.skip('root dir', () => { +describe('root dir', () => { let next: NextInstance beforeAll(async () => { @@ -13,18 +13,11 @@ describe.skip('root dir', () => { files: { public: new FileRef(path.join(__dirname, 'app/public')), pages: new FileRef(path.join(__dirname, 'app/pages')), - root: new FileRef(path.join(__dirname, 'app/root')), - 'root.server.js': new FileRef( - path.join(__dirname, 'app/root.server.js') - ), + views: new FileRef(path.join(__dirname, 'app/views')), 'next.config.js': new FileRef( path.join(__dirname, 'app/next.config.js') ), }, - dependencies: { - react: '18.0.0-rc.2', - 'react-dom': '18.0.0-rc.2', - }, }) }) afterAll(() => next.destroy()) @@ -60,7 +53,7 @@ describe.skip('root dir', () => { // TODO: why is this routable but /should-not-serve-server.server.js it('should not include parent when not in parent directory with route in directory', async () => { - const html = await renderViaHTTP(next.url, '/dashboard/rootonly/hello') + const html = await renderViaHTTP(next.url, '/dashboard/hello') const $ = cheerio.load(html) // Should be nested in /root.js From 8dc7fab6f8e9700a04e6c6682ef4de3e3466394d Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Wed, 4 May 2022 19:55:13 -0500 Subject: [PATCH 07/11] rename rootDir -> viewsDir --- packages/next/build/entries.ts | 58 +++------ packages/next/build/index.ts | 41 +++---- packages/next/build/webpack-config.ts | 28 ++--- .../webpack/plugins/pages-manifest-plugin.ts | 4 +- packages/next/export/index.ts | 2 +- packages/next/export/worker.ts | 8 +- packages/next/lib/constants.ts | 3 +- packages/next/lib/find-pages-dir.ts | 12 +- packages/next/pages/{root.tsx => layout.tsx} | 2 +- packages/next/server/base-server.ts | 110 ++++++------------ packages/next/server/config-shared.ts | 4 +- packages/next/server/dev/hot-reloader.ts | 12 +- packages/next/server/dev/next-dev-server.ts | 46 ++++---- .../server/dev/on-demand-entry-handler.ts | 41 +++---- packages/next/server/lib/find-page-file.ts | 7 +- packages/next/server/load-components.ts | 12 +- packages/next/server/next-server.ts | 22 ++-- packages/next/server/require.ts | 4 +- .../{root-render.tsx => view-render.tsx} | 6 +- packages/next/server/web-server.ts | 2 +- packages/next/shared/lib/constants.ts | 2 +- .../shared/lib/page-path/get-page-paths.ts | 16 +-- .../utils/{root-paths.ts => view-paths.ts} | 2 +- packages/next/taskfile.js | 6 +- test/e2e/views-dir/app/next.config.js | 2 +- 25 files changed, 173 insertions(+), 279 deletions(-) rename packages/next/pages/{root.tsx => layout.tsx} (75%) rename packages/next/server/{root-render.tsx => view-render.tsx} (99%) rename packages/next/shared/lib/router/utils/{root-paths.ts => view-paths.ts} (88%) diff --git a/packages/next/build/entries.ts b/packages/next/build/entries.ts index 4b8c822ef444..1e0eacd25890 100644 --- a/packages/next/build/entries.ts +++ b/packages/next/build/entries.ts @@ -14,8 +14,7 @@ import { API_ROUTE, DOT_NEXT_ALIAS, PAGES_DIR_ALIAS, - ROOT_ALIAS, - ROOT_DIR_ALIAS, + VIEWS_DIR_ALIAS, } from '../lib/constants' import { CLIENT_STATIC_FILES_RUNTIME_AMP, @@ -40,11 +39,7 @@ type ObjectValue = T extends { [key: string]: infer V } ? V : never * special case because it is the only page where we want to preserve the RSC * server extension. */ -export function getPageFromPath( - pagePath: string, - pageExtensions: string[], - isRoot?: boolean -) { +export function getPageFromPath(pagePath: string, pageExtensions: string[]) { const extensions = pagePath.includes('/_app.server.') ? withoutRSCExtensions(pageExtensions) : pageExtensions @@ -53,9 +48,7 @@ export function getPageFromPath( pagePath.replace(new RegExp(`\\.+(${extensions.join('|')})$`), '') ) - if (!isRoot) { - page = page.replace(/\/index$/, '') - } + page = page.replace(/\/index$/, '') return page === '' ? '/' : page } @@ -63,18 +56,18 @@ export function getPageFromPath( export function createPagesMapping({ hasServerComponents, isDev, - isRoot, + isViews, pageExtensions, pagePaths, }: { hasServerComponents: boolean isDev: boolean - isRoot?: boolean + isViews?: boolean pageExtensions: string[] pagePaths: string[] }): { [page: string]: string } { const previousPages: { [key: string]: string } = {} - const pathAlias = isRoot ? ROOT_DIR_ALIAS : PAGES_DIR_ALIAS + const pathAlias = isViews ? VIEWS_DIR_ALIAS : PAGES_DIR_ALIAS const pages = pagePaths.reduce<{ [key: string]: string }>( (result, pagePath) => { // Do not process .d.ts files inside the `pages` folder @@ -82,7 +75,7 @@ export function createPagesMapping({ return result } - const pageKey = getPageFromPath(pagePath, pageExtensions, isRoot) + const pageKey = getPageFromPath(pagePath, pageExtensions) // Assume that if there's a Client Component, that there is // a matching Server Component that will map to the page. @@ -103,11 +96,7 @@ export function createPagesMapping({ previousPages[pageKey] = pagePath } - if (pageKey === 'root') { - result['root'] = normalizePathSep(join(ROOT_ALIAS, pagePath)) - } else { - result[pageKey] = normalizePathSep(join(pathAlias, pagePath)) - } + result[pageKey] = normalizePathSep(join(pathAlias, pagePath)) return result }, {} @@ -117,12 +106,7 @@ export function createPagesMapping({ // the correct source file so that HMR can work properly when a file is // added or removed. - if (isRoot) { - if (isDev) { - pages['root'] = `${ROOT_ALIAS}/root` - } else { - pages['root'] = pages['root'] || 'next/dist/pages/root' - } + if (isViews) { return pages } @@ -259,8 +243,8 @@ interface CreateEntrypointsParams { pagesDir: string previewMode: __ApiPreviewProps target: 'server' | 'serverless' | 'experimental-serverless-trace' - rootDir?: string - rootPaths?: Record + viewsDir?: string + viewPaths?: Record } export function getEdgeServerEntry(opts: { @@ -365,18 +349,18 @@ export function getClientEntry(opts: { } export async function createEntrypoints(params: CreateEntrypointsParams) { - const { config, pages, pagesDir, isDev, target, rootDir, rootPaths } = params + const { config, pages, pagesDir, isDev, target, viewsDir, viewPaths } = params const edgeServer: webpack5.EntryObject = {} const server: webpack5.EntryObject = {} const client: webpack5.EntryObject = {} const getEntryHandler = - (mappings: Record, isRoot: boolean) => + (mappings: Record, isViews: boolean) => async (page: string) => { const bundleFile = normalizePagePath(page) const clientBundlePath = posix.join('pages', bundleFile) const serverBundlePath = posix.join( - isRoot ? (bundleFile === '/root' ? './' : 'views') : 'pages', + isViews ? 'views' : 'pages', bundleFile ) @@ -387,12 +371,8 @@ export async function createEntrypoints(params: CreateEntrypointsParams) { return absolutePagePath.replace(PAGES_DIR_ALIAS, pagesDir) } - if (absolutePagePath.startsWith(ROOT_DIR_ALIAS) && rootDir) { - return absolutePagePath.replace(ROOT_DIR_ALIAS, rootDir) - } - - if (absolutePagePath.startsWith(ROOT_ALIAS) && rootDir) { - return absolutePagePath.replace(ROOT_ALIAS, join(rootDir, '..')) + if (absolutePagePath.startsWith(VIEWS_DIR_ALIAS) && viewsDir) { + return absolutePagePath.replace(VIEWS_DIR_ALIAS, viewsDir) } return require.resolve(absolutePagePath) @@ -432,9 +412,9 @@ export async function createEntrypoints(params: CreateEntrypointsParams) { }) } - if (rootDir && rootPaths) { - const entryHandler = getEntryHandler(rootPaths, true) - await Promise.all(Object.keys(rootPaths).map(entryHandler)) + if (viewsDir && viewPaths) { + const entryHandler = getEntryHandler(viewPaths, true) + await Promise.all(Object.keys(viewPaths).map(entryHandler)) } await Promise.all(Object.keys(pages).map(getEntryHandler(pages, false))) diff --git a/packages/next/build/index.ts b/packages/next/build/index.ts index fa4aaad02ecc..d833480e0691 100644 --- a/packages/next/build/index.ts +++ b/packages/next/build/index.ts @@ -207,9 +207,9 @@ export default async function build( setGlobal('telemetry', telemetry) const publicDir = path.join(dir, 'public') - const { pages: pagesDir, root: rootDir } = findPagesDir( + const { pages: pagesDir, views: viewsDir } = findPagesDir( dir, - config.experimental.rootDir + config.experimental.viewsDir ) const hasPublicDir = await fileExists(publicDir) @@ -245,7 +245,7 @@ export default async function build( .traceAsyncFn(() => verifyTypeScriptSetup( dir, - [pagesDir, rootDir].filter(Boolean) as string[], + [pagesDir, viewsDir].filter(Boolean) as string[], !ignoreTypeScriptErrors, config, cacheDir @@ -311,24 +311,17 @@ export default async function build( ) ) - let rootPaths: string[] | undefined + let viewPaths: string[] | undefined - if (rootDir) { - rootPaths = await nextBuildSpan - .traceChild('collect-root-paths') + if (viewsDir) { + viewPaths = await nextBuildSpan + .traceChild('collect-view-paths') .traceAsyncFn(() => recursiveReadDir( - rootDir, + viewsDir, new RegExp(`\\.(?:${config.pageExtensions.join('|')})$`) ) ) - - const rootFile = await findPageFile( - path.join(rootDir, '..'), - 'root', - config.pageExtensions - ) - if (rootFile) rootPaths.push(rootFile) } // needed for static exporting since we want to replace with HTML // files @@ -353,17 +346,17 @@ export default async function build( }) ) - let mappedRootPaths: ReturnType | undefined + let mappedViewPaths: ReturnType | undefined - if (rootPaths && rootDir) { - mappedRootPaths = nextBuildSpan - .traceChild('create-root-mapping') + if (viewPaths && viewsDir) { + mappedViewPaths = nextBuildSpan + .traceChild('create-views-mapping') .traceFn(() => createPagesMapping({ - pagePaths: rootPaths!, + pagePaths: viewPaths!, hasServerComponents, isDev: false, - isRoot: true, + isViews: true, pageExtensions: config.pageExtensions, }) ) @@ -381,8 +374,8 @@ export default async function build( pagesDir, previewMode: previewProps, target, - rootDir, - rootPaths: mappedRootPaths, + viewsDir, + viewPaths: mappedViewPaths, }) ) @@ -688,7 +681,7 @@ export default async function build( rewrites, runWebpackSpan, target, - rootDir, + viewsDir, } const configs = await runWebpackSpan diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index 2a20939e80b2..636bbf44435c 100644 --- a/packages/next/build/webpack-config.ts +++ b/packages/next/build/webpack-config.ts @@ -10,8 +10,7 @@ import { NEXT_PROJECT_ROOT, NEXT_PROJECT_ROOT_DIST_CLIENT, PAGES_DIR_ALIAS, - ROOT_ALIAS, - ROOT_DIR_ALIAS, + VIEWS_DIR_ALIAS, } from '../lib/constants' import { fileExists } from '../lib/file-exists' import { CustomRoutes } from '../lib/load-custom-routes.js' @@ -315,7 +314,7 @@ export default async function getBaseWebpackConfig( rewrites, runWebpackSpan, target = 'server', - rootDir, + viewsDir, }: { buildId: string config: NextConfigComplete @@ -329,7 +328,7 @@ export default async function getBaseWebpackConfig( rewrites: CustomRoutes['rewrites'] runWebpackSpan: Span target?: string - rootDir?: string + viewsDir?: string } ): Promise { const isClient = compilerType === 'client' @@ -542,7 +541,7 @@ export default async function getBaseWebpackConfig( ) ) .replace(/\\/g, '/'), - ...(config.experimental.rootDir + ...(config.experimental.viewsDir ? { [CLIENT_STATIC_FILES_RUNTIME_MAIN_ROOT]: `./` + @@ -607,16 +606,6 @@ export default async function getBaseWebpackConfig( }, [] as string[]), `next/dist/pages/_document.js`, ] - - if (config.experimental.rootDir && rootDir) { - customRootAliases[`${ROOT_ALIAS}/root`] = [ - ...config.pageExtensions.reduce((prev, ext) => { - prev.push(path.join(rootDir, `root.${ext}`)) - return prev - }, [] as string[]), - 'next/dist/pages/root.js', - ] - } } const resolveConfig = { @@ -651,10 +640,9 @@ export default async function getBaseWebpackConfig( ...customRootAliases, [PAGES_DIR_ALIAS]: pagesDir, - ...(rootDir + ...(viewsDir ? { - [ROOT_DIR_ALIAS]: rootDir, - [ROOT_ALIAS]: path.join(rootDir, '..'), + [VIEWS_DIR_ALIAS]: viewsDir, } : {}), [DOT_NEXT_ALIAS]: distDir, @@ -1559,7 +1547,7 @@ export default async function getBaseWebpackConfig( serverless: isLikeServerless, dev, isEdgeRuntime: isEdgeServer, - rootEnabled: !!config.experimental.rootDir, + rootEnabled: !!config.experimental.viewsDir, }), // MiddlewarePlugin should be after DefinePlugin so NEXT_PUBLIC_* // replacement is done before its process.env.* handling @@ -1570,7 +1558,7 @@ export default async function getBaseWebpackConfig( rewrites, isDevFallback, exportRuntime: hasConcurrentFeatures, - rootEnabled: !!config.experimental.rootDir, + rootEnabled: !!config.experimental.viewsDir, }), new ProfilingPlugin({ runWebpackSpan }), config.optimizeFonts && diff --git a/packages/next/build/webpack/plugins/pages-manifest-plugin.ts b/packages/next/build/webpack/plugins/pages-manifest-plugin.ts index 0ab61944adf7..4cb3e3640511 100644 --- a/packages/next/build/webpack/plugins/pages-manifest-plugin.ts +++ b/packages/next/build/webpack/plugins/pages-manifest-plugin.ts @@ -1,7 +1,7 @@ import { webpack, sources } from 'next/dist/compiled/webpack/webpack' import { PAGES_MANIFEST, - ROOT_PATHS_MANIFEST, + VIEW_PATHS_MANIFEST, } from '../../../shared/lib/constants' import getRouteFromEntrypoint from '../../../server/get-route-from-entrypoint' import { normalizePathSep } from '../../../shared/lib/page-path/normalize-path-sep' @@ -106,7 +106,7 @@ export default class PagesManifestPlugin implements webpack.Plugin { if (this.rootEnabled) { assets[ - `${!this.dev && !this.isEdgeRuntime ? '../' : ''}` + ROOT_PATHS_MANIFEST + `${!this.dev && !this.isEdgeRuntime ? '../' : ''}` + VIEW_PATHS_MANIFEST ] = new sources.RawSource( JSON.stringify( { diff --git a/packages/next/export/index.ts b/packages/next/export/index.ts index c6c8e2fef7b3..366a00e4e1ee 100644 --- a/packages/next/export/index.ts +++ b/packages/next/export/index.ts @@ -581,7 +581,7 @@ export default async function exportApp( outDir, pagesDataDir, renderOpts, - rootDir: nextConfig.experimental.rootDir, + viewsDir: nextConfig.experimental.viewsDir, serverRuntimeConfig, subFolders, buildExport: options.buildExport, diff --git a/packages/next/export/worker.ts b/packages/next/export/worker.ts index 8934c0d441b4..e8db5c26e467 100644 --- a/packages/next/export/worker.ts +++ b/packages/next/export/worker.ts @@ -60,7 +60,7 @@ interface ExportPageInput { parentSpanId: any httpAgentOptions: NextConfigComplete['httpAgentOptions'] serverComponents?: boolean - rootDir?: boolean + viewsDir?: boolean } interface ExportPageResults { @@ -85,7 +85,7 @@ interface RenderOpts { locale?: string defaultLocale?: string trailingSlash?: boolean - rootDir?: boolean + viewsDir?: boolean } type ComponentModule = ComponentType<{}> & { @@ -99,7 +99,7 @@ export default async function exportPage({ pathMap, distDir, outDir, - rootDir, + viewsDir, pagesDataDir, renderOpts, buildExport, @@ -270,7 +270,7 @@ export default async function exportPage({ page, serverless, serverComponents, - rootDir + viewsDir ) const ampState = { ampFirst: pageConfig?.amp === true, diff --git a/packages/next/lib/constants.ts b/packages/next/lib/constants.ts index ea8e0690e117..354b62581704 100644 --- a/packages/next/lib/constants.ts +++ b/packages/next/lib/constants.ts @@ -25,8 +25,7 @@ export const MIDDLEWARE_ROUTE = /_middleware$/ // we have to use a private alias export const PAGES_DIR_ALIAS = 'private-next-pages' export const DOT_NEXT_ALIAS = 'private-dot-next' -export const ROOT_DIR_ALIAS = 'private-next-root-dir' -export const ROOT_ALIAS = 'private-next-root' +export const VIEWS_DIR_ALIAS = 'private-next-views-dir' export const PUBLIC_DIR_MIDDLEWARE_CONFLICT = `You can not have a '_next' folder inside of your public folder. This conflicts with the internal '/_next' route. https://nextjs.org/docs/messages/public-next-folder-conflict` diff --git a/packages/next/lib/find-pages-dir.ts b/packages/next/lib/find-pages-dir.ts index 8c8d7e36d84b..26a6799687ea 100644 --- a/packages/next/lib/find-pages-dir.ts +++ b/packages/next/lib/find-pages-dir.ts @@ -23,13 +23,13 @@ function findDir(dir: string, name: 'pages' | 'views'): string | null { export function findPagesDir( dir: string, - root?: boolean -): { pages: string; root?: string } { + views?: boolean +): { pages: string; views?: string } { const pagesDir = findDir(dir, 'pages') - let rootDir: undefined | string + let viewsDir: undefined | string - if (root) { - rootDir = findDir(dir, 'views') || undefined + if (views) { + viewsDir = findDir(dir, 'views') || undefined } // TODO: allow "root" dir without pages dir @@ -41,6 +41,6 @@ export function findPagesDir( return { pages: pagesDir, - root: rootDir, + views: viewsDir, } } diff --git a/packages/next/pages/root.tsx b/packages/next/pages/layout.tsx similarity index 75% rename from packages/next/pages/root.tsx rename to packages/next/pages/layout.tsx index 5f972e688ce6..259bb4e88df6 100644 --- a/packages/next/pages/root.tsx +++ b/packages/next/pages/layout.tsx @@ -5,7 +5,7 @@ export type RootProps = { bodyChildren: any } -export default function Root({ headChildren, bodyChildren }: RootProps) { +export default function RootLayout({ headChildren, bodyChildren }: RootProps) { return ( diff --git a/packages/next/server/base-server.ts b/packages/next/server/base-server.ts index d6aaab3464d9..d80fd6fde386 100644 --- a/packages/next/server/base-server.ts +++ b/packages/next/server/base-server.ts @@ -70,7 +70,7 @@ import { createHeaderRoute, createRedirectRoute } from './server-route-utils' import { PrerenderManifest } from '../build' import { ImageConfigComplete } from '../shared/lib/image-config' import { replaceBasePath } from './router-utils' -import { normalizeRootPath } from '../shared/lib/router/utils/root-paths' +import { normalizeViewPath } from '../shared/lib/router/utils/view-paths' export type FindComponentsResult = { components: LoadComponentsReturnType @@ -142,7 +142,7 @@ export default abstract class Server { protected publicDir: string protected hasStaticDir: boolean protected pagesManifest?: PagesManifest - protected rootPathsManifest?: PagesManifest + protected viewPathsManifest?: PagesManifest protected buildId: string protected minimalMode: boolean protected renderOpts: { @@ -182,7 +182,7 @@ export default abstract class Server { private responseCache: ResponseCache protected router: Router protected dynamicRoutes?: DynamicRoutes - protected rootPathRoutes?: Record + protected viewPathRoutes?: Record protected customRoutes: CustomRoutes protected middlewareManifest?: MiddlewareManifest protected middleware?: RoutingItem[] @@ -193,7 +193,7 @@ export default abstract class Server { protected abstract getPublicDir(): string protected abstract getHasStaticDir(): boolean protected abstract getPagesManifest(): PagesManifest | undefined - protected abstract getRootPathsManifest(): PagesManifest | undefined + protected abstract getViewPathsManifest(): PagesManifest | undefined protected abstract getBuildId(): string protected abstract generatePublicRoutes(): Route[] protected abstract generateImageRoutes(): Route[] @@ -356,7 +356,7 @@ export default abstract class Server { }) this.pagesManifest = this.getPagesManifest() - this.rootPathsManifest = this.getRootPathsManifest() + this.viewPathsManifest = this.getViewPathsManifest() this.middlewareManifest = this.getMiddlewareManifest() this.customRoutes = this.getCustomRoutes() @@ -876,7 +876,7 @@ export default abstract class Server { const { useFileSystemPublicRoutes } = this.nextConfig if (useFileSystemPublicRoutes) { - this.rootPathRoutes = this.getRootPathRoutes() + this.viewPathRoutes = this.getViewPathRoutes() this.dynamicRoutes = this.getDynamicRoutes() if (!this.minimalMode) { this.middleware = this.getMiddleware() @@ -898,30 +898,6 @@ export default abstract class Server { } } - protected isRoutableRootPath(pathname: string): boolean { - if (this.rootPathRoutes) { - const paths = Object.keys(this.rootPathRoutes) - - /** - * a root path is only routable if - * 1. has root/hello.js and no root/hello/ folder - * 2. has root/hello.js and a root/hello/index.js - */ - const hasFolderIndex = this.rootPathRoutes[`${pathname}/index`] - const hasFolder = paths.some((path) => { - return path.startsWith(`${pathname}/`) - }) - - if (hasFolder && hasFolderIndex) { - return true - } - if (!hasFolder && this.rootPathRoutes[pathname]) { - return true - } - } - return false - } - protected async hasPage(pathname: string): Promise { let found = false try { @@ -995,7 +971,7 @@ export default abstract class Server { return getSortedRoutes( [ - ...Object.keys(this.rootPathRoutes || {}), + ...Object.keys(this.viewPathRoutes || {}), ...Object.keys(this.pagesManifest!), ].map( (page) => @@ -1013,20 +989,20 @@ export default abstract class Server { .filter((item): item is RoutingItem => Boolean(item)) } - protected getRootPathRoutes(): Record { - const rootPathRoutes: Record = {} + protected getViewPathRoutes(): Record { + const viewPathRoutes: Record = {} - Object.keys(this.rootPathsManifest || {}).forEach((entry) => { - rootPathRoutes[normalizeRootPath(entry)] = entry + Object.keys(this.viewPathsManifest || {}).forEach((entry) => { + viewPathRoutes[normalizeViewPath(entry)] = entry }) - return rootPathRoutes + return viewPathRoutes } - protected getRootPathLayouts(pathname: string): string[] { + protected getViewPathLayouts(pathname: string): string[] { const layoutPaths: string[] = [] - if (this.rootPathRoutes) { - const paths = Object.values(this.rootPathRoutes) + if (this.viewPathRoutes) { + const paths = Object.values(this.viewPathRoutes) const parts = pathname.split('/').filter(Boolean) for (let i = 1; i < parts.length; i++) { @@ -1037,7 +1013,7 @@ export default abstract class Server { } } - if (this.rootPathRoutes['/layout']) { + if (this.viewPathRoutes['/layout']) { layoutPaths.unshift('/layout') } } @@ -1757,41 +1733,31 @@ export default abstract class Server { delete query._nextBubbleNoFallback // map the route to the actual bundle name e.g. // `/dashboard/rootonly/hello` -> `/dashboard+rootonly/hello` - const getOriginalRootPath = (rootPath: string) => { - if (this.nextConfig.experimental.rootDir) { - const originalRootPath = - this.rootPathRoutes?.[`${rootPath}/index`] || - this.rootPathRoutes?.[`${rootPath}`] + const getOriginalViewPath = (viewPath: string) => { + if (this.nextConfig.experimental.viewsDir) { + const originalViewPath = + this.viewPathRoutes?.[`${viewPath}/index`] || + this.viewPathRoutes?.[`${viewPath}`] - if (!originalRootPath) { + if (!originalViewPath) { return null } - // TODO: isRoutable check no longer needed as it will only - // find an originalRootPath if it is routable now - // const isRoutable = this.isRoutableRootPath(rootPath) - - // 404 when layout is hit and this isn't a routable path - // e.g. root/hello.js with root/hello/another.js but - // no root/hello/index.js - // if (!isRoutable) { - // return '' - // } - return originalRootPath + return originalViewPath } return null } - const gatherRootLayouts = async ( - rootPath: string, + const gatherViewLayouts = async ( + viewPath: string, result: FindComponentsResult ): Promise => { - const layoutPaths = this.getRootPathLayouts(rootPath) - result.components.rootLayouts = await Promise.all( + const layoutPaths = this.getViewPathLayouts(viewPath) + result.components.viewLayouts = await Promise.all( layoutPaths.map(async (path) => { const layoutRes = await this.findPageComponents(path) return { - isRoot: path === '/layout', + isRootLayout: path === '/layout', Component: layoutRes?.components.Component!, getStaticProps: layoutRes?.components.getStaticProps, getServerSideProps: layoutRes?.components.getServerSideProps, @@ -1804,16 +1770,16 @@ export default abstract class Server { // Ensure a request to the URL /accounts/[id] will be treated as a dynamic // route correctly and not loaded immediately without parsing params. if (!isDynamicRoute(pathname)) { - const rootPath = getOriginalRootPath(pathname) + const viewPath = getOriginalViewPath(pathname) - if (typeof rootPath === 'string') { - page = rootPath + if (typeof viewPath === 'string') { + page = viewPath } const result = await this.findPageComponents(page, query) if (result) { try { - if (result.components.isRootPath) { - await gatherRootLayouts(page, result) + if (result.components.isViewPath) { + await gatherViewLayouts(page, result) } return await this.renderToResponseWithComponents(ctx, result) } catch (err) { @@ -1833,10 +1799,10 @@ export default abstract class Server { continue } page = dynamicRoute.page - const rootPath = getOriginalRootPath(page) + const viewPath = getOriginalViewPath(page) - if (typeof rootPath === 'string') { - page = rootPath + if (typeof viewPath === 'string') { + page = viewPath } const dynamicRouteResult = await this.findPageComponents( @@ -1846,8 +1812,8 @@ export default abstract class Server { ) if (dynamicRouteResult) { try { - if (dynamicRouteResult.components.isRootPath) { - await gatherRootLayouts(page, dynamicRouteResult) + if (dynamicRouteResult.components.isViewPath) { + await gatherViewLayouts(page, dynamicRouteResult) } return await this.renderToResponseWithComponents( { diff --git a/packages/next/server/config-shared.ts b/packages/next/server/config-shared.ts index ebde47189cc0..afb3f4275750 100644 --- a/packages/next/server/config-shared.ts +++ b/packages/next/server/config-shared.ts @@ -95,7 +95,7 @@ export interface ExperimentalConfig { scrollRestoration?: boolean externalDir?: boolean conformance?: boolean - rootDir?: boolean + viewsDir?: boolean amp?: { optimizer?: any validator?: string @@ -492,7 +492,7 @@ export const defaultConfig: NextConfig = { swcFileReading: true, craCompat: false, esmExternals: true, - rootDir: false, + viewsDir: false, // default to 50MB limit isrMemoryCacheSize: 50 * 1024 * 1024, serverComponents: false, diff --git a/packages/next/server/dev/hot-reloader.ts b/packages/next/server/dev/hot-reloader.ts index 4a71f8bfb5cd..b0035377844b 100644 --- a/packages/next/server/dev/hot-reloader.ts +++ b/packages/next/server/dev/hot-reloader.ts @@ -168,7 +168,7 @@ export default class HotReloader { private fallbackWatcher: any private hotReloaderSpan: Span private pagesMapping: { [key: string]: string } = {} - private rootDir?: string + private viewsDir?: string constructor( dir: string, @@ -179,7 +179,7 @@ export default class HotReloader { buildId, previewProps, rewrites, - rootDir, + viewsDir, }: { config: NextConfigComplete pagesDir: string @@ -187,14 +187,14 @@ export default class HotReloader { buildId: string previewProps: __ApiPreviewProps rewrites: CustomRoutes['rewrites'] - rootDir?: string + viewsDir?: string } ) { this.buildId = buildId this.dir = dir this.middlewares = [] this.pagesDir = pagesDir - this.rootDir = rootDir + this.viewsDir = viewsDir this.distDir = distDir this.clientStats = null this.serverStats = null @@ -427,7 +427,7 @@ export default class HotReloader { pagesDir: this.pagesDir, rewrites: this.rewrites, runWebpackSpan: this.hotReloaderSpan, - rootDir: this.rootDir, + viewsDir: this.viewsDir, } return webpackConfigSpan @@ -839,7 +839,7 @@ export default class HotReloader { multiCompiler, watcher: this.watcher, pagesDir: this.pagesDir, - rootDir: this.rootDir, + viewsDir: this.viewsDir, nextConfig: this.config, ...(this.config.onDemandEntries as { maxInactiveAge: number diff --git a/packages/next/server/dev/next-dev-server.ts b/packages/next/server/dev/next-dev-server.ts index 3a855aa3c624..7a5c28597ddd 100644 --- a/packages/next/server/dev/next-dev-server.ts +++ b/packages/next/server/dev/next-dev-server.ts @@ -66,7 +66,7 @@ import { isCustomErrorPage, isReservedPage } from '../../build/utils' import { NodeNextResponse, NodeNextRequest } from '../base-http/node' import { getPageRuntime, invalidatePageRuntimeCache } from '../../build/entries' import { normalizePathSep } from '../../shared/lib/page-path/normalize-path-sep' -import { normalizeRootPath } from '../../shared/lib/router/utils/root-paths' +import { normalizeViewPath } from '../../shared/lib/router/utils/view-paths' // Load ReactDevOverlay only when needed let ReactDevOverlayImpl: React.FunctionComponent @@ -98,7 +98,7 @@ export default class DevServer extends Server { protected sortedRoutes?: string[] private addedUpgradeListener = false private pagesDir: string - private rootDir?: string + private viewsDir?: string protected staticPathsWorker?: { [key: string]: any } & { loadStaticPaths: typeof import('./static-paths-worker').loadStaticPaths @@ -179,12 +179,12 @@ export default class DevServer extends Server { this.isCustomServer = !options.isNextDevCommand // TODO: hot-reload root/pages dirs? - const { pages: pagesDir, root: rootDir } = findPagesDir( + const { pages: pagesDir, views: viewsDir } = findPagesDir( this.dir, - this.nextConfig.experimental.rootDir + this.nextConfig.experimental.viewsDir ) this.pagesDir = pagesDir - this.rootDir = rootDir + this.viewsDir = viewsDir } protected getBuildId(): string { @@ -267,8 +267,8 @@ export default class DevServer extends Server { let wp = (this.webpackWatcher = new Watchpack()) const toWatch = [this.pagesDir!] - if (this.rootDir) { - toWatch.push(this.rootDir) + if (this.viewsDir) { + toWatch.push(this.viewsDir) } wp.watch([], toWatch, 0) @@ -276,7 +276,7 @@ export default class DevServer extends Server { const routedMiddleware = [] const routedPages: string[] = [] const knownFiles = wp.getTimeInfoEntries() - const rootPaths: Record = {} + const viewPaths: Record = {} const ssrMiddleware = new Set() for (const [fileName, { accuracy, safeTime }] of knownFiles) { @@ -284,17 +284,17 @@ export default class DevServer extends Server { continue } let pageName: string = '' - let isRootPath = false + let isViewPath = false if ( - this.rootDir && + this.viewsDir && normalizePathSep(fileName).startsWith( - normalizePathSep(this.rootDir) + normalizePathSep(this.viewsDir) ) ) { - isRootPath = true + isViewPath = true pageName = absolutePathToPage( - this.rootDir, + this.viewsDir, fileName, this.nextConfig.pageExtensions, false @@ -307,11 +307,11 @@ export default class DevServer extends Server { ) } - if (isRootPath) { + if (isViewPath) { // TODO: should only routes ending in /index.js be route-able? const originalPageName = pageName - pageName = normalizeRootPath(pageName) - rootPaths[pageName] = originalPageName + pageName = normalizeViewPath(pageName) + viewPaths[pageName] = originalPageName if (routedPages.includes(pageName)) { continue @@ -348,7 +348,7 @@ export default class DevServer extends Server { routedPages.push(pageName) } - this.rootPathRoutes = rootPaths + this.viewPathRoutes = viewPaths this.middleware = getSortedRoutes(routedMiddleware).map((page) => ({ match: getRouteMatcher( getMiddlewareRegex(page, !ssrMiddleware.has(page)) @@ -410,7 +410,7 @@ export default class DevServer extends Server { setGlobal('phase', PHASE_DEVELOPMENT_SERVER) await verifyTypeScriptSetup( this.dir, - [this.pagesDir!, this.rootDir].filter(Boolean) as string[], + [this.pagesDir!, this.viewsDir].filter(Boolean) as string[], false, this.nextConfig ) @@ -437,7 +437,7 @@ export default class DevServer extends Server { previewProps: this.getPreviewProps(), buildId: this.buildId, rewrites, - rootDir: this.rootDir, + viewsDir: this.viewsDir, }) await super.prepare() await this.addExportPathMapRoutes() @@ -495,10 +495,10 @@ export default class DevServer extends Server { return false } - // check rootDir first if enabled - if (this.rootDir) { + // check viewsDir first if enabled + if (this.viewsDir) { const pageFile = await findPageFile( - this.rootDir, + this.viewsDir, normalizedPath, this.nextConfig.pageExtensions ) @@ -786,7 +786,7 @@ export default class DevServer extends Server { return undefined } - protected getRootPathsManifest(): undefined { + protected getViewPathsManifest(): undefined { return undefined } diff --git a/packages/next/server/dev/on-demand-entry-handler.ts b/packages/next/server/dev/on-demand-entry-handler.ts index 48fa63957e5d..116136adb030 100644 --- a/packages/next/server/dev/on-demand-entry-handler.ts +++ b/packages/next/server/dev/on-demand-entry-handler.ts @@ -54,7 +54,7 @@ export function onDemandEntryHandler({ nextConfig, pagesBufferLength, pagesDir, - rootDir, + viewsDir, watcher, }: { maxInactiveAge: number @@ -62,7 +62,7 @@ export function onDemandEntryHandler({ nextConfig: NextConfigComplete pagesBufferLength: number pagesDir: string - rootDir?: string + viewsDir?: string watcher: any }) { const invalidator = new Invalidator(watcher) @@ -101,7 +101,7 @@ export function onDemandEntryHandler({ return invalidator.doneBuilding() } const [clientStats, serverStats, edgeServerStats] = multiStats.stats - const root = !!rootDir + const root = !!viewsDir const pagePaths = [ ...getPagePathsFromEntrypoints( 'client', @@ -182,7 +182,7 @@ export function onDemandEntryHandler({ pagesDir, page, nextConfig.pageExtensions, - rootDir + viewsDir ) let entryAdded = false @@ -340,23 +340,18 @@ async function findPagePathData( pagesDir: string, page: string, extensions: string[], - rootDir?: string + viewsDir?: string ) { const normalizedPagePath = tryToNormalizePagePath(page) let pagePath: string | null = null - let isRoot = false - const isRootFile = rootDir && normalizedPagePath === '/_root' - - // check rootDir first - if (rootDir) { - pagePath = await findPageFile( - join(rootDir, isRootFile ? '..' : ''), - isRootFile ? 'root' : normalizedPagePath, - extensions - ) + let isView = false + + // check viewsDir first + if (viewsDir) { + pagePath = await findPageFile(viewsDir, normalizedPagePath, extensions) if (pagePath) { - isRoot = true + isView = true } } @@ -366,19 +361,11 @@ async function findPagePathData( if (pagePath !== null) { const pageUrl = ensureLeadingSlash( - removePagePathTail(normalizePathSep(pagePath), extensions, !isRoot) + removePagePathTail(normalizePathSep(pagePath), extensions, !isView) ) const bundleFile = normalizePagePath(pageUrl) - let bundlePath - let absolutePagePath - - if (isRootFile) { - bundlePath = 'root' - absolutePagePath = join(rootDir!, '..', pagePath) - } else { - bundlePath = posix.join(isRoot ? 'views' : 'pages', bundleFile) - absolutePagePath = join(isRoot ? rootDir! : pagesDir, pagePath) - } + const bundlePath = posix.join(isView ? 'views' : 'pages', bundleFile) + const absolutePagePath = join(isView ? viewsDir! : pagesDir, pagePath) return { absolutePagePath, diff --git a/packages/next/server/lib/find-page-file.ts b/packages/next/server/lib/find-page-file.ts index 517931fbde2a..b7e60c2b7dd5 100644 --- a/packages/next/server/lib/find-page-file.ts +++ b/packages/next/server/lib/find-page-file.ts @@ -20,12 +20,7 @@ export async function findPageFile( normalizedPagePath: string, pageExtensions: string[] ): Promise { - const isRootPaths = pagesDir.replace(/\\/g, '/').endsWith('/views') - const pagePaths = getPagePaths( - normalizedPagePath, - pageExtensions, - isRootPaths - ) + const pagePaths = getPagePaths(normalizedPagePath, pageExtensions) const [existingPath, ...others] = ( await Promise.all( pagePaths.map(async (path) => diff --git a/packages/next/server/load-components.ts b/packages/next/server/load-components.ts index e236a222101c..3b03250be45d 100644 --- a/packages/next/server/load-components.ts +++ b/packages/next/server/load-components.ts @@ -40,9 +40,9 @@ export type LoadComponentsReturnType = { ComponentMod: any AppMod: any AppServerMod: any - isRootPath?: boolean - rootLayouts?: Array<{ - isRoot?: boolean + isViewPath?: boolean + viewLayouts?: Array<{ + isRootLayout?: boolean Component: NextComponentType getStaticProps?: GetStaticProps getServerSideProps?: GetServerSideProps @@ -134,7 +134,7 @@ export async function loadComponents( const { getServerSideProps, getStaticProps, getStaticPaths } = ComponentMod - let isRootPath = false + let isViewPath = false if (rootEnabled) { const pagePath = getPagePath( @@ -145,7 +145,7 @@ export async function loadComponents( undefined, rootEnabled ) - isRootPath = !!pagePath?.match(/server[/\\]views[/\\]/) + isViewPath = !!pagePath?.match(/server[/\\]views[/\\]/) } return { @@ -162,6 +162,6 @@ export async function loadComponents( getStaticProps, getStaticPaths, serverComponentManifest, - isRootPath, + isViewPath, } } diff --git a/packages/next/server/next-server.ts b/packages/next/server/next-server.ts index d0b527aea940..47764d6a06cb 100644 --- a/packages/next/server/next-server.ts +++ b/packages/next/server/next-server.ts @@ -31,7 +31,7 @@ import { ROUTES_MANIFEST, MIDDLEWARE_FLIGHT_MANIFEST, CLIENT_PUBLIC_FILES_PATH, - ROOT_PATHS_MANIFEST, + VIEW_PATHS_MANIFEST, } from '../shared/lib/constants' import { recursiveReadDirSync } from './lib/recursive-readdir-sync' import { format as formatUrl, UrlWithParsedQuery } from 'url' @@ -46,7 +46,7 @@ import { getExtension, serveStatic } from './serve-static' import { ParsedUrlQuery } from 'querystring' import { apiResolver } from './api-utils/node' import { RenderOpts, renderToHTML } from './render' -import { renderToHTML as rootRenderToHTML } from './root-render' +import { renderToHTML as viewRenderToHTML } from './view-render' import { ParsedUrl, parseUrl } from '../shared/lib/router/utils/parse-url' import * as Log from '../build/output/log' @@ -159,13 +159,13 @@ export default class NextNodeServer extends BaseServer { return require(join(this.serverDistDir, PAGES_MANIFEST)) } - protected getRootPathsManifest(): PagesManifest | undefined { - if (this.nextConfig.experimental.rootDir) { - const rootPathsManifestPath = join( + protected getViewPathsManifest(): PagesManifest | undefined { + if (this.nextConfig.experimental.viewsDir) { + const viewPathsManifestPath = join( this.serverDistDir, - ROOT_PATHS_MANIFEST + VIEW_PATHS_MANIFEST ) - return require(rootPathsManifestPath) + return require(viewPathsManifestPath) } } @@ -584,8 +584,8 @@ export default class NextNodeServer extends BaseServer { // https://github.com/vercel/next.js/blob/df7cbd904c3bd85f399d1ce90680c0ecf92d2752/packages/next/server/render.tsx#L947-L952 renderOpts.serverComponentManifest = this.serverComponentManifest - if (renderOpts.isRootPath) { - return rootRenderToHTML( + if (renderOpts.isViewPath) { + return viewRenderToHTML( req.originalRequest, res.originalResponse, pathname, @@ -642,7 +642,7 @@ export default class NextNodeServer extends BaseServer { this._isLikeServerless, this.renderOpts.dev, locales, - this.nextConfig.experimental.rootDir + this.nextConfig.experimental.viewsDir ) } @@ -673,7 +673,7 @@ export default class NextNodeServer extends BaseServer { pagePath!, !this.renderOpts.dev && this._isLikeServerless, this.renderOpts.serverComponents, - this.nextConfig.experimental.rootDir + this.nextConfig.experimental.viewsDir ) if ( diff --git a/packages/next/server/require.ts b/packages/next/server/require.ts index 3205c04d624d..c5bebb5aca48 100644 --- a/packages/next/server/require.ts +++ b/packages/next/server/require.ts @@ -6,7 +6,7 @@ import { PAGES_MANIFEST, SERVER_DIRECTORY, SERVERLESS_DIRECTORY, - ROOT_PATHS_MANIFEST, + VIEW_PATHS_MANIFEST, } from '../shared/lib/constants' import { normalizeLocalePath } from '../shared/lib/i18n/normalize-locale-path' import { normalizePagePath } from '../shared/lib/page-path/normalize-page-path' @@ -39,7 +39,7 @@ export function getPagePath( if (page === '/_root') { return join(serverBuildPath, 'root.js') } - rootPathsManifest = require(join(serverBuildPath, ROOT_PATHS_MANIFEST)) + rootPathsManifest = require(join(serverBuildPath, VIEW_PATHS_MANIFEST)) } const pagesManifest = require(join( serverBuildPath, diff --git a/packages/next/server/root-render.tsx b/packages/next/server/view-render.tsx similarity index 99% rename from packages/next/server/root-render.tsx rename to packages/next/server/view-render.tsx index e3deaafa6891..43b21cb77ca1 100644 --- a/packages/next/server/root-render.tsx +++ b/packages/next/server/view-render.tsx @@ -21,7 +21,7 @@ import { FlushEffectsContext } from '../shared/lib/flush-effects' import ReactDOMServer from 'react-dom/server.browser' import { isDynamicRoute } from '../shared/lib/router/utils' import { tryGetPreviewData } from './api-utils/node' -import DefaultRootLayout from '../pages/root' +import DefaultRootLayout from '../pages/layout' export type RenderOptsPartial = { err?: Error | null @@ -216,7 +216,7 @@ export async function renderToHTML( const hasConcurrentFeatures = !!runtime const pageIsDynamic = isDynamicRoute(pathname) - const layouts = renderOpts.rootLayouts || [] + const layouts = renderOpts.viewLayouts || [] layouts.push({ Component: renderOpts.Component, @@ -243,7 +243,7 @@ export async function renderToHTML( const dataCacheKey = i.toString() const layout = layouts[i] - if (layout.isRoot) { + if (layout.isRootLayout) { RootLayout = layout.Component continue } diff --git a/packages/next/server/web-server.ts b/packages/next/server/web-server.ts index ca37bbebfbb1..4747f91ca122 100644 --- a/packages/next/server/web-server.ts +++ b/packages/next/server/web-server.ts @@ -103,7 +103,7 @@ export default class NextWebServer extends BaseServer { [this.serverOptions.webServerConfig.page]: '', } } - protected getRootPathsManifest() { + protected getViewPathsManifest() { return { [this.serverOptions.webServerConfig.page]: '', } diff --git a/packages/next/shared/lib/constants.ts b/packages/next/shared/lib/constants.ts index ab3193f05b3d..8c17e406a3e7 100644 --- a/packages/next/shared/lib/constants.ts +++ b/packages/next/shared/lib/constants.ts @@ -4,7 +4,7 @@ export const PHASE_PRODUCTION_SERVER = 'phase-production-server' export const PHASE_DEVELOPMENT_SERVER = 'phase-development-server' export const PHASE_TEST = 'phase-test' export const PAGES_MANIFEST = 'pages-manifest.json' -export const ROOT_PATHS_MANIFEST = 'root-paths-manifest.json' +export const VIEW_PATHS_MANIFEST = 'view-paths-manifest.json' export const BUILD_MANIFEST = 'build-manifest.json' export const EXPORT_MARKER = 'export-marker.json' export const EXPORT_DETAIL = 'export-detail.json' diff --git a/packages/next/shared/lib/page-path/get-page-paths.ts b/packages/next/shared/lib/page-path/get-page-paths.ts index 9be9bce3549d..4d4906e3d868 100644 --- a/packages/next/shared/lib/page-path/get-page-paths.ts +++ b/packages/next/shared/lib/page-path/get-page-paths.ts @@ -10,23 +10,9 @@ import { join } from '../isomorphic/path' * @param normalizedPagePath Normalized page path (it will denormalize). * @param extensions Allowed extensions. */ -export function getPagePaths( - normalizedPagePath: string, - extensions: string[], - isRoot?: boolean -) { +export function getPagePaths(normalizedPagePath: string, extensions: string[]) { const page = denormalizePagePath(normalizedPagePath) - if (isRoot) { - return flatten( - extensions.map((extension) => { - return normalizedPagePath.endsWith('/index') - ? [`${page}.${extension}`, join(page, `index.${extension}`)] - : [`${page}.${extension}`] - }) - ) - } - return flatten( extensions.map((extension) => { return !normalizedPagePath.endsWith('/index') diff --git a/packages/next/shared/lib/router/utils/root-paths.ts b/packages/next/shared/lib/router/utils/view-paths.ts similarity index 88% rename from packages/next/shared/lib/router/utils/root-paths.ts rename to packages/next/shared/lib/router/utils/view-paths.ts index d9674f4fd81e..f34eb96c3bf1 100644 --- a/packages/next/shared/lib/router/utils/root-paths.ts +++ b/packages/next/shared/lib/router/utils/view-paths.ts @@ -1,5 +1,5 @@ // remove (name) from pathname as it's not considered for routing -export function normalizeRootPath(pathname: string) { +export function normalizeViewPath(pathname: string) { let normalized = '' const segments = pathname.split('/') diff --git a/packages/next/taskfile.js b/packages/next/taskfile.js index 9b7d5f19bed8..0a4e59c0c7a9 100644 --- a/packages/next/taskfile.js +++ b/packages/next/taskfile.js @@ -1887,9 +1887,9 @@ export async function pages_document(task, opts) { .target('dist/pages') } -export async function pages_root(task, opts) { +export async function pages_layout(task, opts) { await task - .source('pages/root.tsx') + .source('pages/layout.tsx') .swc('server', { dev: opts.dev, keepImportAssertions: true }) .target('dist/pages') } @@ -1901,7 +1901,7 @@ export async function pages(task, opts) { 'pages_app_server', 'pages_error', 'pages_document', - 'pages_root', + 'pages_layout', ], opts ) diff --git a/test/e2e/views-dir/app/next.config.js b/test/e2e/views-dir/app/next.config.js index 9abd7b65b73a..4131d5b60875 100644 --- a/test/e2e/views-dir/app/next.config.js +++ b/test/e2e/views-dir/app/next.config.js @@ -1,6 +1,6 @@ module.exports = { experimental: { - rootDir: true, + viewsDir: true, runtime: 'nodejs', reactRoot: true, serverComponents: true, From 8cc67de2552974e6aa20f2447c2352f23aac0bf2 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Wed, 4 May 2022 20:04:32 -0500 Subject: [PATCH 08/11] lint fix --- packages/next/build/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/next/build/index.ts b/packages/next/build/index.ts index d833480e0691..a0dfe1154e3f 100644 --- a/packages/next/build/index.ts +++ b/packages/next/build/index.ts @@ -114,7 +114,6 @@ import { MiddlewareManifest } from './webpack/plugins/middleware-plugin' import { recursiveCopy } from '../lib/recursive-copy' import { recursiveReadDir } from '../lib/recursive-readdir' import { lockfilePatchPromise, teardownTraceSubscriber } from './swc' -import { findPageFile } from '../server/lib/find-page-file' export type SsgRoute = { initialRevalidateSeconds: number | false From 244a1c82e000e863b451b1ec15c9455dc9d39073 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Wed, 4 May 2022 20:23:43 -0500 Subject: [PATCH 09/11] update test --- test/e2e/views-dir/index.test.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/e2e/views-dir/index.test.ts b/test/e2e/views-dir/index.test.ts index b2177850afd0..e4090960292e 100644 --- a/test/e2e/views-dir/index.test.ts +++ b/test/e2e/views-dir/index.test.ts @@ -6,6 +6,10 @@ import cheerio from 'cheerio' import webdriver from 'next-webdriver' describe('root dir', () => { + if (process.env.NEXT_TEST_REACT_VERSION === '^17') { + it('should skip for react v17', () => {}) + return + } let next: NextInstance beforeAll(async () => { From 5a5968caf788fd7fa224b4c0bb81b4d8c9859dfc Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Wed, 4 May 2022 20:49:35 -0500 Subject: [PATCH 10/11] update default layout --- .../{pages/layout.tsx => lib/views-layout.tsx} | 7 +++++-- packages/next/server/view-render.tsx | 2 +- packages/next/taskfile.js | 15 +-------------- 3 files changed, 7 insertions(+), 17 deletions(-) rename packages/next/{pages/layout.tsx => lib/views-layout.tsx} (65%) diff --git a/packages/next/pages/layout.tsx b/packages/next/lib/views-layout.tsx similarity index 65% rename from packages/next/pages/layout.tsx rename to packages/next/lib/views-layout.tsx index 259bb4e88df6..bbbbecd42693 100644 --- a/packages/next/pages/layout.tsx +++ b/packages/next/lib/views-layout.tsx @@ -1,11 +1,14 @@ import React from 'react' -export type RootProps = { +export type LayoutProps = { headChildren: any bodyChildren: any } -export default function RootLayout({ headChildren, bodyChildren }: RootProps) { +export default function ViewsLayout({ + headChildren, + bodyChildren, +}: LayoutProps) { return ( diff --git a/packages/next/server/view-render.tsx b/packages/next/server/view-render.tsx index 43b21cb77ca1..d8bedf081b0f 100644 --- a/packages/next/server/view-render.tsx +++ b/packages/next/server/view-render.tsx @@ -21,7 +21,7 @@ import { FlushEffectsContext } from '../shared/lib/flush-effects' import ReactDOMServer from 'react-dom/server.browser' import { isDynamicRoute } from '../shared/lib/router/utils' import { tryGetPreviewData } from './api-utils/node' -import DefaultRootLayout from '../pages/layout' +import DefaultRootLayout from '../lib/views-layout' export type RenderOptsPartial = { err?: Error | null diff --git a/packages/next/taskfile.js b/packages/next/taskfile.js index 0a4e59c0c7a9..3edcde3e5a6a 100644 --- a/packages/next/taskfile.js +++ b/packages/next/taskfile.js @@ -1887,22 +1887,9 @@ export async function pages_document(task, opts) { .target('dist/pages') } -export async function pages_layout(task, opts) { - await task - .source('pages/layout.tsx') - .swc('server', { dev: opts.dev, keepImportAssertions: true }) - .target('dist/pages') -} - export async function pages(task, opts) { await task.parallel( - [ - 'pages_app', - 'pages_app_server', - 'pages_error', - 'pages_document', - 'pages_layout', - ], + ['pages_app', 'pages_app_server', 'pages_error', 'pages_document'], opts ) } From bc9d623ceaad465185d4f56614b27cda26f93fe2 Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Thu, 5 May 2022 13:09:45 +0200 Subject: [PATCH 11/11] Rename test suite --- test/e2e/views-dir/index.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/views-dir/index.test.ts b/test/e2e/views-dir/index.test.ts index e4090960292e..361613c99dfc 100644 --- a/test/e2e/views-dir/index.test.ts +++ b/test/e2e/views-dir/index.test.ts @@ -5,7 +5,7 @@ import path from 'path' import cheerio from 'cheerio' import webdriver from 'next-webdriver' -describe('root dir', () => { +describe('views dir', () => { if (process.env.NEXT_TEST_REACT_VERSION === '^17') { it('should skip for react v17', () => {}) return