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

[RFC] lingui t macro demonstrate #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rwu823
Copy link

@rwu823 rwu823 commented Oct 5, 2023

Hi @thekip,

Could you help take a look at this and if there are any issues? It works well on both the server and client sides.

reference

lingui/js-lingui#1698

@timofei-iatsenko
Copy link
Owner

t is using a global i18n instance. Use it with a very big caution, especially in server setup.
The problem is that i18n singleton is "cached" on the module level (js modules feature) and shared between all your requests.

However, nodejs is processing requests from your users - concurrently, it means it can start processing another request while still waiting for some async operation of the first one. In this case, it may happen that global i18n instance would be switched to another language in the middle of processing first request.

So using global t in server side context has not obvious problems with delayed consequences.

@timofei-iatsenko
Copy link
Owner

The same is true for what you did for rsc trans file. Using global i18n instance will lead to the same problem as with t. In server context you always have to create a separate instance of i18n for every request, avoiding polluting from other users requests.

@rwu823
Copy link
Author

rwu823 commented Oct 5, 2023

@thekip Thanks for explaining. So, the purpose of using React.cache is to have a separate i18n instance for each request, right?

@rwu823 rwu823 changed the title fix: lingui t macro demonstrate [RFC] lingui t macro demonstrate Oct 6, 2023
@timofei-iatsenko
Copy link
Owner

Exactly.

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