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
<docs-info>This is only applicable if you were using a custom server in Remix v2. If you were using `remix-serve` you can skip this step.</docs-info>
102
+
103
+
If you were using `getLoadContext` in your Remix app, then you'll notice that the `LoaderFunctionArgs`/`ActionFunctionArgs` types now type the `context` parameter incorrectly (optional and typed as `any`). These types accept a generic for the `context` type but even that still leaves the property as optional because it does not exist in React Router SPA apps.
104
+
105
+
The proper long term fix is to move to the new [`Route.LoaderArgs`][server-loaders]/[`Route.ActionArgs`][server-actions] types from the new typegen in React Router v7.
106
+
107
+
However, the short-term solution to ease the upgrade is to use TypeScript's [module augmentation][ts-module-augmentation] feature to override the built in `LoaderFunctionArgs`/`ActionFunctionArgs` interfaces.
108
+
109
+
You can do this with the following code in your `vite.config.ts`:
110
+
111
+
```ts filename="vite.config.ts"
112
+
// Your AppLoadContext used in v2
113
+
interfaceAppLoadContext {
114
+
whatever:string;
115
+
}
116
+
117
+
// Tell v7 the type of the context and that it is non-optional
118
+
declaremodule"react-router" {
119
+
interfaceLoaderFunctionArgs {
120
+
context:AppLoadContext;
121
+
}
122
+
}
123
+
```
124
+
125
+
This should allow you to upgrade and ship your application on React Router v7, and then you can incrementally migrate routes to the new typegen approach.
126
+
99
127
## Known Prerelease Issues
100
128
101
129
### Typesafety
@@ -127,3 +155,6 @@ let data = useLoaderData<typeof loader>();
0 commit comments