Repository navigation
Public API for building and selecting client variants #7895
Replies: 3 comments 1 reply
|
This would resolve the longstanding generaltranslation/paraglide-js#88 issue. Some benchmarking With L similarly sized locales, the approximate reduction in client-side translation code is: 2 locales: ~50% |
|
interesting proposal! is there any prior art in any other framework? how does SSR work with multiple locales? does the server build have all translations available all the time? |
|
Adding numbers from a production app in case it helps prioritize this. Setup: TanStack Start 1.169, Paraglide 2.25 ( Before (gzip JS preloaded by each route chain, app entry included):
Every message module carries all 10 translations, so each page downloads ten languages of every string it renders. Stopgap we shipped: a client-only Vite transform keeps just the default locale inside each message module and resolves the other locales from a per-locale dictionary, which the client entry dynamic-imports before
The last column removes every other locale at compile time, which is roughly what per-locale client builds would give default-locale visitors. Visitors in the other nine locales would gain more: no ~90 KB dictionary and no extra round trip before hydration. The stopgap has costs that the proposed API would remove:
With |
Uh oh!
There was an error while loading. Please reload this page.
Problem
Plugins sometimes need multiple specialized versions of a TanStack Start client build.
Paraglide JS's
experimentalPerLocaleBuild, for example, builds one client graph per locale. Each graph receives a compile-time locale value, allowing Vite/Rolldown to tree-shake translations for every other locale.The Vite-native implementation is available in opral/paraglide-js#728. It generates independent locale environments without rewriting emitted chunks.
TanStack Start is already close because it uses Vite environments and owns
builder.buildApp. However, Start currently creates oneclientenvironment, captures one client build, serializes one Start manifest, and caches one production base manifest. Paraglide cannot safely compose with that without depending on private build and manifest internals.Proposed solution
Register client variants
Expose a public integration API that lets plugins request variants of Start's normal client environment. The names below are illustrative:
Start should clone its normal client inputs, route splitting, compiler transforms, and import protection for each variant. Start would retain ownership of output directories and manifests; plugins would never inspect or rewrite emitted chunks.
Build a manifest for each variant
Start's build orchestration would:
Select a variant per request
Add a selector to
createStartHandler, or an equivalent request option:The selected manifest should control
<Scripts />, route chunks, CSS and inline CSS, module preloads, early hints, and asset URL transforms. Production manifest caches must include the variant ID.The same selection should be honored while prerendering, allowing
/en/aboutand/de/aboutto reference different client graphs.Bundle-size impact
Without per-locale builds:
With per-locale builds:
For similarly sized catalogs, the translation portion approaches
1 / numberOfLocalesof the unsplit translation payload. The tradeoff is increased build time and deployment storage because shared application code may be emitted once per locale. The optimization targets bytes transferred to each visitor.The prototype verifies that other locales' translations are absent from executable JavaScript and source maps.
Expected behavior
This API could also support white-label builds, regional configuration, and build-time product editions.
All reactions