-
Notifications
You must be signed in to change notification settings - Fork 26.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reset not-found and error boundary when navigating #49855
Merged
timneutkens
merged 5 commits into
canary
from
05-16-Reset_not-found_and_error_boundary_when_navigating
May 18, 2023
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ebaeaa8
Reset not-found and error boundary when navigating
timneutkens 6aa4349
Add test for error boundary
timneutkens af832a4
Use getDerivedStateFromProps instead as class components don't suppor…
timneutkens fb40ea4
Remove outdated code
timneutkens 5a92833
Ensure previousPathName is always set based on props
timneutkens File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
13 changes: 13 additions & 0 deletions
13
test/e2e/app-dir/error-boundary-and-not-found-linking/app/error.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,13 @@ | ||
'use client' | ||
import Link from 'next/link' | ||
|
||
export default function ErrorComponent() { | ||
return ( | ||
<> | ||
<h1 id="error-component">Error Happened!</h1> | ||
<Link href="/result" id="to-result"> | ||
To Result | ||
</Link> | ||
</> | ||
) | ||
} |
7 changes: 7 additions & 0 deletions
7
test/e2e/app-dir/error-boundary-and-not-found-linking/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,7 @@ | ||
export default function Root({ children }: { children: React.ReactNode }) { | ||
return ( | ||
<html> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
12 changes: 12 additions & 0 deletions
12
test/e2e/app-dir/error-boundary-and-not-found-linking/app/not-found.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 NotFound() { | ||
return ( | ||
<> | ||
<h1 id="not-found-component">Not Found!</h1> | ||
<Link href="/result" id="to-result"> | ||
To Result | ||
</Link> | ||
</> | ||
) | ||
} |
3 changes: 3 additions & 0 deletions
3
test/e2e/app-dir/error-boundary-and-not-found-linking/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,3 @@ | ||
export default function Page() { | ||
return <h1 id="homepage">Home</h1> | ||
} |
3 changes: 3 additions & 0 deletions
3
test/e2e/app-dir/error-boundary-and-not-found-linking/app/result/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,3 @@ | ||
export default function Page() { | ||
return <h1 id="result-page">Result Page!</h1> | ||
} |
7 changes: 7 additions & 0 deletions
7
test/e2e/app-dir/error-boundary-and-not-found-linking/app/trigger-404/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 @@ | ||
import { notFound } from 'next/navigation' | ||
|
||
export const dynamic = 'force-dynamic' | ||
|
||
export default function Page() { | ||
notFound() | ||
} |
5 changes: 5 additions & 0 deletions
5
test/e2e/app-dir/error-boundary-and-not-found-linking/app/trigger-error/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,5 @@ | ||
export const dynamic = 'force-dynamic' | ||
|
||
export default function Page() { | ||
throw new Error('This is an error') | ||
} |
39 changes: 39 additions & 0 deletions
39
...app-dir/error-boundary-and-not-found-linking/error-boundary-and-not-found-linking.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,39 @@ | ||
import { createNextDescribe } from 'e2e-utils' | ||
|
||
createNextDescribe( | ||
'not-found-linking', | ||
{ | ||
files: __dirname, | ||
}, | ||
({ next }) => { | ||
it('should allow navigation on not-found', async () => { | ||
const browser = await next.browser('/trigger-404') | ||
expect(await browser.elementByCss('#not-found-component').text()).toBe( | ||
'Not Found!' | ||
) | ||
|
||
expect( | ||
await browser | ||
.elementByCss('#to-result') | ||
.click() | ||
.waitForElementByCss('#result-page') | ||
.text() | ||
).toBe('Result Page!') | ||
}) | ||
|
||
it('should allow navigation on error', async () => { | ||
const browser = await next.browser('/trigger-error') | ||
expect(await browser.elementByCss('#error-component').text()).toBe( | ||
'Error Happened!' | ||
) | ||
|
||
expect( | ||
await browser | ||
.elementByCss('#to-result') | ||
.click() | ||
.waitForElementByCss('#result-page') | ||
.text() | ||
).toBe('Result Page!') | ||
}) | ||
} | ||
) |
10 changes: 10 additions & 0 deletions
10
test/e2e/app-dir/error-boundary-and-not-found-linking/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,10 @@ | ||
/** | ||
* @type {import('next').NextConfig} | ||
*/ | ||
const nextConfig = { | ||
typescript: { | ||
ignoreBuildErrors: true, | ||
}, | ||
} | ||
|
||
module.exports = nextConfig |
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 |
---|---|---|
@@ -1,9 +1,15 @@ | ||
import Link from 'next/link' | ||
import styles from './style.module.css' | ||
|
||
export default function NotFound() { | ||
return ( | ||
<h1 id="not-found-component" className={styles.red}> | ||
Not Found! | ||
</h1> | ||
<> | ||
<h1 id="not-found-component" className={styles.red}> | ||
Not Found! | ||
</h1> | ||
<Link href="/not-found/result" id="to-result"> | ||
To Result | ||
</Link> | ||
</> | ||
) | ||
} |
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 Page() { | ||
return <h1 id="result-page">Result Page!</h1> | ||
} |
1 change: 0 additions & 1 deletion
1
test/e2e/app-dir/navigation/app/not-found/servercomponent/page.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
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,8 @@ | ||
import { notFound } from 'next/navigation' | ||
|
||
export const dynamic = 'force-dynamic' | ||
|
||
export default function Page() { | ||
notFound() | ||
return <></> | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, didn't notice this before: you need to set
previousPathname
even ifstate.error
is not set. So you can just delete that part of the condition.Otherwise
previousPathname
will always be the initial value, until there's an error.