Skip to content

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

Closed

Description

@AbdulAAhmad

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions