Skip to content

perf(translations): load every date-fns locale from one file on the server - #18577

Draft
AlessioGr wants to merge 1 commit into
mainfrom
perf/translations-server-date-fns-bundle
Draft

AlessioGr wants to merge 1 commit into
mainfrom
perf/translations-server-date-fns-bundle

Conversation

@AlessioGr

Copy link
Copy Markdown
Member

Written by AI (Claude Code). The measurements were also run by AI.

What

importDateFNSLocale loads one of 40 date-fns locales, each through its own import(). That's right for browsers, which only download the language they use. But bundlers compile every import() target, so server components and SSR also compiled all 40 locale files and their loaders.

Servers don't download anything, so they now load all locales from one bundled file, dist/dateFNS/all.js. The translations package imports its loader through #importDateFNSLocale, a package-private import defined in the imports field of package.json: browsers get the per-locale version, and everything else gets dist/importDateFNSLocale.server.js. The build checks that the server version only reads locales that all.js exports.

imports works like exports, but for paths a package only uses internally. Node, Next.js, Vite and esbuild all support it, and publishConfig points it at dist when the package is published, the same way it does for exports. Inside the monorepo, both point at the source file, as before.

Results

Fresh website template (Next.js 16.4.0, Turbopack), cold next dev at 4 threads, with locally packed packages: main, and main plus only this PR. Next.js 16.4 no longer logs compile times, so the /admin response time is measured without a browser and covers compiling and rendering the page. Times are medians of 6 interleaved runs, which vary by about ±0.2 s.

Cold next dev, 4 threads main This PR
Server component modules compiled for /admin 1,108 1,029 (−79)
SSR modules compiled for /admin 468 389 (−79)
Browser modules compiled for /admin 603 603
All modules compiled for /admin 2,250 2,092
/admin response time, opened first 4.73 s 4.71 s
/admin response time, after the front-end page 2.71 s 2.59 s

On its own, the response time change is within run-to-run noise.

🤖 Generated with Claude Code

…erver

Browsers still load one small file per locale. Servers don't download anything, so #importDateFNSLocale now resolves to a version that loads all locales from one bundled file, and server components and SSR compile about 8 translations modules instead of 48.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

📦 esbuild Bundle Analysis for payload

This analysis was generated by esbuild-bundle-analyzer. 🤖
This PR introduced no changes to the esbuild bundle! 🙌

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant