Drawbacks of manually supplying messages to context provider over using getMessages
?
#1419
-
I am in the process of splitting up my i18n file into server and client files to reduce the amount of strings sent to the client as well as keeping certain strings on the server in order to not have them accessible by data mining. My setup is fairly simple as follows: // global.d.ts
type ClientMessages = typeof import('@/i18n/en.client.json')
type ServerMessages = typeof import('@/i18n/en.server.json')
declare interface IntlMessages extends ClientMessages, ServerMessages {} // request.tsx
export default getRequestConfig(async () => {
// ...
return {
// ...
messages: {
...(await import('@/i18n/en.client.json')).default,
...(await import('@/i18n/en.server.json')).default,
},
// ...
}
}) // layout.tsx
const getClientMessages = cache(async () => (await import('@/i18n/en.client.json')).default)
export default async function RootLayout({ children }: { children: ReactNode }) {
// Is there any differences/drawbacks using my second approach to hide server variables?
const messages = await getMessages()
const messages = await getClientMessages()
return (
{/* ... */}
<NextIntlClientProvider messages={messages}>
{children}
</NextIntlClientProvider>
{/* ... */}
)
} As the comment in the layout suggests, I'd like to ask whether there is functionally any difference between the two lines in the layout that I should be aware of. In terms of DX I am aware of the typing not being narrow enough or rather not contextual enough to display only client/only server variables, but I've written a small tool that "lints" my use of variables based on context and complains in case I do something wrong as such I'm only curious about the use of my function in the layout. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Your approach with passing messages from There's a bit more about this here: The ultimate goal would be to automatically detect which messages are needed for the client side btw.: #1. Is your tool that lints for client messages available somewhere? Or can you briefly explain how it works? Would be curious :) |
Beta Was this translation helpful? Give feedback.
Your approach with passing messages from
getClientMessages
is absolutely fine!There's a bit more about this here:
The ultimate goal would be to automatically detect which messages are needed for the client side btw.: #1.
Is your tool that lints for client messages available somewhere? Or can you briefly explain how it works? Would be curious :)