@react-router/dev 7.6.0 → 7.6.1-pre.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,117 @@
1
1
  # `@react-router/dev`
2
2
 
3
+ ## 7.6.1-pre.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Prevent typegen with route files are outside the app directory ([#12996](https://github.com/remix-run/react-router/pull/12996))
8
+ - Fix typegen when same route is used at multiple paths ([#13574](https://github.com/remix-run/react-router/pull/13574))
9
+
10
+ For example, `routes/route.tsx` is used at 4 different paths here:
11
+
12
+ ```ts
13
+ import { type RouteConfig, route } from "@react-router/dev/routes";
14
+ export default [
15
+ route("base/:base", "routes/base.tsx", [
16
+ route("home/:home", "routes/route.tsx", { id: "home" }),
17
+ route("changelog/:changelog", "routes/route.tsx", { id: "changelog" }),
18
+ route("splat/*", "routes/route.tsx", { id: "splat" }),
19
+ ]),
20
+ route("other/:other", "routes/route.tsx", { id: "other" }),
21
+ ] satisfies RouteConfig;
22
+ ```
23
+
24
+ Previously, typegen would arbitrarily pick one of these paths to be the "winner" and generate types for the route module based on that path.
25
+ Now, typegen creates unions as necessary for alternate paths for the same route file.
26
+
27
+ - Add additional logging to `build` command output when cleaning assets from server build ([#13547](https://github.com/remix-run/react-router/pull/13547))
28
+ - Better types for `params` ([#13543](https://github.com/remix-run/react-router/pull/13543))
29
+
30
+ For example:
31
+
32
+ ```ts
33
+ // routes.ts
34
+ import { type RouteConfig, route } from "@react-router/dev/routes";
35
+
36
+ export default [
37
+ route("parent/:p", "routes/parent.tsx", [
38
+ route("route/:r", "routes/route.tsx", [
39
+ route("child1/:c1a/:c1b", "routes/child1.tsx"),
40
+ route("child2/:c2a/:c2b", "routes/child2.tsx"),
41
+ ]),
42
+ ]),
43
+ ] satisfies RouteConfig;
44
+ ```
45
+
46
+ Previously, `params` for `routes/route` were calculated as `{ p: string, r: string }`.
47
+ This incorrectly ignores params that could come from child routes.
48
+ If visiting `/parent/1/route/2/child1/3/4`, the actual params passed to `routes/route` will have a type of `{ p: string, r: string, c1a: string, c1b: string }`.
49
+
50
+ Now, `params` are aware of child routes and autocompletion will include child params as optionals:
51
+
52
+ ```ts
53
+ params.|
54
+ // ^ cursor is here and you ask for autocompletion
55
+ // p: string
56
+ // r: string
57
+ // c1a?: string
58
+ // c1b?: string
59
+ // c2a?: string
60
+ // c2b?: string
61
+ ```
62
+
63
+ You can also narrow the types for `params` as it is implemented as a normalized union of params for each page that includes `routes/route`:
64
+
65
+ ```ts
66
+ if (typeof params.c1a === 'string') {
67
+ params.|
68
+ // ^ cursor is here and you ask for autocompletion
69
+ // p: string
70
+ // r: string
71
+ // c1a: string
72
+ // c1b: string
73
+ }
74
+ ```
75
+
76
+ ***
77
+
78
+ UNSTABLE: renamed internal `react-router/route-module` export to `react-router/internal`
79
+ UNSTABLE: removed `Info` export from generated `+types/*` files
80
+
81
+ - [UNSTABLE] Normalize dirent entry path across node versions when generating SRI manifest ([#13591](https://github.com/remix-run/react-router/pull/13591))
82
+ - Don't clean assets from server build when `build.ssrEmitAssets` has been enabled in Vite config ([#13547](https://github.com/remix-run/react-router/pull/13547))
83
+ - Fix `href` for optional segments ([#13595](https://github.com/remix-run/react-router/pull/13595))
84
+
85
+ Type generation now expands paths with optionals into their corresponding non-optional paths.
86
+ For example, the path `/user/:id?` gets expanded into `/user` and `/user/:id` to more closely model visitable URLs.
87
+ `href` then uses these expanded (non-optional) paths to construct type-safe paths for your app:
88
+
89
+ ```ts
90
+ // original: /user/:id?
91
+ // expanded: /user & /user/:id
92
+ href("/user"); // ✅
93
+ href("/user/:id", { id: 1 }); // ✅
94
+ ```
95
+
96
+ This becomes even more important for static optional paths where there wasn't a good way to indicate whether the optional should be included in the resulting path:
97
+
98
+ ```ts
99
+ // original: /products/:id/detail?
100
+
101
+ // before
102
+ href("/products/:id/detail?"); // ❌ How can we tell `href` to include or omit `detail?` segment with a complex API?
103
+
104
+ // now
105
+ // expanded: /products/:id & /products/:id/detail
106
+ href("/product/:id"); // ✅
107
+ href("/product/:id/detail"); // ✅
108
+ ```
109
+
110
+ - Updated dependencies:
111
+ - `react-router@7.6.1-pre.0`
112
+ - `@react-router/node@7.6.1-pre.0`
113
+ - `@react-router/serve@7.6.1-pre.0`
114
+
3
115
  ## 7.6.0
4
116
 
5
117
  ### Minor Changes