-
Notifications
You must be signed in to change notification settings - Fork 397
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
I18nProvider remounts all the children, but not rerender #1136
Comments
comments in code:
i18n is not changed, but dependency list can hold it's properties, then memo is recalculated on deep changes in i18n There is another stuff in code:
useState may be passed a function as a parameter, it is named initialState, but you use it like useMemo for tracking props. It's really bad practice to have initialState parameter recalculated on each render. I would write
BTW makeContext may be wrapped in useCallback |
Hi mate, when we worked on the reimplementation of Lingui 3 we forgot a lot about the React side, also we lost a bit the north. I'll be happy to review a pull request from you making the React implementation much better than it is right now. |
instead of using |
Ok, ignore my previous comment, I talked before looking at the code. After analysis the issue, I think there are mainly a hole in the documentation and a bad option naming. Children of Buuuuut not everything re-render if there is a memo in the tree somewhere under the provider. Only the React parts receiving locale related prop or using context will re-render alone. So using So I understand the why behind the I suggest 2 actions:
const {i18n} = useLingui()
const message = t(i18n)`Hello World` |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
plzzz stale bot :) |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Was just running into this as well. probably just stupidity on my side: |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
not stale |
A remount seems a bit heavy handed esp for larger apps and could lead to some really hard to debug bugs. I probably won't have time to contribute to this in a form of a PR but if we can create a bounty I'll contribute. I'm not sure we currently can due to the stale bot closing this though. |
@JSteunou we are going to release v4 soon, and it seems it's a good time to fix this as well. Would you want to participate and prepare a PR? Or at least code-review if i implement what you mentioned in the comment above? |
I'm experiencing an issue where my entire app re-mounts for non-US-english translations. I've described my issue in depth here on StackOverflow. Please let me know if you have any guidance. Thanks so much! |
I'm a bit late but kudos it works fine. The only issue now is that migration path is not that easy because of a limitation pointed out by @vonovak about the use of @thekip you though about a new macro |
Describe the bug
I18nProvider
implementation has a very unpleasant effect of changing own key when locale changes. It declares, that forceRenderOnLocaleChange force rerender of all children. Sorry, but its not a rerender, it's full remount of it's children. As a result React.memo is killed and state of all the components is reset. I have google map inside and its remount is slow and flickeringTo Reproduce
Expected behavior
It would be great to have all the components just rerendered, not remounted. It is usually done with a trick like having state with counter and incrementing it by one every time we need children to be rerendered.
I cannot have a single global
I18nProvider
as it remounts everything inside, the heavy components like maps are remounted with unpleasant flicker.Additional context
The text was updated successfully, but these errors were encountered: