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 adds instructions for the use with sveltekit that avoids a tricky caveat regarding the way that Sveltekit uses stores on serverside:
On most SSR environments using the store directly – as you would in plain Svelte Apps – means localisation state is unintentionally shared between users.
For most smaller applications this doesn't have any visible effect because localisation state is set at the beginning of the request and the request is completed before another user's request is received.
But in high traffic environments and / or slow rendering pages the following could happen:
en
. State is set, the page starts rendering with localeen
.cn
. This modifies the globallocale
state.cn
!The Sveltekit docs explicitly state to avoid global stores for this reason:
https://kit.svelte.dev/docs/state-management
Fortunately this library uses i18next's
createInstance
function, so the fix is as easy as just usinggetContext
instead of using the store directly.