-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(turbopack): intercepting routes should have default slots (#69929)
### What? Intercepting routes should only override the slot they are in and not affect other parts of the tree. This PR makes sure we replace all other slots with the default route. Closes PACK-3219 Fixes #69299 Closes #69575
- Loading branch information
1 parent
4e14037
commit 7eccedc
Showing
13 changed files
with
241 additions
and
37 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
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-and-interception-catchall/app/@modal/(.)cart/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 async function CartModalPage() { | ||
return ( | ||
<div id="cart-modal-intercept"> | ||
<p>Cart Modal</p> | ||
</div> | ||
) | ||
} |
12 changes: 12 additions & 0 deletions
12
test/e2e/app-dir/parallel-routes-and-interception-catchall/app/@modal/[...segments]/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,12 @@ | ||
// This component is required for the cart modal to hide when the user navigates to a new page | ||
// https://nextjs.org/docs/app/building-your-application/routing/parallel-routes#closing-the-modal | ||
// Since client-side navigations to a route that no longer match the slot will remain visible, | ||
// we need to match the slot to a route that returns null to close the modal. | ||
|
||
export default function ModalCartCatchAll() { | ||
return ( | ||
<div id="cart-modal-catch-all"> | ||
<p>Cart Catch All</p> | ||
</div> | ||
) | ||
} |
7 changes: 7 additions & 0 deletions
7
test/e2e/app-dir/parallel-routes-and-interception-catchall/app/@modal/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,7 @@ | ||
export default function ModalCartDefault() { | ||
return ( | ||
<div id="cart-modal-default"> | ||
<p>Cart Default</p> | ||
</div> | ||
) | ||
} |
7 changes: 7 additions & 0 deletions
7
test/e2e/app-dir/parallel-routes-and-interception-catchall/app/@slot/[...segments]/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 CatchAll() { | ||
return ( | ||
<div id="slot-catch-all"> | ||
<p>Slot Catch All</p> | ||
</div> | ||
) | ||
} |
7 changes: 7 additions & 0 deletions
7
test/e2e/app-dir/parallel-routes-and-interception-catchall/app/@slot/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 SlotRoot() { | ||
return ( | ||
<div id="slot-page"> | ||
<p>Slot Page</p> | ||
</div> | ||
) | ||
} |
7 changes: 7 additions & 0 deletions
7
test/e2e/app-dir/parallel-routes-and-interception-catchall/app/[...segments]/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 CatchAll() { | ||
return ( | ||
<div id="root-catch-all"> | ||
<p>Root Catch All</p> | ||
</div> | ||
) | ||
} |
7 changes: 7 additions & 0 deletions
7
test/e2e/app-dir/parallel-routes-and-interception-catchall/app/cart/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 async function CartPage() { | ||
return ( | ||
<div id="cart-page"> | ||
<p>Cart Page</p> | ||
</div> | ||
) | ||
} |
30 changes: 30 additions & 0 deletions
30
test/e2e/app-dir/parallel-routes-and-interception-catchall/app/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,30 @@ | ||
import React from 'react' | ||
|
||
export default function RootLayout({ | ||
children, | ||
modal, | ||
slot, | ||
}: Readonly<{ | ||
children: React.ReactNode | ||
modal: React.ReactNode | ||
slot: React.ReactNode | ||
}>) { | ||
return ( | ||
<html lang="en"> | ||
<body> | ||
<section> | ||
<h1>Children</h1> | ||
<div id="children-slot">{children}</div> | ||
</section> | ||
<section> | ||
<h1>Modal</h1> | ||
<div id="modal-slot">{modal}</div> | ||
</section> | ||
<section> | ||
<h1>Slot</h1> | ||
<div id="slot-slot">{slot}</div> | ||
</section> | ||
</body> | ||
</html> | ||
) | ||
} |
12 changes: 12 additions & 0 deletions
12
test/e2e/app-dir/parallel-routes-and-interception-catchall/app/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,12 @@ | ||
import Link from 'next/link' | ||
|
||
export default function Home() { | ||
return ( | ||
<div id="root-page"> | ||
<p>Home Page</p> | ||
<Link href="/cart">Open cart</Link> | ||
<br /> | ||
<Link href="/catch-all">Open catch all</Link> | ||
</div> | ||
) | ||
} |
6 changes: 6 additions & 0 deletions
6
test/e2e/app-dir/parallel-routes-and-interception-catchall/next.config.js
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,6 @@ | ||
/** | ||
* @type {import('next').NextConfig} | ||
*/ | ||
const nextConfig = {} | ||
|
||
module.exports = nextConfig |
41 changes: 41 additions & 0 deletions
41
...rallel-routes-and-interception-catchall/parallel-routes-and-interception-catchall.test.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,41 @@ | ||
import { nextTestSetup } from 'e2e-utils' | ||
|
||
describe('parallel-routes-and-interception-catchall', () => { | ||
const { next } = nextTestSetup({ | ||
files: __dirname, | ||
}) | ||
|
||
it('should render intercepted route and preserve other slots', async () => { | ||
const browser = await next.browser('/') | ||
|
||
const homeContent = 'Home Page\n\nOpen cart\nOpen catch all' | ||
const slotContent = 'Slot Page' | ||
|
||
expect(await browser.elementById('children-slot').text()).toBe(homeContent) | ||
expect(await browser.elementById('slot-slot').text()).toBe(slotContent) | ||
|
||
// Check if navigation to modal route works | ||
await browser | ||
.elementByCss('[href="/cart"]') | ||
.click() | ||
.waitForElementByCss('#cart-modal-intercept') | ||
|
||
expect(await browser.elementById('cart-modal-intercept').text()).toBe( | ||
'Cart Modal' | ||
) | ||
|
||
// Children slot should still be the same | ||
expect(await browser.elementById('children-slot').text()).toBe(homeContent) | ||
expect(await browser.elementById('slot-slot').text()).toBe(slotContent) | ||
|
||
// Check if url matches even though it was intercepted. | ||
expect(await browser.url()).toBe(next.url + '/cart') | ||
|
||
// Trigger a refresh, this should load the normal page, not the modal. | ||
await browser.refresh().waitForElementByCss('#cart-page') | ||
expect(await browser.elementById('children-slot').text()).toBe('Cart Page') | ||
|
||
// Check if the url matches still. | ||
expect(await browser.url()).toBe(next.url + '/cart') | ||
}) | ||
}) |