Skip to content

Commit f3daa1c

Browse files
authored
Add missing isRootLayout when creating optimistic tree (vercel#45899)
Fixes vercel#45750 Closes vercel#45822 Fixes NEXT-514 Ensures rootlayout marker is copied into the optimistic tree. <!-- Thanks for opening a PR! Your contribution is much appreciated. To make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below. Choose the right checklist for the change(s) that you're making: --> ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md) ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md) ## Documentation / Examples - [ ] Make sure the linting passes by running `pnpm build && pnpm lint` - [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
1 parent 5422f3c commit f3daa1c

5 files changed

Lines changed: 45 additions & 4 deletions

File tree

packages/next/src/client/components/router-reducer/create-optimistic-tree.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ describe('createOptimisticTree', () => {
4242
'refetch',
4343
],
4444
},
45+
undefined,
46+
undefined,
47+
true,
4548
])
4649
})
4750
})

packages/next/src/client/components/router-reducer/create-optimistic-tree.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ export function createOptimisticTree(
1010
flightRouterState: FlightRouterState | null,
1111
parentRefetch: boolean
1212
): FlightRouterState {
13-
const [existingSegment, existingParallelRoutes] = flightRouterState || [
14-
null,
15-
{},
16-
]
13+
const [existingSegment, existingParallelRoutes, url, refresh, isRootLayout] =
14+
flightRouterState || [null, {}]
1715
const segment = segments[0]
1816
const isLastSegment = segments.length === 1
1917

@@ -45,8 +43,18 @@ export function createOptimisticTree(
4543
},
4644
]
4745

46+
if (url) {
47+
result[2] = url
48+
}
49+
4850
if (!parentRefetch && shouldRefetchThisLevel) {
4951
result[3] = 'refetch'
52+
} else if (segmentMatches && refresh) {
53+
result[3] = refresh
54+
}
55+
56+
if (segmentMatches && isRootLayout) {
57+
result[4] = isRootLayout
5058
}
5159

5260
return result
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import Link from 'next/link'
2+
3+
export default function Page() {
4+
return (
5+
<>
6+
<Link
7+
href="/prefetch-false/result"
8+
prefetch={false}
9+
id="to-prefetch-false-result"
10+
>
11+
To prefetch false
12+
</Link>
13+
</>
14+
)
15+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function Page() {
2+
return <h1 id="prefetch-false-page-result">Result page</h1>
3+
}

test/e2e/app-dir/app-prefetch/prefetching.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,17 @@ createNextDescribe(
9898
).toBe(0)
9999
}
100100
})
101+
102+
it('should navigate when prefetch is false', async () => {
103+
const browser = await next.browser('/prefetch-false/initial')
104+
await browser
105+
.elementByCss('#to-prefetch-false-result')
106+
.click()
107+
.waitForElementByCss('#prefetch-false-page-result')
108+
109+
expect(
110+
await browser.elementByCss('#prefetch-false-page-result').text()
111+
).toBe('Result page')
112+
})
101113
}
102114
)

0 commit comments

Comments
 (0)