From f64ee1ee9b6ff099755860eaad689000f7f8a397 Mon Sep 17 00:00:00 2001 From: imranbarbhuiya Date: Sat, 18 Feb 2023 16:46:56 +0000 Subject: [PATCH 1/4] fix: typedroute routes for window --- .../src/build/webpack/plugins/flight-types-plugin.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/next/src/build/webpack/plugins/flight-types-plugin.ts b/packages/next/src/build/webpack/plugins/flight-types-plugin.ts index cd3175014d22f..636737844def4 100644 --- a/packages/next/src/build/webpack/plugins/flight-types-plugin.ts +++ b/packages/next/src/build/webpack/plugins/flight-types-plugin.ts @@ -220,15 +220,19 @@ export class FlightTypesPlugin { return } + // Filter out non-page files in pages dir + if (!isApp && !/[/\\](?:_app|_document|404|500)\.[^.]+$/.test(filePath)) { + return + } + const page = isApp ? normalizeAppPath(path.relative(this.appDir, filePath)) : '/' + path.relative(this.pagesDir, filePath) let route = (isApp - ? page.replace(/\/page\.[^./]+$/, '') - : page.replace(/\.[^./]+$/, '') - ).replace(/\/index$/, '') || '/' + ? page.replace(/[/\\]page\.[^./]+$/, '') + : page.replace(/\.[^./]+$/, '').replace(/[/\\]index$/, '')) || '/' if (isDynamicRoute(route)) { route = route From 7ca0d3f1f362ddc5d1865b2ae3634008bccad059 Mon Sep 17 00:00:00 2001 From: imranbarbhuiya Date: Sat, 18 Feb 2023 16:52:37 +0000 Subject: [PATCH 2/4] fix: change \ to / --- packages/next/src/build/webpack/plugins/flight-types-plugin.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/next/src/build/webpack/plugins/flight-types-plugin.ts b/packages/next/src/build/webpack/plugins/flight-types-plugin.ts index 636737844def4..260923fe51ffa 100644 --- a/packages/next/src/build/webpack/plugins/flight-types-plugin.ts +++ b/packages/next/src/build/webpack/plugins/flight-types-plugin.ts @@ -232,7 +232,8 @@ export class FlightTypesPlugin { let route = (isApp ? page.replace(/[/\\]page\.[^./]+$/, '') - : page.replace(/\.[^./]+$/, '').replace(/[/\\]index$/, '')) || '/' + : page.replace(/\.[^./]+$/, '').replace(/[/\\]index$/, '') + ).replace(/\\/g, '/') || '/' if (isDynamicRoute(route)) { route = route From 4e46eeb2f70fccf497e5f1f688d207ea3a098de4 Mon Sep 17 00:00:00 2001 From: imranbarbhuiya Date: Sat, 18 Feb 2023 16:54:36 +0000 Subject: [PATCH 3/4] fix: wrong logic --- packages/next/src/build/webpack/plugins/flight-types-plugin.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/next/src/build/webpack/plugins/flight-types-plugin.ts b/packages/next/src/build/webpack/plugins/flight-types-plugin.ts index 260923fe51ffa..f8ea5a20fed77 100644 --- a/packages/next/src/build/webpack/plugins/flight-types-plugin.ts +++ b/packages/next/src/build/webpack/plugins/flight-types-plugin.ts @@ -221,7 +221,7 @@ export class FlightTypesPlugin { } // Filter out non-page files in pages dir - if (!isApp && !/[/\\](?:_app|_document|404|500)\.[^.]+$/.test(filePath)) { + if (!isApp && /[/\\](?:_app|_document|404|500)\.[^.]+$/.test(filePath)) { return } From 2f15e4d66d45a72b158616c64dfeb4cc149aacb3 Mon Sep 17 00:00:00 2001 From: imranbarbhuiya Date: Sat, 18 Feb 2023 16:56:34 +0000 Subject: [PATCH 4/4] fix: add _error file --- .../next/src/build/webpack/plugins/flight-types-plugin.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/next/src/build/webpack/plugins/flight-types-plugin.ts b/packages/next/src/build/webpack/plugins/flight-types-plugin.ts index f8ea5a20fed77..77a570249cecc 100644 --- a/packages/next/src/build/webpack/plugins/flight-types-plugin.ts +++ b/packages/next/src/build/webpack/plugins/flight-types-plugin.ts @@ -221,7 +221,10 @@ export class FlightTypesPlugin { } // Filter out non-page files in pages dir - if (!isApp && /[/\\](?:_app|_document|404|500)\.[^.]+$/.test(filePath)) { + if ( + !isApp && + /[/\\](?:_app|_document|_error|404|500)\.[^.]+$/.test(filePath) + ) { return }