Repository navigation
Description
Which project does this relate to?
Router
Describe the bug
When loader is in a split grouping, a route whose loader uses the object form breaks the code splitter:
export const Route = createFileRoute('/posts/$id')({
loader: {
staleReloadMode: 'blocking',
handler: async ({ params }) => load(params.id),
},
component: () => null,
})- The
?tsr-split=loaderchunk throwsUnexpected splitNode type ☝️: ObjectExpression, so the build fails, and in dev the chunk fails to load. - The route file replaces the whole object with
lazyFn($$splitLoaderImporter, 'loader'), sostaleReloadModeis gone.
A handler() {} method and a handler imported from another file fail the same way.
Complete minimal reproducer
Steps to Reproduce the Bug
- Clone the gist, run
npm install, thennpm start. - The script runs
compileCodeSplitReferenceRouteandcompileCodeSplitVirtualRoutefrom@tanstack/router-plugin1.168.47 on the route above, with groupings[['loader'], ['component']]. - See
loader: lazyFn($$splitLoaderImporter, 'loader')in the route file andUnexpected splitNode type ☝️: ObjectExpressionfrom the loader chunk.
A Vite dev server with tanstackRouter({ target: 'react', autoCodeSplitting: true, codeSplittingOptions: { defaultBehavior: [['loader'], ['component']] } }) gives the same output and the same error from server.transformRequest('/src/routes/index.tsx?tsr-split=loader').
Expected behavior
Only handler moves to the loader chunk, and the route file keeps the other options:
loader: {
staleReloadMode: 'blocking',
handler: lazyFn($$splitLoaderImporter, 'loader'),
},A module-level binding read by both handler and another loader option should go to the ?tsr-shared=1 module, like any binding a split option shares with one that stays.
Screenshots or Videos
No response
Platform
- Router / Start Version:
@tanstack/router-plugin1.168.47; also onmain(b1b1117) - OS: macOS
- Browser: n/a (build time)
- Browser Version: n/a
- Bundler: vite
- Bundler Version: 8.3.4
Additional context
#8630 pins this as a known failure, and #8504 fixes it as part of the Yuku migration. I'll open a small fix for the current compiler. A loader object passed by reference (loader: loaderObject, the second pin in #8630) is a different case and not covered here.
AI disclosure: Claude Code wrote this report and the reproducer, and ran the reproducer against 1.168.47.
Activity
Sheraff commentedon Oct 18, 2026
FWIW we're in the process of rewriting the entire compiler
fix(router-plugin): split the handler of an object-form loader (#8753)
Merge branch 't3/object-loader-split' (an object-form loader's handle…