fix: log warning on invalid route configurations (#2954)

Related to #2953.

I found it confusing that there were unsupported route configurations,
that fails silently without any errors or wanings. Though I think it is
a good idea to not throw for this, as that would be worse DX. But
logging a warning if the developer is migrating from Fresh v1, or if the
developer is using code that will not work (e.g. copy pasting a handler
from a route to `_middleware`), I think it's helpful where reasonable to
help guide a bit more.

Does a small refactor first to hopefully improve typing to be more
correct for `InternalRoute.handlers`, then adds warnings for the
following:

- `_middleware` using Object form (`GET`, `POST` handlers) of the
handler format
  - Helps find issues when moving handler from route to middleware
- `_layout` using `handlers`
  - E.g. if developer moves a route to a layout
- ~~`_404`, `_500` or `_error` using Object handler form (`GET`, `POST`
handlers), which is not yet supported (See #2953)~~
  - No longer necessary as it is fixed by #2955
This commit is contained in:
Christian Svensson
2025-05-15 17:09:53 +02:00
committed by GitHub
parent 20162f6896
commit b852fe7deb
3 changed files with 68 additions and 9 deletions
+3 -2
View File
@@ -98,9 +98,10 @@ export type RouteHandler<Data, State> =
| HandlerByMethod<Data, State>;
export function isHandlerByMethod<D, S>(
handler: RouteHandler<D, S>,
handler: RouteHandler<D, S> | RouteHandler<D, S>[] | null,
): handler is HandlerByMethod<D, S> {
return handler !== null && typeof handler === "object";
return handler !== null && !Array.isArray(handler) &&
typeof handler === "object";
}
/**