From 8dadd66cb6a9796fd50f10e1d06ab4a5f228305b Mon Sep 17 00:00:00 2001 From: Jimmy Lai Date: Thu, 13 Apr 2023 18:47:34 +0200 Subject: [PATCH 1/2] fix --- .../router-reducer/compute-changed-path.ts | 26 +++++++++++++++++-- .../[username]/@feed/page.js | 0 .../[username]/@modal/(..)photo/[id]/page.js | 0 .../[username]/@modal/default.js | 0 .../[username]/layout.js | 0 .../photo/[id]/page.js | 0 .../photo/layout.js | 0 7 files changed, 24 insertions(+), 2 deletions(-) rename test/e2e/app-dir/parallel-routes-and-interception/app/{ => (group)}/intercepting-parallel-modal/[username]/@feed/page.js (100%) rename test/e2e/app-dir/parallel-routes-and-interception/app/{ => (group)}/intercepting-parallel-modal/[username]/@modal/(..)photo/[id]/page.js (100%) rename test/e2e/app-dir/parallel-routes-and-interception/app/{ => (group)}/intercepting-parallel-modal/[username]/@modal/default.js (100%) rename test/e2e/app-dir/parallel-routes-and-interception/app/{ => (group)}/intercepting-parallel-modal/[username]/layout.js (100%) rename test/e2e/app-dir/parallel-routes-and-interception/app/{ => (group)}/intercepting-parallel-modal/photo/[id]/page.js (100%) rename test/e2e/app-dir/parallel-routes-and-interception/app/{ => (group)}/intercepting-parallel-modal/photo/layout.js (100%) diff --git a/packages/next/src/client/components/router-reducer/compute-changed-path.ts b/packages/next/src/client/components/router-reducer/compute-changed-path.ts index 59e68ca4f7dfc..42e96caa115f9 100644 --- a/packages/next/src/client/components/router-reducer/compute-changed-path.ts +++ b/packages/next/src/client/components/router-reducer/compute-changed-path.ts @@ -53,7 +53,7 @@ export function extractPathFromFlightRouterState( return finalPath.endsWith('/') ? finalPath.slice(0, -1) : finalPath } -export function computeChangedPath( +function computeChangedPathImpl( treeA: FlightRouterState, treeB: FlightRouterState ): string | null { @@ -79,7 +79,7 @@ export function computeChangedPath( for (const parallelRouterKey in parallelRoutesA) { if (parallelRoutesB[parallelRouterKey]) { - const changedPath = computeChangedPath( + const changedPath = computeChangedPathImpl( parallelRoutesA[parallelRouterKey], parallelRoutesB[parallelRouterKey] ) @@ -91,3 +91,25 @@ export function computeChangedPath( return null } + +export function computeChangedPath( + treeA: FlightRouterState, + treeB: FlightRouterState +): string | null { + const changedPath = computeChangedPathImpl(treeA, treeB) + + if (changedPath === null) return null + + // lightweight normalization to remove route groups + return changedPath.split('/').reduce((acc, segment) => { + if (!segment) { + return acc + } + + if (segment.startsWith('(') && segment.endsWith(')')) { + return acc + } + + return `${acc}/${segment}` + }, '') +} diff --git a/test/e2e/app-dir/parallel-routes-and-interception/app/intercepting-parallel-modal/[username]/@feed/page.js b/test/e2e/app-dir/parallel-routes-and-interception/app/(group)/intercepting-parallel-modal/[username]/@feed/page.js similarity index 100% rename from test/e2e/app-dir/parallel-routes-and-interception/app/intercepting-parallel-modal/[username]/@feed/page.js rename to test/e2e/app-dir/parallel-routes-and-interception/app/(group)/intercepting-parallel-modal/[username]/@feed/page.js diff --git a/test/e2e/app-dir/parallel-routes-and-interception/app/intercepting-parallel-modal/[username]/@modal/(..)photo/[id]/page.js b/test/e2e/app-dir/parallel-routes-and-interception/app/(group)/intercepting-parallel-modal/[username]/@modal/(..)photo/[id]/page.js similarity index 100% rename from test/e2e/app-dir/parallel-routes-and-interception/app/intercepting-parallel-modal/[username]/@modal/(..)photo/[id]/page.js rename to test/e2e/app-dir/parallel-routes-and-interception/app/(group)/intercepting-parallel-modal/[username]/@modal/(..)photo/[id]/page.js diff --git a/test/e2e/app-dir/parallel-routes-and-interception/app/intercepting-parallel-modal/[username]/@modal/default.js b/test/e2e/app-dir/parallel-routes-and-interception/app/(group)/intercepting-parallel-modal/[username]/@modal/default.js similarity index 100% rename from test/e2e/app-dir/parallel-routes-and-interception/app/intercepting-parallel-modal/[username]/@modal/default.js rename to test/e2e/app-dir/parallel-routes-and-interception/app/(group)/intercepting-parallel-modal/[username]/@modal/default.js diff --git a/test/e2e/app-dir/parallel-routes-and-interception/app/intercepting-parallel-modal/[username]/layout.js b/test/e2e/app-dir/parallel-routes-and-interception/app/(group)/intercepting-parallel-modal/[username]/layout.js similarity index 100% rename from test/e2e/app-dir/parallel-routes-and-interception/app/intercepting-parallel-modal/[username]/layout.js rename to test/e2e/app-dir/parallel-routes-and-interception/app/(group)/intercepting-parallel-modal/[username]/layout.js diff --git a/test/e2e/app-dir/parallel-routes-and-interception/app/intercepting-parallel-modal/photo/[id]/page.js b/test/e2e/app-dir/parallel-routes-and-interception/app/(group)/intercepting-parallel-modal/photo/[id]/page.js similarity index 100% rename from test/e2e/app-dir/parallel-routes-and-interception/app/intercepting-parallel-modal/photo/[id]/page.js rename to test/e2e/app-dir/parallel-routes-and-interception/app/(group)/intercepting-parallel-modal/photo/[id]/page.js diff --git a/test/e2e/app-dir/parallel-routes-and-interception/app/intercepting-parallel-modal/photo/layout.js b/test/e2e/app-dir/parallel-routes-and-interception/app/(group)/intercepting-parallel-modal/photo/layout.js similarity index 100% rename from test/e2e/app-dir/parallel-routes-and-interception/app/intercepting-parallel-modal/photo/layout.js rename to test/e2e/app-dir/parallel-routes-and-interception/app/(group)/intercepting-parallel-modal/photo/layout.js From eae0b9cac467525ea7257c4fa0e53a7597267a52 Mon Sep 17 00:00:00 2001 From: Jimmy Lai Date: Thu, 13 Apr 2023 22:01:41 +0200 Subject: [PATCH 2/2] fix --- .../components/router-reducer/compute-changed-path.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/next/src/client/components/router-reducer/compute-changed-path.ts b/packages/next/src/client/components/router-reducer/compute-changed-path.ts index 42e96caa115f9..a98f62aa5af98 100644 --- a/packages/next/src/client/components/router-reducer/compute-changed-path.ts +++ b/packages/next/src/client/components/router-reducer/compute-changed-path.ts @@ -98,15 +98,13 @@ export function computeChangedPath( ): string | null { const changedPath = computeChangedPathImpl(treeA, treeB) - if (changedPath === null) return null + if (changedPath == null || changedPath === '/') { + return changedPath + } // lightweight normalization to remove route groups return changedPath.split('/').reduce((acc, segment) => { - if (!segment) { - return acc - } - - if (segment.startsWith('(') && segment.endsWith(')')) { + if (segment === '' || (segment.startsWith('(') && segment.endsWith(')'))) { return acc }