Middleware should run even if there is no loader #12950
Replies: 2 comments
-
I agree that middlewares should run regardless if the route has a loader or not, at least of routes behind the umbrella of the the middleware, so if you add a middleware in root every route will be under that middleware, but if you add it to a layout route other routes not nested inside should not trigger it. |
Beta Was this translation helpful? Give feedback.
-
Also at a minimum it would be super helpful to have the behaviour clearly documented (with most common use cases like logging and auth as examples), before middleware is deemed 'stable'. Also would be worth clarifying in the docs that a new context is instantiated on every invocation of the createRequestHandler (which is helpful, for example on Cloudflare Workers, for ensuring context data isn't shared between multiple requests to the same Worker process/isolate from different users). Maybe some kind of diagram would even be helpful for folks. It feels deserving of an entire page on the docs to explain all the aspects of Middleware so that folks can use it correctly and not have to dig through source code to understand how/when it is called and with what context. |
Beta Was this translation helpful? Give feedback.
-
The soon to ship middleware feature is currently coupled to the need to run a loader/action. So, routes without a loader will not participate in middleware. This is problematic for routes that do not have a loader for many valid reasons. One example: I want to continue to use
useQuery
in a route or don't have time to migrate, but I still want to protect that route with an auth middleware.In my custom implementation of middleware in
dataStrategy
, I have to addloader: () => null
to routes that I want to "force" into the middleware matching. This is not obvious and is a confusing DX/API. It also creates cruft on a bunch of routes that haven't been converted to use loaders yet.Should middleware opt a route into the dataStrategy/revalidation?
Beta Was this translation helpful? Give feedback.
All reactions