-
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 navigation applying stale data when triggered from global not found
- Loading branch information
Showing
4 changed files
with
83 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// we want the layout to opt-out of static prefetching | ||
export const dynamic = 'force-dynamic' | ||
|
||
import Link from 'next/link' | ||
|
||
export default function RootLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode | ||
}) { | ||
return ( | ||
<html lang="en"> | ||
<body> | ||
<Link href="/">Link to `/`</Link> | ||
<div>{children}</div> | ||
</body> | ||
</html> | ||
) | ||
} |
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,10 @@ | ||
import Link from 'next/link' | ||
|
||
export default function Home() { | ||
return ( | ||
<div> | ||
<h1>Home Page</h1> | ||
<Link href="/fake-link">Go to Invalid Page</Link> | ||
</div> | ||
) | ||
} |
40 changes: 40 additions & 0 deletions
40
test/e2e/app-dir/prefetching-not-found/prefetching-not-found.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,40 @@ | ||
import { nextTestSetup } from 'e2e-utils' | ||
import { retry } from 'next-test-utils' | ||
|
||
describe('prefetching-not-found', () => { | ||
const { next } = nextTestSetup({ | ||
files: __dirname, | ||
}) | ||
|
||
it('should correctly navigate to/from a global 404 page when following links with prefetch=auto', async () => { | ||
let browser = await next.browser('/') | ||
expect(await browser.elementByCss('h1').text()).toBe('Home Page') | ||
|
||
await browser.elementByCss("[href='/fake-link']").click() | ||
|
||
await retry(async () => { | ||
expect(await browser.elementByCss('body').text()).toContain( | ||
'This page could not be found.' | ||
) | ||
}) | ||
|
||
await browser.elementByCss("[href='/']").click() | ||
|
||
await retry(async () => { | ||
expect(await browser.elementByCss('h1').text()).toBe('Home Page') | ||
}) | ||
|
||
// assert the same behavior, but starting at the not found page. This is to ensure that when we seed the prefetch cache, | ||
// we don't have any cache collisions that would cause the not-found page to remain rendered when following a link to the home page | ||
browser = await next.browser('/fake-link') | ||
expect(await browser.elementByCss('body').text()).toContain( | ||
'This page could not be found.' | ||
) | ||
|
||
await browser.elementByCss("[href='/']").click() | ||
|
||
await retry(async () => { | ||
expect(await browser.elementByCss('h1').text()).toBe('Home Page') | ||
}) | ||
}) | ||
}) |