fetch-router@0.18.0
Breaking Changes📦 remixView on GitHub →
⚠ 5 breaking✨ 2 features🔧 13 symbols
Summary
This release introduces significant breaking changes to context handling and route definition structures, moving context management to explicit key-value storage on the request context and standardizing action controller shapes. It also updates internal dependencies.
⚠️ Breaking Changes
- Action objects now use the `handler` property instead of `action` when passed to `router.get(...)`, `router.post(...)`, and `router.map(...)`, and in `BuildAction` object definitions. Fix: Replace `action: handlerFn` with `handler: handlerFn` in route definitions.
- Removed `context.storage`, `context.session`, `context.sessionStarted`, `context.formData`, and `context.files` from `@remix-run/fetch-router`. Fix: Use request-scoped context methods `context.get(key)`, `context.set(key, value)`, and `context.has(key)` with keys created by `createContextKey(...)` or constructors like `Session` and `FormData`.
- Renamed `createStorageKey(...)` to `createContextKey(...)`. Fix: Update calls to use `createContextKey(...)`.
- `RequestContext` no longer accepts a request-method generic (`RequestContext<'GET', ...>`); it is now generic over route params and typed context entries (`RequestContext<{ id: string }, entries>`).
- `router.map()` controllers now require a single shape: an object with an `actions` property and optional `middleware`. Fix: Wrap existing controller objects in `{ actions: existingController }`. Nested route maps must also use nested controllers with `{ actions, middleware? }`.
Migration Steps
- Replace `action: handlerFn` with `handler: handlerFn` in route definitions passed to `router.get`, `router.post`, and `router.map`.
- Update usage of removed context properties (`context.storage`, `context.session`, etc.) to use `context.get(key)`, `context.set(key, value)`, or `context.has(key)` with context keys.
- Rename calls from `createStorageKey(...)` to `createContextKey(...)`.
- Update `RequestContext` instantiation to remove the request method generic parameter.
- Wrap existing controller objects passed to `router.map()` in an object containing an `actions` property: `{ actions: existingController }`.
✨ New Features
- Exported helpers `MiddlewareContext`, `WithParams`, `MergeContext`, and `AnyParams` from `fetch-router` to allow deriving context contracts from installed middleware.
- The `Action`/`BuildAction` object form accepted by routing methods now supports omitting the `middleware` property when no route middleware is needed, instead of requiring `middleware: []`.