Skip to content

Merge nested NextIntlClientProvider messages #1890

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

Open
noahbald opened this issue May 16, 2025 · 1 comment
Open

Merge nested NextIntlClientProvider messages #1890

noahbald opened this issue May 16, 2025 · 1 comment
Labels
enhancement New feature or request unconfirmed Needs triage.

Comments

@noahbald
Copy link

noahbald commented May 16, 2025

Is your feature request related to a problem? Please describe.

The problem I'm running into is with our project's monorepo setup. Essentially, we have many siloed translations and many shared translations, as such there are many unnecessary translations that get included when using the client provider.

We end up with long blobs in the HTML, like this

<script>
  self.__next_f.push([1, "28:{\"example\":\"lots of json\"])
</script>

To get around this we're looking into splitting each of our routes to use only the set of translations the need

// ...home/layout.tsx

import homeMessages from "./homeMessages"
import sharedMessages from "./sharedMessages"

return <NextIntlClientProvider
  messages={{
    home: homeMessages,
    shared: sharedMessages,
  }}>
  {children}
</NextIntlClientProvider>

This works to an extent, however we now run into the case that duplicate blobs end up in the html, essentially because we're reusing translations in seperate layouts.

The tree might look something like this

<... some stuff>
  <layout 1>
     <!-- shared translations ends up in a blob for this -->
     <NextIntlClientProvider messages={{ shared }}>
       ... components using stuff
       <layout 2>
         <!-- shared translations also ends up in a blob for this -->
         <NextIntlClientProvider messages{{ shared, home }}>
           ... components using stuff and home
         </NextIntlClientProvider>
       </layout 2>
     </NextIntlClientProvider>
    </layout 1>
</... some stuff>

Describe the solution you'd like

Unless there's already a solution for this, I'd like to suggest that nested instances of NextIntlClientProvider could inherit it's parent's translations.

By doing this we can improve how much data needs to be send to the client.

Describe alternatives you've considered

I could probably improve how I'm doing imports. I think this is coming from the server/client boundary, still looking into it

@noahbald noahbald added enhancement New feature or request unconfirmed Needs triage. labels May 16, 2025
@amannn
Copy link
Owner

amannn commented May 16, 2025

Hey, there was some previous discussion on this here: #1413 (comment)

#1 is intended to be the solution to this problem, I hope to find time to work on this in the near future!

In the meantime, you can of course merge messages yourself in userland.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request unconfirmed Needs triage.
Projects
None yet
Development

No branches or pull requests

2 participants