Skip to content

context returned from server middleware is incorrectly typed as undefined only in Solid Start #7092

Closed

Description

@njGroters

Which project does this relate to?

Start

Describe the bug

The type of the context object which has passed through server middleware is incorrectly inferred as undefined. When I log out the context object, it does actually have the fields I would expect from the middleware, they're just missing from the type.

The context object comes from route middleware in a parent route and is accessed in a child route's server handler. I'm not sure if that's relevant, though. Adding the middleware array directly to the child route's middlleware array also does not correctly set the type on context, it's still typed as undefined. I've added an example in my reproduction to show this.

It seems like the issue is limited to Solid Start. I've recreated the same routes and middleware in React Start and the types are properly inferred. I've included this example in my reproduction for reference.

Your Example Website or App

https://github.com/njGroters/tanstack-context-reproduction

Steps to Reproduce the Bug or Issue

  1. Clone the repo
  2. Step into the solid-broken folder
  3. Run npx tsc and see that context is typed as 'undefined'
  4. Start the local dev server and visit http://localhost:3000/api/public/example. You should see a stringified context object which does have the supportsGzip field
  5. Step to the repo's root level and then into the react-working folder
  6. Run npx tsc and see that context is not typed as 'undefined' despite getting created and accessed in the same way

Expected behavior

I would expect the type of context to be inferred from the shape of the data returned under the context field from my middleware chain instead of undefined. This is the result I see in React Start, but not Solid Start.

Screenshots or Videos

No response

Platform

  • Start Version: latest (1.167.15)
  • OS: macOS
  • Browser: Firefox
  • Browser Version: 149.0
  • Bundler: vite
  • Bundler Version: 7.3.1

Additional context

No response

Activity

  1. njGroters commented on Apr 3, 2026

    @njGroters
    Author

    When I compare the type signatures on the GET server handler in the nested route, it does appear that the context's type is in there, but it's slightly different between the two frameworks 👀

    React has the request's middleware type in a tuple ([RequestMiddlewareAfterServer<{}, undefined, { supportsGzip: boolean; }>]) whereas Solid has it in an array in the same place (RequestMiddlewareAfterServer<{}, undefined, { supportsGzip: boolean; }>[])

    Full React type

    (property) GET: ({ context }: RouteMethodHandlerCtx<Register, Route<Register, RootRoute<Register, undefined, {}, AnyContext, AnyContext, {}, undefined, unknown, unknown, unknown, unknown, undefined>, "/api/public", "/api/public", "/api/public", "/api/public", undefined, ResolveParams<"/api/public">, AnyContext, AnyContext, AnyContext, {}, undefined, unknown, unknown, unknown, readonly [RequestMiddlewareAfterServer<{}, undefined, {
        supportsGzip: boolean;
    }>], undefined>, "/example", ResolveParams<...>, unknown, any>) => Response

    Full Solid type

    (property) GET: ({ context }: RouteMethodHandlerCtx<Register, Route<Register, RootRoute<Register, undefined, {}, AnyContext, AnyContext, {}, undefined, unknown, unknown, unknown, undefined>, "/api/public", "/api/public", "/api/public", "/api/public", undefined, ResolveParams<"/api/public">, AnyContext, AnyContext, AnyContext, {}, undefined, unknown, unknown, unknown, RequestMiddlewareAfterServer<{}, undefined, {
        supportsGzip: boolean;
    }>[], undefined>, "/example", ResolveParams<...>, unknown, any>) => 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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions