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

[useTranslation] Avoid setting the new t function if the component is unmounted. #1051

Merged
merged 1 commit into from
Mar 20, 2020

Conversation

zozoens31
Copy link
Contributor

Once the translations are loaded from backend, the hook sets its t function without checking that the component is still mounted, which induces an error from react-dom.

Warning: 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 a useEffect cleanup function.

I've updated the code to keep the isMounted pattern to be consistent with the previous version, but I'll gladly change it for a promise cancellation if you find it more appropriate.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.01%) to 95.327% when pulling ee21d84 on bayesimpact:cyrille-no-callback into c764b02 on i18next:master.

@sprilukin
Copy link

+1 for the issue.

@jamuhl
Copy link
Member

jamuhl commented Feb 11, 2020

Looks valid...never run into this myself - but thinking about it the case is valid. Will deeper check this when back from holidays (this weekend, early next week) and merge this into master.

@jamuhl jamuhl merged commit b375857 into i18next:master Mar 20, 2020
@jamuhl
Copy link
Member

jamuhl commented Mar 20, 2020

sorry forgot about this one...published in react-i18next@11.3.4

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

Successfully merging this pull request may close these issues.

4 participants