Skip to content
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

Allow resetting not-found error boundary when search params change #69652

Open
wants to merge 12 commits into
base: canary
Choose a base branch
from

Conversation

abhi12299
Copy link
Contributor

@abhi12299 abhi12299 commented Sep 4, 2024

Fixing a bug

Fixes #69622
Fixes #70164

What?

The not found error boundary must also react to changes in search params, besides just the pathname. The current code checks only the pathname:

static getDerivedStateFromProps(
props: NotFoundErrorBoundaryProps,
state: NotFoundErrorBoundaryState
): NotFoundErrorBoundaryState | null {
/**
* Handles reset of the error boundary when a navigation happens.
* Ensures the error boundary does not stay enabled when navigating to a new page.
* Approach of setState in render is safe as it checks the previous pathname and then overrides
* it as outlined in https://react.dev/reference/react/useState#storing-information-from-previous-renders
*/
if (props.pathname !== state.previousPathname && state.notFoundTriggered) {
return {
notFoundTriggered: false,
previousPathname: props.pathname,
}
}
return {
notFoundTriggered: state.notFoundTriggered,
previousPathname: props.pathname,
}
}

How?

By passing search params in the error boundary component and then checking if either the pathname or the search params changed.

@ijjk
Copy link
Member

ijjk commented Sep 4, 2024

Allow CI Workflow Run

  • approve CI run for commit: 5c9a0f5

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

@abhi12299
Copy link
Contributor Author

@ijjk please review this as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants