Public API for building and selecting client variants #7895
samuelstroschein
started this conversation in
Ideas
Replies: 2 comments
|
This would resolve the longstanding opral/paraglide-js#88 issue. Some benchmarking With L similarly sized locales, the approximate reduction in client-side translation code is: 2 locales: ~50% |
0 replies
|
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? |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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