Skip to content

SSR: multiple i18n instances vs calling loadAndActivate per request? #1804

Answered by thekip
pepijnvandenhoven asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, it's preferable to have an instance per request. And this instance should be passed to the React tree and never used globally. Keep in mind that macro such as t or plural using i18n instance globally if you haven't pass it explicitly like so t(i18n)`Hello!`.

The main gotcha with Server-side VS Client-side - your server process few requests simultaneously. And if you have any async jobs during the response (and you do have, because it's almost impossible to write an app without async) the one request may affect response of other requests.

Imagine the example with one global instance:

  1. Server receive [request 1] with EN language. loadAndActivate('en') is called
  2. Server renders couple o…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@pepijnvandenhoven
Comment options

@thekip
Comment options

@pepijnvandenhoven
Comment options

@thekip
Comment options

Answer selected by pepijnvandenhoven
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants