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

Sveltkit is using shared global store server-side (SSR) #746

Closed
cristovao-trevisan opened this issue Nov 1, 2023 · 2 comments
Closed

Sveltkit is using shared global store server-side (SSR) #746

cristovao-trevisan opened this issue Nov 1, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@cristovao-trevisan
Copy link

cristovao-trevisan commented Nov 1, 2023

Version

5.26.2

Describe the bug

Current svelte implementation is using a global LL store, which is shared server side thus may cause inconsistent language with SSR.
As per sveltekit docs # avoid shared state stores should never be global (should not be exported in .ts and .js files), but the current code does so:

const { locale, LL, setLocale } = initI18nSvelte<Locales, Translations, TranslationFunctions, Formatters>(loadedLocales, loadedFormatters)

There are two options to fix this problem that I'm aware off:

  • use context to set the store in layout.svelte (and further acquire LL from the context again)
  • use the $app.data (PageData) to set the store in layout.ts

Context usage can also be simplified using components, for example:

  • +layout.svelte
<LangProvider locale={initLocale()}>
  <slot />
</LangProvider>
  • +page.svelte
<Locale let:LL>
  {LL.HI()}
</Locale>

Reproduction

This is hard to reproduce consistently since it's a race condition (multiple requests with different languages at the same time).
The thing is, as per kit's docs, stores should not be global, so the bug is there as long as there is a global store being used.

Logs

No response

Config

No response

Additional information

No response

@cristovao-trevisan cristovao-trevisan added the bug Something isn't working label Nov 1, 2023
@cristovao-trevisan cristovao-trevisan changed the title Sveltkit is using shared global store server-side Sveltkit is using shared global store server-side (SSR) Nov 1, 2023
@cristovao-trevisan
Copy link
Author

Related issue at similar lib: cibernox/svelte-intl-precompile#39

@Cluster2a
Copy link

This project is not maintained anymore - 739.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants