router icon indicating copy to clipboard operation
router copied to clipboard

Middleware doesn't run when server function factory is re-exported using `export { } from` or `export * from` syntax

Open AbdulAAhmad opened this issue 1 month ago • 0 comments

Which project does this relate to?

Start

Describe the bug

When re-exporting a server function factory (created with createServerFn().middleware([...])), the export syntax affects whether middleware executes. Using export { foo } from "./module" or export * from "./module" causes middleware to be silently skipped, resulting in an empty context object.

Your Example Website or App

https://github.com/AbdulAAhmad/start-bare-serverfn-factories-export

Steps to Reproduce the Bug or Issue

  1. Clone the repo and run nvm use && pnpm install && pnpm dev
  2. Navigate to / route
  3. Observe console: context {} — middleware did not run
  4. In src/lib/index.ts, switch from: export { authedServerFn } from "./wrappers"; to: import { authedServerFn } from "./wrappers"; export { authedServerFn };
  5. Refresh the page
  6. Observe console: AUTH MIDDLEWARE RUNNING and context { user: {...}, session: {...} }

Expected behavior

Export syntax should not affect middleware execution. Both export styles should result in middleware running and context being populated.

Screenshots or Videos

No response

Platform

  • Router / Start Version: 1.139.14
  • OS: macOS
  • Browser: Chrome
  • Browser Version: N/A
  • Bundler: vite
  • Bundler Version: 7.1.7

Additional context

No response

AbdulAAhmad avatar Dec 05 '25 12:12 AbdulAAhmad