This repository has been archived by the owner on Jan 10, 2025. It is now read-only.
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.
This PR addresses a few performance concerns, one of which was the cause of the issue we had in Web when we tried to roll these out:
undefined
, we no longer call the subscription (this is technically a bit dangerous because theloading
property can get out of date, but we don't currently use this anywhere anyways, and this basically only happens for more detailed locales (e.g.,fr-CA
), where the consumer will get an update on thefr
part resolving just fineuseSimpleI18n
hook and, instead, madeuseI18n
bail out early when there are no options passed. This violates the rules of hooks, but we get around that by throwing an error if they try to switch between the two modesuseI18n
hooks linked up to theI18nContext
, any update to onei18n
object higher in the tree would cause all descendants' hooks to run again, which would be useless, because the IDs in question are still the same.ShareTranslations
component that gets returned is always the same function. This was the main cause of the incident we had: when the "highest" i18n-connected component had some translations that resolved async (even for locales likeen-CA
, which would do an async lookup for the-CA
languages), itsShareTranslations
would change. When that happened, the entire subtree below it got unmounted (this is how React's reconciliation works), then remounted. For a component like ourAdminNextFallback
, which sometimes makes non-idempotent get requests on mount, this could cause issues (like multiple GETs eventually causing full-page auth redirects).With these in place, the performance of i18n on load is much better. Here's the before/ after for a shop in
en-CA
:The
hydrate
bit is about the same length in both, So this basically shaves off 500–600ms.