Repository navigation
fix(widget): re-render i18n consumers when strings are added (JUM-1733) - #918
Merged
Merged
Conversation
🦋 Changeset detectedLatest commit: c927d15 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
📦 Bundle size✅ No significant changes. Every check is within budget. @lifi/widget
@lifi/wallet-management
@lifi/widget-light
Providers
Full integration
How to read this
|
Contributor
✅ E2E Dev Smoke — passing
4 passed · 0 failed · 0 skipped · 23s |
Contributor
E2E Playground resultsDetails
📥 Download full HTML report (open the run → Artifacts → |
Contributor
E2E Examples — all passedAll examples passed in the latest run. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which Linear task is linked to this PR?
JUM-1733
Why was it implemented this way?
The problem
With
languages.default: 'fr'and nothing saved, the widget tabs and often Send, Receive and Select can stay in English. The rest of the widget is French. We saw this on jumper.xyz/fr.The cause
languages.default: 'fr'and nothing saved,I18nProvidercreates the i18n instance withlng: 'fr'but without French strings. The first render shows the English fallback.fr.jsonarrives, the widget adds it withaddResourceBundle. The language does not change, so nolanguageChangedevent fires.useTranslationconsumers only onlanguageChanged, becausebindI18nStoreis''by default. A memoized component, such as the navigation tabs, keeps the English text.The same thing occurs for a returning user with old saved strings. The widget loads the new strings and adds them, but memoized components keep the old text. The result depends on timing.
The fix
react: { bindI18nStore: 'added' }. AlluseTranslationconsumers now re-render when the instance adds strings.I18nProvideradds a changed language cache in an effect, not inuseMemo. Theaddedevent then fires after the commit and does not update other components during a render. A ref skips the cache that the instance already has at creation.I18nProvidercreates the i18n instance one time withuseState. Before, auseMemowith a ref did the same job.Alternatives that I did not use
changeLanguageagain after the widget adds a bundle. This was the first version of this PR. It fixes the fresh load, but not the old saved strings. It also fails when the bundle arrives through the store rehydration before the hook runs.How I checked it
I18nProvider.test.tsxhas 3 tests: a fresh load, and old saved strings with and withoutlanguages.default. All 3 fail onmainand pass with the fix.next dev) with a proxy that delays the widget's French chunk by 3 s:mainhere): 3 of 6 fresh loads of/frshowed English tabs and an English Send / Receive / Select card.widget-playground-vite) with the navigation tabs and a proxy that delaysfr.jsonandes.jsonby 3 s:main: 2 of 4 fresh loads withlanguages.default: 'fr'stayed English (tabs and the From / To / Send labels).languageResourcesforfrandenshowed in all 4 loads.languages.allow: ['fr', 'es'], the menu showed only these 2 languages. A switch to Spanish changed the widget at once.main(about 450 ms in dev mode).Known items that this PR does not change
useLanguagesand once in the provider effect. This gives one extra re-render for each switch.availableLanguagesinuseLanguagesdoes not update when a bundle loads later, becausei18n.store.datakeeps the same identity.languages.defaultreplaces a language that the user saved.Visual showcase (Screenshots or Videos)
Not applicable. The Linear task has screenshots of the bug.
Checklist before requesting a review