createFileRoute() doesn't pass context from global middleware -- FIXED
EDIT: I figured out this issue is fixed in a commit a few days ago:
https://github.com/TanStack/router/commit/41cc7e19ef6f40538cd621d54ca7a478e301a703
I have a global middleware that adds a session to context. It's included like this:
It works perfectly on server function routes. But on a file route, the context is an empty object, despite having proper types:
The global authMiddleware actually runs on this route, but the context is lost.
If I explicitly add the auth middleware to the createFileRoute's server object, the context is filled properly. However, in that case authMiddleware runs twice on this route.
When I trace the innards, it looks like the handleServerRoute() function in createStartHandle.js doesn't accept the middleware's context and runs its own middleware chain which doesn't include the global middleware.
Is it possible there's a bug here? It seems like if the global middleware runs, the context should be passed through.
GitHub
fix: pass server context to handler (#5601) · TanStack/router@41cc7e1
Co-authored-by: Samy Alzahrani <samyalzahrani@MacBook-Air.local>
0 Replies