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

Translation reset after component is unmounted with useTranslation #801

Closed
durasj opened this issue Mar 24, 2019 · 3 comments
Closed

Translation reset after component is unmounted with useTranslation #801

durasj opened this issue Mar 24, 2019 · 3 comments

Comments

@durasj
Copy link

@durasj durasj commented Mar 24, 2019

I've already mentioned this bug in the #796 (comment). If the namespace is loaded after the component is no longer mounted, the React logs errors

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.
in Child (created by App)

Occurs in latest stable at the time of writing - #15.0.6 and react-i18next#10.5.1.

To Reproduce
I've forked the code sandbox - https://codesandbox.io/s/qxj1xykyww

There is a custom backend that resolves only after 5 secs. Before it does, click on the "Toggle child" to remove the child. After 5 secs, error should appear in the console.

Expected behaviour
Loading should be either cancelled or reset should not happen if the component is not mounted anymore. Solution proposals mentioned in the #796 (comment)

@jamuhl

This comment has been minimized.

Copy link
Member

@jamuhl jamuhl commented Mar 24, 2019

ok this happens only in the non-suspense case -> so it's save to loadNamespaces in a useEffect for that case to keep that isMounted in a closure

@jamuhl

This comment has been minimized.

Copy link
Member

@jamuhl jamuhl commented Mar 25, 2019

should be fixed in react-i18next@10.6.0

If you like this module don’t forget to star this repo. Make a tweet, share the word or have a look at our https://locize.com to support the devs of this project -> there are many ways to help this project 🙏

@durasj

This comment has been minimized.

Copy link
Author

@durasj durasj commented Mar 25, 2019

I can confirm this is fixed in the 10.6.0. Thank you for the quick fix and good luck with the locize!

@durasj durasj closed this Mar 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.