SSR: multiple i18n instances vs calling loadAndActivate per request? #1804
-
I stumbled into an issue with Next.js SSR and came across a related issue here. It refers to the example over here. I was wondering if there are any suggestions on the note that's in the
Is it really preferable to have an instance per locale over calling |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
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 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:
I believe initial design of Lingui was created when more SPA application was developed, now we see a shift towards MPA application with SSR rendering and concepts from original design become confusing for people. |
Beta Was this translation helpful? Give feedback.
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
orplural
using i18n instance globally if you haven't pass it explicitly like sot(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:
loadAndActivate('en')
is called