[RFR] Improve translation loading - #3152
Merged
Merged
Conversation
added 2 commits
April 21, 2019 08:45
Contributor
|
Build is failing because you did not apply eslint on the modified files. |
Contributor
Author
|
Oops, true, fixed it. Thanks 🙌 |
djhi
approved these changes
Apr 21, 2019
djhi
left a comment
Contributor
There was a problem hiding this comment.
This might be improved to delay it for a short while, so there is no spinner when the messages are returned immediately.
I tried it on the demo. It does not even appear. It does trigger a useless state update though. I don't think it matters
|
|
||
| componentDidUpdate(prevProps) { | ||
| if (prevProps.locale !== this.props.locale) { | ||
| if (prevProps.locale !== this.props.locale || prevProps.messages !== this.props.messages) { |
Contributor
There was a problem hiding this comment.
You're comparing object references here for messages. This should be enough as the reference to the messages object should change when loading new ones
Member
|
Thanks! |
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.
These changes do two things:
When receiving a new locale and messages it's not only checked if the locale has changed but also if the messages have changed. This fixes Translations not updating using an async function as provider and not changing language key #3139 .
Object comparison might not be the best use here, but I think that the messages object won't be too large for it to still be performant.
It will start showing the fetch spinner before loading the translations and end it afterwards. This is useful when translations are loaded async. When it takes longer, the user doesn't know that anything is happening and then suddenly the strings switch.
This might be improved to delay it for a short while, so there is no spinner when the messages are returned immediately.