Replies: 2 comments
-
Imagine you have a single Now you receive two requests, one uses the locale Now imagine the loaders run in the server in this order (A and B are the requests):
Because This is why remix-i18next is creating an instance per getFixedT, each call could have a different locale but i18next will use the last you set. The only way the lib could give you a single instance should be if it was per locale or per request, but that would mean that instead of letting the runtime garbage collect the instance once the request is done and the instance is not used anymore. And you can do that, if you move the getFixedT call to getLoadContext in your HTTP server, you can pass the |
Beta Was this translation helpful? Give feedback.
-
Thanks for the thorough explanation!
This looks to me an optimization for space on the expense of performance. I can imagine that the Apart from that, don't you agree that exposing Thanks again for the great contribution to the community! |
Beta Was this translation helpful? Give feedback.
-
Thank you for the great work!
I have few questions. I read the code in
remix-i18next/build/server.js
and I notice that this library callsi18next.createInstance
whenever you callgetFixedT
. I wonder what is the reasoning behind that? How does this play when multiple loaders callgetFixedT
in the same request? Wouldn't this potentially lead to creating many instances?Also I see in the setup that the library user is supposed to call
i18next.createInstance
again inentry.server.tsx
and pass the instance toI18nextProvider
. Does it make more sense to use an instance created byremix-i18next
? This means the configuration doesn't need to be repeated in the constructor ofRemixI18Next
andinstance.init
with the inconsistency risk this duplication can bring?How about a singleton design where
RemixI18Next
keeps one instance and expose it so that it can be passed toI18nextProvider
?Looking forward to your ideas.
Beta Was this translation helpful? Give feedback.
All reactions