-
Notifications
You must be signed in to change notification settings - Fork 26.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix interception/detail routes being triggered by router refreshes
- Loading branch information
Showing
24 changed files
with
280 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...t/src/client/components/router-reducer/reducers/has-interception-route-in-current-tree.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import type { FlightRouterState } from '../../../../server/app-render/types' | ||
import { isInterceptionRouteAppPath } from '../../../../server/future/helpers/interception-routes' | ||
|
||
export function hasInterceptionRouteInCurrentTree([ | ||
segment, | ||
parallelRoutes, | ||
]: FlightRouterState): boolean { | ||
// If we have a dynamic segment, it's marked as an interception route by the presence of the `i` suffix. | ||
if (Array.isArray(segment) && (segment[2] === 'di' || segment[2] === 'ci')) { | ||
return true | ||
} | ||
|
||
// If segment is not an array, apply the existing string-based check | ||
if (typeof segment === 'string' && isInterceptionRouteAppPath(segment)) { | ||
return true | ||
} | ||
|
||
// Iterate through parallelRoutes if they exist | ||
if (parallelRoutes) { | ||
for (const key in parallelRoutes) { | ||
if (hasInterceptionRouteInCurrentTree(parallelRoutes[key])) { | ||
return true | ||
} | ||
} | ||
} | ||
|
||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
test/e2e/app-dir/parallel-routes-revalidation/app/@interception/(.)detail-page/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function Page() { | ||
return ( | ||
<div> | ||
<h2 id="detail-title">Detail Page (Intercepted)</h2> | ||
</div> | ||
) | ||
} |
16 changes: 16 additions & 0 deletions
16
...app-dir/parallel-routes-revalidation/app/catchall/@interception2/(.)[...dynamic]/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use client' | ||
import { useRouter } from 'next/navigation' | ||
|
||
export default function Page({ params }: { params: { dynamic: string } }) { | ||
const router = useRouter() | ||
return ( | ||
<div> | ||
<h2 id="detail-title">Detail Page (Intercepted)</h2> | ||
<p id="params">{params.dynamic}</p> | ||
<span suppressHydrationWarning id="random-number"> | ||
{Math.random()} | ||
</span> | ||
<button onClick={() => router.refresh()}>Refresh</button> | ||
</div> | ||
) | ||
} |
3 changes: 3 additions & 0 deletions
3
test/e2e/app-dir/parallel-routes-revalidation/app/catchall/@interception2/default.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Default() { | ||
return null | ||
} |
16 changes: 16 additions & 0 deletions
16
test/e2e/app-dir/parallel-routes-revalidation/app/catchall/[...dynamic]/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use client' | ||
import { useRouter } from 'next/navigation' | ||
|
||
export default function Page({ params }: { params: { dynamic: string } }) { | ||
const router = useRouter() | ||
return ( | ||
<div> | ||
<h2 id="detail-title">Detail Page (Non-Intercepted)</h2> | ||
<p id="params">{params.dynamic}</p> | ||
<span suppressHydrationWarning id="random-number"> | ||
{Math.random()} | ||
</span> | ||
<button onClick={() => router.refresh()}>Refresh</button> | ||
</div> | ||
) | ||
} |
3 changes: 3 additions & 0 deletions
3
test/e2e/app-dir/parallel-routes-revalidation/app/catchall/default.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Default() { | ||
return null | ||
} |
16 changes: 16 additions & 0 deletions
16
test/e2e/app-dir/parallel-routes-revalidation/app/catchall/layout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react' | ||
|
||
export default function Layout({ | ||
children, | ||
interception2, | ||
}: { | ||
children: React.ReactNode | ||
interception2: React.ReactNode | ||
}) { | ||
return ( | ||
<div> | ||
{children} | ||
{interception2} | ||
</div> | ||
) | ||
} |
9 changes: 9 additions & 0 deletions
9
test/e2e/app-dir/parallel-routes-revalidation/app/catchall/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import Link from 'next/link' | ||
|
||
export default function Page() { | ||
return ( | ||
<div> | ||
<Link href="/catchall/foobar">Dynamic Catchall Interception</Link> | ||
</div> | ||
) | ||
} |
15 changes: 15 additions & 0 deletions
15
test/e2e/app-dir/parallel-routes-revalidation/app/detail-page/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use client' | ||
import { useRouter } from 'next/navigation' | ||
|
||
export default function Page() { | ||
const router = useRouter() | ||
return ( | ||
<div> | ||
<h2 id="detail-title">Detail Page (Non-Intercepted)</h2> | ||
<span suppressHydrationWarning id="random-number"> | ||
{Math.random()} | ||
</span> | ||
<button onClick={() => router.refresh()}>Refresh</button> | ||
</div> | ||
) | ||
} |
16 changes: 16 additions & 0 deletions
16
...e2e/app-dir/parallel-routes-revalidation/app/dynamic/@interception2/(.)[dynamic]/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use client' | ||
import { useRouter } from 'next/navigation' | ||
|
||
export default function Page({ params }: { params: { dynamic: string } }) { | ||
const router = useRouter() | ||
return ( | ||
<div> | ||
<h2 id="detail-title">Detail Page (Intercepted)</h2> | ||
<p id="params">{params.dynamic}</p> | ||
<span suppressHydrationWarning id="random-number"> | ||
{Math.random()} | ||
</span> | ||
<button onClick={() => router.refresh()}>Refresh</button> | ||
</div> | ||
) | ||
} |
3 changes: 3 additions & 0 deletions
3
test/e2e/app-dir/parallel-routes-revalidation/app/dynamic/@interception2/default.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Default() { | ||
return null | ||
} |
16 changes: 16 additions & 0 deletions
16
test/e2e/app-dir/parallel-routes-revalidation/app/dynamic/[dynamic]/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use client' | ||
import { useRouter } from 'next/navigation' | ||
|
||
export default function Page({ params }: { params: { dynamic: string } }) { | ||
const router = useRouter() | ||
return ( | ||
<div> | ||
<h2 id="detail-title">Detail Page (Non-Intercepted)</h2> | ||
<p id="params">{params.dynamic}</p> | ||
<span suppressHydrationWarning id="random-number"> | ||
{Math.random()} | ||
</span> | ||
<button onClick={() => router.refresh()}>Refresh</button> | ||
</div> | ||
) | ||
} |
3 changes: 3 additions & 0 deletions
3
test/e2e/app-dir/parallel-routes-revalidation/app/dynamic/default.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Default() { | ||
return null | ||
} |
16 changes: 16 additions & 0 deletions
16
test/e2e/app-dir/parallel-routes-revalidation/app/dynamic/layout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react' | ||
|
||
export default function Layout({ | ||
children, | ||
interception2, | ||
}: { | ||
children: React.ReactNode | ||
interception2: React.ReactNode | ||
}) { | ||
return ( | ||
<div> | ||
{children} | ||
{interception2} | ||
</div> | ||
) | ||
} |
9 changes: 9 additions & 0 deletions
9
test/e2e/app-dir/parallel-routes-revalidation/app/dynamic/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import Link from 'next/link' | ||
|
||
export default function Page() { | ||
return ( | ||
<div> | ||
<Link href="/dynamic/foobar">Dynamic Interception</Link> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.