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

First resetKeys update ignored when error triggered on mount #84

Closed
wild-lotus opened this issue Feb 24, 2021 · 2 comments · Fixed by #85
Closed

First resetKeys update ignored when error triggered on mount #84

wild-lotus opened this issue Feb 24, 2021 · 2 comments · Fixed by #85
Labels

Comments

@wild-lotus
Copy link
Contributor

  • react-error-boundary version: 3.1.0
  • node version: 12.16.1
  • yarn version: 1.22.5

What you did:

I use ErrorBoundary with resetKeys, with the error being triggered on ErrorBoundarymount. Then I trigger a reset via resetKeys

What happened:

The ErrorBoundary error state is not reset until the second resetKeys update.

Reproduction repository:

https://codesandbox.io/s/react-error-boundaryignored-update-issue-fcfyi?file=/src/App.js
This is the same code as in Error Recovery example, but with explode state initialized as true.
Try clicking "toggle explode" button right after the initial render: it does not get reset.

Problem description:

this.updatedWithError flag is not set on component mount, only on component update, so if the error is triggered on component mount, 2 extra updates are needed instead of one. The first one sets the this.updatedWithError and the second ones resets the state.

Suggested solution:

Adding:

  componentDidMount() {
    const {error} = this.state
    if (error !== null) {
      this.updatedWithError = true
    }
  }
@wild-lotus
Copy link
Contributor Author

Silly me, I just realised this is a duplicate from #74. 🤦
I suggest a different solution though, happy to attempt a PR if you see it fit.

kentcdodds pushed a commit that referenced this issue Mar 2, 2021
* fix: update failing snapshots

* fix: ignored update after error triggered on component mount

Closes #74 and Closes #84
@github-actions
Copy link

github-actions bot commented Mar 2, 2021

🎉 This issue has been resolved in version 3.1.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging a pull request may close this issue.

1 participant