Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sveltekit instructions #12

Merged
merged 1 commit into from
Sep 7, 2023
Merged

Add sveltekit instructions #12

merged 1 commit into from
Sep 7, 2023

Conversation

Lobidu
Copy link
Contributor

@Lobidu Lobidu commented Sep 1, 2023

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:

  • User A has a locale en. State is set, the page starts rendering with locale en.
  • While user A's request is still being rendered on the server, User B makes a request with a different locale, say cn. This modifies the global locale state.
  • User A's request will now finish rendering with locale 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 using getContext instead of using the store directly.

@NishuGoel
Copy link
Owner

Thanks for the PR @Lobidu LGTM ✅

@NishuGoel NishuGoel merged commit d4ed801 into NishuGoel:main Sep 7, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants