You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/fetch-router/.changes/minor.action-route-entry-types.md
+40-2Lines changed: 40 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
BREAKING CHANGE: Simplified route action helper types so `Action` and `BuildAction`no longer accept an unused request method type parameter. If you manually type route actions, pass only the route pattern or route object plus any request context type:
1
+
BREAKING CHANGE: Simplified route action and middleware helper types so they no longer accept unused request method type parameters. If you manually type route actions, pass only the route pattern or route object plus any request context type:
Renamed the custom router matcher payload type from `MatchData` to `RouteEntry`:
@@ -25,3 +25,41 @@ let matcher = createMatcher<MatchData>()
25
25
// after
26
26
let matcher =createMatcher<RouteEntry>()
27
27
```
28
+
29
+
If you manually annotate middleware, pass only the params type and context transform type:
30
+
31
+
```ts
32
+
// before
33
+
let middleware:Middleware<'ANY', {}, SetDatabaseContextTransform>
34
+
35
+
// after
36
+
let middleware:Middleware<{}, SetDatabaseContextTransform>
37
+
```
38
+
39
+
`Action` now accepts string patterns, `RoutePattern` objects, and `Route` objects directly. It also owns the optional action middleware tuple generic, so `BuildAction` is no longer exported.
40
+
41
+
For stored action objects with action-local middleware, the handler context can now be derived from the middleware tuple that actually runs. Previously, the action had to repeat the middleware's type effect with a manually refined context type. That was type-safe only as long as the manual context type and the runtime middleware stayed in sync:
Copy file name to clipboardExpand all lines: packages/fetch-router/README.md
+6-9Lines changed: 6 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -629,8 +629,8 @@ Route params are only half of a handler's type contract. In many apps, handlers
629
629
`fetch-router` now lets you carry that context contract through the router, controller, and action types directly. A common pattern is to derive one app-local context type from your router middleware, then reuse it across stored controllers and actions.
In this example, the action declares the stronger context it requires, and the action-local middleware makes that contract true at runtime. In a larger app, you can still derive a shared base context from router middleware with `MiddlewareContext<typeof middleware>` and build on top of it the same way.
655
+
In this example, the action-local middleware tuple gives the handler the stronger context it requires and makes that contract true at runtime. In a larger app, you can still derive a shared base context from router middleware with `MiddlewareContext<typeof middleware>` and build on top of it the same way.
0 commit comments