Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/curvy-chairs-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/solid-router': patch
---

fix server middleware type in solid-router
2 changes: 1 addition & 1 deletion packages/solid-router/src/fileRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class FileRoute<
TLoaderFn = undefined,
TChildren = unknown,
TSSR = unknown,
TMiddlewares = unknown,
const TMiddlewares = unknown,
THandlers = undefined,
>(
options?: FileBaseRouteOptions<
Expand Down
95 changes: 95 additions & 0 deletions packages/solid-router/tests/fileRoute.test-d.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,53 @@
import { expectTypeOf, test } from 'vitest'
import { createFileRoute, createRootRoute } from '../src'
import type { Route } from '@tanstack/router-core'

declare module '@tanstack/router-core' {
interface FilebaseRouteOptionsInterface<
TRegister,
TParentRoute,
TId,
TPath,
TSearchValidator,
TParams,
TLoaderDeps,
TLoaderFn,
TRouterContext,
TRouteContextFn,
TBeforeLoadFn,
TRemountDepsFn,
TSSR,
TServerMiddlewares,
THandlers,
> {
server?: {
middleware?: TServerMiddlewares
}
}

interface RouteTypes<
TRegister,
TParentRoute,
TPath,
TFullPath,
TCustomId,
TId,
TSearchValidator,
TParams,
TRouterContext,
TRouteContextFn,
TBeforeLoadFn,
TLoaderDeps,
TLoaderFn,
TChildren,
TFileRouteTypes,
TSSR,
TServerMiddlewares,
THandlers,
> {
middleware: TServerMiddlewares
}
}
Comment on lines +5 to +50

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check whether FilebaseRouteOptionsInterface / RouteTypes augmentations exist in production solid-router sources.
fd -t f -e ts -e tsx . packages/solid-router/src | xargs rg -nP "declare module '@tanstack/router-core'|FilebaseRouteOptionsInterface|RouteTypes\b" -C2

Repository: TanStack/router

Length of output: 5244


🏁 Script executed:

# Read the full module augmentation in fileRoute.ts
cat -n packages/solid-router/src/fileRoute.ts | sed -n '182,220p'

Repository: TanStack/router

Length of output: 1419


🏁 Script executed:

# Search for FilebaseRouteOptionsInterface augmentation in production
rg -nP "FilebaseRouteOptionsInterface" packages/solid-router/src

Repository: TanStack/router

Length of output: 41


🏁 Script executed:

# Search for FilebaseRouteOptionsInterface augmentation in router-core package
fd -type f -e ts -e tsx . packages/router-core | xargs rg -nP "FilebaseRouteOptionsInterface|declare module.*@tanstack/router-core" -C3

Repository: TanStack/router

Length of output: 14521


🏁 Script executed:

# Also check what's exported from packages/router-core/src/fileRoute.ts if it exists
cat -n packages/router-core/src/fileRoute.ts 2>/dev/null | head -100

Repository: TanStack/router

Length of output: 3102


🏁 Script executed:

# Read the full FilebaseRouteOptionsInterface definition in router-core
cat -n packages/router-core/src/route.ts | sed -n '944,1000p'

Repository: TanStack/router

Length of output: 1750


🏁 Script executed:

# Check if FilebaseRouteOptionsInterface has any augmentation in solid-router production code
rg -nP "declare module|server\?" packages/solid-router/src/fileRoute.ts packages/solid-router/src/route.tsx -C5

Repository: TanStack/router

Length of output: 1785


🏁 Script executed:

# Check what the start-client-core augmentation looks like for FilebaseRouteOptionsInterface
cat -n packages/start-client-core/src/serverRoute.ts | sed -n '15,80p'

Repository: TanStack/router

Length of output: 2161


Move module augmentations to solid-router production code.

The FilebaseRouteOptionsInterface and RouteTypes augmentations in this test file are test-only declarations. While start-client-core (the full-stack framework) includes these augmentations in production, solid-router (the routing library) does not. This means:

  • The test passes because it declares the types locally
  • End users of @tanstack/solid-router won't receive server.middleware typing support
  • The test doesn't actually validate what consumers experience

Move these augmentations to packages/solid-router/src/fileRoute.ts or a dedicated augmentation file so that users of solid-router get proper type support for server middleware.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/solid-router/tests/fileRoute.test-d.tsx` around lines 5 - 50, The
test declares module augmentations for FilebaseRouteOptionsInterface and
RouteTypes which hides a missing production augmentation; move these
declarations out of the test and into the solid-router source (e.g., add them to
packages/solid-router/src/fileRoute.ts or a new augmentation file in that
package) so that the server?: { middleware?: TServerMiddlewares } property on
FilebaseRouteOptionsInterface and the middleware: TServerMiddlewares field on
RouteTypes are exported as real library type augmentations and available to
consumers; update exports or add a .d.ts augmentation file within the
solid-router package containing the same interface augmentations and remove the
test-local declarations.


const rootRoute = createRootRoute()

Expand Down Expand Up @@ -100,3 +148,50 @@ test('when creating a folder group', () => {
expectTypeOf<'(auth)/protected'>(protectedRoute.path)
expectTypeOf<'/protected'>(protectedRoute.id)
})

<<<<<<< Updated upstream
test('when creating a file route with server middleware', () => {
const middleware = createMiddleware({ type: 'request' }).server(
({ next }) => {
return next({ context: { supportsGzip: true } })
},
)
=======
test('when creating a file route with middleware options', () => {
type Middleware = { readonly middleware: 'middleware' }
const middleware = { middleware: 'middleware' } as const
>>>>>>> Stashed changes
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

const route = createFileRoute('/invoices')({
server: {
middleware: [middleware],
},
})

type ExtractMiddlewares<TRoute> = TRoute extends Route<
any,
any,
any,
any,
any,
any,
any,
any,
any,
any,
any,
any,
any,
any,
any,
any,
infer TMiddlewares,
any
>
? TMiddlewares
: never

expectTypeOf<ExtractMiddlewares<typeof route>>().toEqualTypeOf<
readonly [Middleware]
>()
})
Loading