Skip to content
Source
Sign inSign up
TanStack/router

router-plugin: object-form loader breaks the code splitter when loader is split #8753

Send to my agent
Openshkumbinhasani(GitHub profile, opens in a new tab) opened this issue 1 comment

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=loader chunk throws Unexpected 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'), so staleReloadMode is gone.

A handler() {} method and a handler imported from another file fail the same way.

Complete minimal reproducer

https://gist.github.com/shkumbinhasani/0d4a67a26c2137a6e1ba1501a72e6e10

Steps to Reproduce the Bug

  1. Clone the gist, run npm install, then npm start.
  2. The script runs compileCodeSplitReferenceRoute and compileCodeSplitVirtualRoute from @tanstack/router-plugin 1.168.47 on the route above, with groupings [['loader'], ['component']].
  3. See loader: lazyFn($$splitLoaderImporter, 'loader') in the route file and Unexpected splitNode type ☝️: ObjectExpression from 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-plugin 1.168.47; also on main (b1b111761)
  • 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.

  1. FWIW we're in the process of rewriting the entire compiler

Sign in to join this conversation.