This website requires JavaScript.
About
Status
₊˚⊹Discord
Explore
Register
Sign in
Reference in a new issue
Blame
Copy permalink
Reference in a new issue
Copy permalink
TanStack
/
router
Star
0
Fork
You've already forked router
0
mirror of
https://github.com/TanStack/router.git
synced
2026-11-16 19:38:07 +00:00
Code
Issues
Releases
Packages
Activity
devtools-solid-2
router
/
packages
/
router-plugin
/
tests
/
code-splitter
/
snapshots
/
react
/
1-default
/
shared-function@shared.tsx
5 lines
114 B
Raw
Permalink
Normal View
History
fix: shared virtual module for code-split routes (#6659) * fix: shared virtual module for code-split routes When a route file has module-level bindings (variables, functions, classes) referenced by **both** split and non-split route properties, the bindings are duplicated — initialized independently in the reference file and in each virtual split file. This breaks singletons, causes double side effects, and wastes bundle size. ```tsx const collection = { name: 'todos', preload: async () => {} } export const Route = createFileRoute('/todos')({ loader: async () => { await collection.preload() }, // stays in reference component: () => <div>{collection.name}</div>, // split to virtual }) ``` In this example, `collection` is initialized in **both** the reference file (because `loader` references it) and the `?tsr-split=component` virtual file (because the component references it). Two separate instances exist at runtime. To solve this issue, this PR introduces a third virtual module `route.tsx?tsr-shared=1` that contains shared bindings. Both the reference and virtual files import from it. When `sharedBindings` is empty (the common case — component-only helpers, loader-only code), no shared module exists and the system works exactly as today. The reference transform runs first and will emit a static import of `?tsr-shared=1` **only when needed**. Since split chunks are only discovered via the reference file's emitted `import('...?tsr-split=...')`, the bundler will always process/evaluate the reference module first. Result: the shared module is evaluated once and then reused by any later-loaded split chunk.
2026-02-14 13:10:54 +01:00