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

Getting errors on autosave: Can't perform a React state update on an unmounted component.... #920

Closed
michaellill-corefihub opened this issue Apr 6, 2021 · 4 comments · Fixed by #922
Assignees
Labels
Type: Bug Bug reports and their fixes
Milestone

Comments

@michaellill-corefihub
Copy link

I'm getting this error in our app when running tests with cypress:

Can't perform a React state update on an unmounted component.
This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in %s.%s", "the componentWillUnmount method", "\n at AutoValidatedQuickBootstrap4Form\n at QuickCheckForm

// Do not call `onSubmit` before componentDidMount
if (this.mounted && this.props.autosave) {
if (this.delayId) {
this.delayId = clearTimeout(this.delayId);
}
// Delay autosave by `autosaveDelay` milliseconds...
this.delayId = setTimeout(() => {
// ...and wait for all scheduled `setState`s to commit. This is required
// for AutoForm to validate correct model, waiting in `onChange`.
this.setState(
() => null,
() => {
this.onSubmit();
},
);
}, this.props.autosaveDelay);
}
}

I think we need to check if component is still mounted right before setState in line 226?

@radekmie radekmie self-assigned this Apr 6, 2021
@radekmie radekmie added the Type: Bug Bug reports and their fixes label Apr 6, 2021
@radekmie radekmie added this to the v3.3 milestone Apr 6, 2021
@radekmie
Copy link
Contributor

radekmie commented Apr 6, 2021

Hi @michaellill-corefihub. Thanks for the report! I think we'd rather clearTimeout it in componentWillUnmount instead.

@michaellill-corefihub
Copy link
Author

@radekmie Yes, that is even better.

@michaellill-corefihub
Copy link
Author

@radekmie Do you want me to provide a PR?

@radekmie
Copy link
Contributor

radekmie commented Apr 6, 2021

I'm already on it, but thanks 😄

radekmie added a commit that referenced this issue Apr 6, 2021
@radekmie radekmie linked a pull request Apr 6, 2021 that will close this issue
radekmie added a commit that referenced this issue Apr 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Bug reports and their fixes
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants