fix: avoid overriding of translations data from previous state #901
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.
Avoid overriding previous state translations data over new translations.
File
Please provide a brief description of the changes or additions made in this pull request.
return { result: { ...state.result, ...payload }, langCode: langCode.toLowerCase(), langDirection: isRtl ? 'rtl' : 'ltr', isLoading: false }
This would make the translations data in the result dirty.
Unless if there was a specific use case, due to which this is written like this {
...state.result, ...payload }
, we should avoid destructuring of new translations over previous state translations.Because, when there are keys that are present in Hindi translation but are not present in English translation file, it would retain such keys and its values when we change locale from Hindi to English due to this destructuring
{ ...state.result, ...payload }
Related Issues
If this pull request is related to any issue(s), please list them here.
#900
Steps to Test
This is basically because, there are some strings missing in then en_us translation file, due to which the logic {
...state.result, ...payload }
retained previous states translations.Although it is suggested to maintain translations data similar across locale, it is also a better practice to avoid merging previous translation object and new translation object.
Provide steps on how to test the changes introduced in this pull request.
Screenshots (if applicable)
If your changes include visual updates, it would be helpful to provide screenshots of the before and after.
Checklist