Skip to content

Commit f8fd39a

Browse files
committed
This change fixes the problems with intercept routes not reloading automatically with hmr
1 parent cbbc8f3 commit f8fd39a

File tree

9 files changed

+111
-1
lines changed

9 files changed

+111
-1
lines changed

crates/next-core/src/next_app/mod.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,18 @@ impl PageSegment {
6767
bail!("slashes are not allowed in segments");
6868
}
6969

70+
if let Some(s) = segment
71+
.strip_prefix("(...)")
72+
.or_else(|| segment.strip_prefix("(..)"))
73+
.or_else(|| segment.strip_prefix("(.)"))
74+
{
75+
return Ok(PageSegment::Static(s.into()));
76+
}
77+
7078
if let Some(s) = segment.strip_prefix('(').and_then(|s| s.strip_suffix(')')) {
71-
return Ok(PageSegment::Group(s.into()));
79+
if !s.starts_with(".") {
80+
return Ok(PageSegment::Group(s.into()));
81+
}
7282
}
7383

7484
if let Some(s) = segment.strip_prefix('@') {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function InterceptPage() {
2+
return <h1>I'm the intercept page</h1>
3+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default function RootLayout({ children }) {
2+
return (
3+
<html lang="en">
4+
<body>{children}</body>
5+
</html>
6+
)
7+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import Link from 'next/link'
2+
3+
export default function Home() {
4+
return (
5+
<div>
6+
<h1>Main Page</h1>
7+
<Link id="to-intercept" href="/intercept">
8+
Goto Intercept
9+
</Link>
10+
</div>
11+
)
12+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function Intercept() {
2+
return <h1 id="intercept">I'm the intercept</h1>
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function Default() {
2+
return <h1 id="default-intercept">I'm the default intercept</h1>
3+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default function RootLayout({ children, intercept }) {
2+
return (
3+
<html lang="en">
4+
<body>
5+
{children}
6+
{intercept}
7+
</body>
8+
</html>
9+
)
10+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { nextTestSetup } from 'e2e-utils'
2+
3+
// This only works for Turbopack HMR builds
4+
;(process.env.IS_TURBOPACK_TEST ? describe : describe.skip)(
5+
'hmr-intercept-routes',
6+
() => {
7+
const { next } = nextTestSetup({
8+
files: __dirname,
9+
})
10+
11+
it('should update intercept routes via HMR', async () => {
12+
const browser = await next.browser('/')
13+
expect(await browser.elementByCss('h1').text()).toBe('Main Page')
14+
15+
const parallelDefaultContent = await next.readFile(
16+
'fixtures/@intercept/default.js'
17+
)
18+
19+
const parallelInterceptContent = await next.readFile(
20+
'fixtures/@intercept/(.)intercept/page.js'
21+
)
22+
23+
// Write the fixture files to the associated output location
24+
await next.patchFile('app/@intercept/default.js', parallelDefaultContent)
25+
await next.patchFile(
26+
'app/@intercept/(.)intercept/page.js',
27+
parallelInterceptContent
28+
)
29+
30+
// Read the original code of the root layout page
31+
const rootLayoutContent = await next.readFile('app/layout.js')
32+
const fixtureLayoutContent = await next.readFile('fixtures/layout.js')
33+
34+
// Update the root layout file with the fixture layout which includes the new parallel routes
35+
await next.patchFile('app/layout.js', fixtureLayoutContent)
36+
37+
// Check to make sure that the main page now has the correct layout changes
38+
await browser.waitForElementByCss('#default-intercept')
39+
expect(await browser.elementById('default-intercept').text()).toBe(
40+
"I'm the default intercept"
41+
)
42+
43+
// Go to the intercept route and check that the intercept worked correctly
44+
await browser.elementById('to-intercept').click()
45+
await browser.waitForElementByCss('#intercept')
46+
expect(await browser.elementById('intercept').text()).toBe(
47+
"I'm the intercept"
48+
)
49+
50+
// Reset the file statuses
51+
await next.patchFile('app/layout.js', rootLayoutContent)
52+
await next.deleteFile('app/@intercept')
53+
})
54+
}
55+
)

test/turbopack-dev-tests-manifest.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2539,6 +2539,13 @@
25392539
"flakey": [],
25402540
"runtimeError": false
25412541
},
2542+
"test/development/app-dir/hmr-intercept-routes/hmr-intercept-routes.test.ts": {
2543+
"passed": ["hmr-intercept-routes should update intercept routes via HMR"],
2544+
"failed": [],
2545+
"pending": [],
2546+
"flakey": [],
2547+
"runtimeError": false
2548+
},
25422549
"test/development/app-dir/hmr-move-file/hmr-move-file.test.ts": {
25432550
"passed": [
25442551
"HMR Move File should work when moving a component to another directory"

0 commit comments

Comments
 (0)