add initialize prop to LocaizeProvider to support SSR #127
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.
Proposed fix for #125 and #103 both related to server side rendering.
Issue:
The library currently doesn't work with server side rendering, as the initial context for LocalizeProvider has no values for
languages
, ortranslations
until theinitialize
action is called.Since no the state changes triggered by the
initialize
action will be tracked on the server this results in the empty context. This causes issues when the server attempts to render components with translations, and results in errors being thrown because of missing languages, and translation data.Solution:
Allow for passing
initialize
payload as a prop toLocalizeProvider
. If using server side rendering this would be the required way toinitialize
, and would need to be done on the server and the client.Example:
Instead of repeating the initialize payload on both the server, and client you could use a workflow that is well known for Redux and SSR where the initialState is stored in a window object. That is really up to the user to decide.
If using server side rendering this will be used in place of the
initialize
action that would usually be called from a component lifecycle method. If not using server side rendering this prop could also be used in place of theinitialize
action call, that is up to the user, and what use case works best for them.