Skip to content

Translated client components would add about 12 KB of JavaScript to their pages #624

Closed

Description

@richshaw

Needs your OK: this turns on next-intl's experimental message precompiling, so a translated client component costs about 3 KB instead of about 12 KB. Nothing anyone sees changes. Swap pipeline:proposed for pipeline:ready to have it built.

What happens

The first client component to show translated text (the sign-up dialog, a later step in #619) would ship next-intl's runtime with its ICU parser: 11.6 KB gzipped, measured. /s/[slug] is budgeted at 127 KB (it was 132 KB when this was written) and kept within about 2 KB of its real size. With experimental.messages.precompile, messages are compiled at build time and the runtime drops to 2.8 KB. In a real Next build with one translated client component, /s/[slug]'s page chunk grew by 3.5 KB (measured on 25 October; measure again when this is built).

Fix, in outline

  • In the createNextIntlPlugin options, set experimental.messages to path: './src/messages', format: 'json', locales: 'infer' and precompile: true.
  • Import catalogs only as modules, never read them with fs in web code. The plugin's loader compiles what's imported, and a message that skips it loses its arguments silently in the web process.
  • Land it before any client component uses translations, so none ever ships the full runtime.

Watch for

  • Two formatters run in production. Inside the Next build every translator, server and client, formats precompiled messages; the worker and vitest format raw JSON with use-intl's full formatter. The guards: the catalog check compiles every message (Nothing checks the message catalogs, or catches new hard-coded text #623), src/email/templates/worker-render.test.ts renders emails under the worker toolchain, and the first participant text step adds a production-build e2e that renders a message with arguments.
  • Turbopack: the catalog loader needs Next 16 there. pnpm dev uses webpack on 15.5, so leave it that way.
  • It's experimental, so pin next-intl to an exact version. If it misbehaves, turning it off costs about 9 KB on the participant pages, and that budget raise needs its reason in the PR.

Order

After #620, because it configures the plugin #620 adds.

Done when

  • A server component and a test client component both render a message with arguments correctly in pnpm build && pnpm start.
  • pnpm budgets is unchanged.
  • pnpm lint && pnpm typecheck && pnpm knip && pnpm test pass.

Planned with the owner in https://claude.ai/code/session_01EFKmj716ZY3b3SwR8TV8Y2 and checked against the code on main at 35288fa. The full plan is private to the owner's account: https://claude.ai/artifact/VgQH6U2s2EVx3LX991fJi8 (a Claude session on that account can open it with the Artifact tool's read action). This is step 0.5 there.

Updated on 13 November 2026 against main at 4f67fd4: /s/[slug]'s budget is now 127 KB.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions