Skip to content

pathname is undefined in global request middleware registered via createStart() #6647

@kkznch

Description

@kkznch

Which project does this relate to?

Start

Describe the bug

When using createStart({ requestMiddleware }) to register global request middleware, the pathname property passed to the middleware's server function is undefined at runtime, despite the TypeScript type RequestServerOptions declaring it as pathname: string.

Root Cause:

In packages/start-server-core/src/createStartHandler.ts, the two executeMiddleware calls for global request middleware do not include pathname in the initial context object:

  • Server function path (L532-535): { request, context } — missing pathname
  • Page request path (L626-629): { request, context } — missing pathname

The route-level middleware execution in handleServerRoutes (L784-789) correctly passes pathname.

The url variable (new URL(request.url) via getNormalizedURL) is already available in scope, so the fix is simply adding pathname: url.pathname to both call sites.

Your Example Website or App

N/A (root cause is clearly visible in source code)

Steps to Reproduce the Bug or Issue

  1. Register a request middleware via createStart():
const myMiddleware = createMiddleware({ type: 'request' }).server(
  async ({ pathname, next }) => {
    console.log(pathname) // → undefined (should be a string)
    return next()
  },
)

export const startInstance = createStart(() => ({
  requestMiddleware: [myMiddleware] as const,
}))
  1. Access any page or call any server function
  2. pathname is undefined

Expected behavior

pathname should be a string containing the request path (e.g., /api/users), as declared in the RequestServerOptions type.

Screenshots or Videos

No response

Platform

  • Router / Start Version: 1.159.4
  • OS: macOS
  • Browser: N/A (server-side)
  • Browser Version: N/A
  • Bundler: vite
  • Bundler Version: N/A

Additional context

A fix PR will be submitted shortly.

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