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
@@ -334,29 +329,26 @@ For Remix consumers migrating to React Router, the `vitePlugin` and `cloudflareD
334
329
+import { cloudflareDevProxy } from "@react-router/dev/vite/cloudflare";
335
330
```
336
331
337
-
**Removed Vite Plugin `manifest` option**
332
+
**Removed `manifest` option**
338
333
339
334
For Remix consumers migrating to React Router, the Vite plugin's `manifest` option has been removed. The `manifest` option been superseded by the more powerful `buildEnd` hook since it's passed the `buildManifest` argument. You can still write the build manifest to disk if needed, but you'll most likely find it more convenient to write any logic depending on the build manifest within the `buildEnd` hook itself. ([#11573](https://github.com/remix-run/react-router/pull/11573))
340
335
341
336
If you were using the `manifest` option, you can replace it with a `buildEnd` hook that writes the manifest to disk like this:
@@ -470,131 +462,9 @@ Also note that, if you were using Remix's `routes` option to define config-based
470
462
471
463
#### Typesafety improvements
472
464
473
-
React Router now generates types for each of your route modules and passes typed props to route module component exports ([#11961](https://github.com/remix-run/react-router/pull/11961), [#12019](https://github.com/remix-run/react-router/pull/12019)). You can access those types by importing them from `./+types.<route filename without extension>`.
This initial implementation targets type inference for:
487
-
488
-
-`Params` : Path parameters from your routing config in `routes.ts` including file-based routing
489
-
-`LoaderData` : Loader data from `loader` and/or `clientLoader` within your route module
490
-
-`ActionData` : Action data from `action` and/or `clientAction` within your route module
491
-
492
-
These types are then used to create types for route export args and props:
493
-
494
-
-`LoaderArgs`
495
-
-`ClientLoaderArgs`
496
-
-`ActionArgs`
497
-
-`ClientActionArgs`
498
-
-`HydrateFallbackProps`
499
-
-`ComponentProps` (for the `default` export)
500
-
-`ErrorBoundaryProps`
501
-
502
-
In the future, we plan to add types for the rest of the route module exports: `meta`, `links`, `headers`, `shouldRevalidate`, etc.
503
-
504
-
We also plan to generate types for typesafe `Link`s:
505
-
506
-
```tsx
507
-
<Linkto="/products/:id"params={{ id: 1 }} />
508
-
// ^^^^^^^^^^^^^ ^^^^^^^^^
509
-
// typesafe `to` and `params` based on the available routes in your app
510
-
```
511
-
512
-
##### Setup
513
-
514
-
React Router will generate types into a `.react-router/` directory at the root of your app. This directory is fully managed by React Router and is derived based on your route config (`routes.ts`).
515
-
516
-
👉 **Add `.react-router/` to `.gitignore`**
517
-
518
-
```txt
519
-
.react-router
520
-
```
521
-
522
-
You should also ensure that generated types for routes are always present before running typechecking, especially for running typechecking in CI.
523
-
524
-
👉 **Add `react-router typegen` to your `typecheck` command in `package.json`**
525
-
526
-
```json
527
-
{
528
-
"scripts": {
529
-
"typecheck": "react-router typegen && tsc"
530
-
}
531
-
}
532
-
```
533
-
534
-
To get TypeScript to use those generated types, you'll need to add them to `include` in `tsconfig.json`. And to be able to import them as if they files next to your route modules, you'll also need to configure `rootDirs`.
535
-
536
-
👉 **Configure `tsconfig.json` for generated types**
465
+
React Router now generates types for each of your route modules and passes typed props to route module component exports ([#11961](https://github.com/remix-run/react-router/pull/11961), [#12019](https://github.com/remix-run/react-router/pull/12019)). You can access those types by importing them from `./+types/<route filename without extension>`.
537
466
538
-
```json
539
-
{
540
-
"include": [".react-router/types/**/*"],
541
-
"compilerOptions": {
542
-
"rootDirs": [".", "./.react-router/types"]
543
-
}
544
-
}
545
-
```
546
-
547
-
##### `typegen` command
548
-
549
-
You can manually generate types with the new `typegen` command:
550
-
551
-
```sh
552
-
react-router typegen
553
-
```
554
-
555
-
However, manual type generation is tedious and types can get out of sync quickly if you ever forget to run `typegen`. Instead, we recommend that you setup our new TypeScript plugin which will automatically generate fresh types whenever routes change. That way, you'll always have up-to-date types.
556
-
557
-
##### TypeScript plugin
558
-
559
-
To get automatic type generation, you can use our new TypeScript plugin.
560
-
561
-
👉 **Add the TypeScript plugin to `tsconfig.json`**
562
-
563
-
```json
564
-
{
565
-
"compilerOptions": {
566
-
"plugins": [{ "name": "@react-router/dev" }]
567
-
}
568
-
}
569
-
```
570
-
571
-
We plan to add some other goodies to our TypeScript plugin soon, including:
572
-
573
-
- Automatic `jsdoc` for route exports that include links to official docs
574
-
- Autocomplete for route exports
575
-
- Warnings for non-HMR compliant exports
576
-
577
-
###### VSCode
578
-
579
-
TypeScript looks for plugins registered in `tsconfig.json` in the local `node_modules/`,
580
-
but VSCode ships with its own copy of TypeScript that is installed outside of your project.
581
-
For TypeScript plugins to work, you'll need to tell VSCode to use the local workspace version of TypeScript.
582
-
583
-
👉 **Ensure that VSCode is using the workspace version of TypeScript**
584
-
585
-
This should already be set up for you by a `.vscode/settings.json`:
586
-
587
-
```json
588
-
{
589
-
"typescript.tsdk": "node_modules/typescript/lib"
590
-
}
591
-
```
592
-
593
-
Alternatively, you can open up any TypeScript file and use <kbd>CMD</kbd>+<kbd>SHIFT</kbd>+<kbd>P</kbd> to find `Select TypeScript Version` and then select `Use Workspace Version`. You may need to quit VSCode and reopen it for this setting to take effect.
594
-
595
-
###### Troubleshooting
596
-
597
-
In VSCode, open up any TypeScript file in your project and then use <kbd>CMD</kbd>+<kbd>SHIFT</kbd>+<kbd>P</kbd> to select `Open TS Server log`. There should be a log for `[react-router] setup` that indicates that the plugin was resolved correctly. Then look for any errors in the log.
467
+
See [_How To > Route Module Type Safety_](https://reactrouter.com/dev/how-to/route-module-type-safety) and [_Explanations > Type Safety_](https://reactrouter.com/dev/explanation/type-safety) for more details.
598
468
599
469
#### Prerendering
600
470
@@ -791,9 +661,7 @@ async function fakeGetSlugsFromCms() {
0 commit comments