UNPKG

18.9 kBMarkdownView Raw
1# `react-router`
2
3## 6.16.0
4
5### Minor Changes
6
7- In order to move towards stricter TypeScript support in the future, we're aiming to replace current usages of `any` with `unknown` on exposed typings for user-provided data. To do this in Remix v2 without introducing breaking changes in React Router v6, we have added generics to a number of shared types. These continue to default to `any` in React Router and are overridden with `unknown` in Remix. In React Router v7 we plan to move these to `unknown` as a breaking change. ([#10843](https://github.com/remix-run/react-router/pull/10843))
8 - `Location` now accepts a generic for the `location.state` value
9 - `ActionFunctionArgs`/`ActionFunction`/`LoaderFunctionArgs`/`LoaderFunction` now accept a generic for the `context` parameter (only used in SSR usages via `createStaticHandler`)
10 - The return type of `useMatches` (now exported as `UIMatch`) accepts generics for `match.data` and `match.handle` - both of which were already set to `unknown`
11- Move the `@private` class export `ErrorResponse` to an `UNSAFE_ErrorResponseImpl` export since it is an implementation detail and there should be no construction of `ErrorResponse` instances in userland. This frees us up to export a `type ErrorResponse` which correlates to an instance of the class via `InstanceType`. Userland code should only ever be using `ErrorResponse` as a type and should be type-narrowing via `isRouteErrorResponse`. ([#10811](https://github.com/remix-run/react-router/pull/10811))
12- Export `ShouldRevalidateFunctionArgs` interface ([#10797](https://github.com/remix-run/react-router/pull/10797))
13- Removed private/internal APIs only required for the Remix v1 backwards compatibility layer and no longer needed in Remix v2 (`_isFetchActionRedirect`, `_hasFetcherDoneAnything`) ([#10715](https://github.com/remix-run/react-router/pull/10715))
14
15### Patch Changes
16
17- Updated dependencies:
18 - `@remix-run/router@1.9.0`
19
20## 6.15.0
21
22### Minor Changes
23
24- Add's a new `redirectDocument()` function which allows users to specify that a redirect from a `loader`/`action` should trigger a document reload (via `window.location`) instead of attempting to navigate to the redirected location via React Router ([#10705](https://github.com/remix-run/react-router/pull/10705))
25
26### Patch Changes
27
28- Ensure `useRevalidator` is referentially stable across re-renders if revalidations are not actively occurring ([#10707](https://github.com/remix-run/react-router/pull/10707))
29- Updated dependencies:
30 - `@remix-run/router@1.8.0`
31
32## 6.14.2
33
34### Patch Changes
35
36- Updated dependencies:
37 - `@remix-run/router@1.7.2`
38
39## 6.14.1
40
41### Patch Changes
42
43- Fix loop in `unstable_useBlocker` when used with an unstable blocker function ([#10652](https://github.com/remix-run/react-router/pull/10652))
44- Fix issues with reused blockers on subsequent navigations ([#10656](https://github.com/remix-run/react-router/pull/10656))
45- Updated dependencies:
46 - `@remix-run/router@1.7.1`
47
48## 6.14.0
49
50### Patch Changes
51
52- Strip `basename` from locations provided to `unstable_useBlocker` functions to match `useLocation` ([#10573](https://github.com/remix-run/react-router/pull/10573))
53- Fix `generatePath` when passed a numeric `0` value parameter ([#10612](https://github.com/remix-run/react-router/pull/10612))
54- Fix `unstable_useBlocker` key issues in `StrictMode` ([#10573](https://github.com/remix-run/react-router/pull/10573))
55- Fix `tsc --skipLibCheck:false` issues on React 17 ([#10622](https://github.com/remix-run/react-router/pull/10622))
56- Upgrade `typescript` to 5.1 ([#10581](https://github.com/remix-run/react-router/pull/10581))
57- Updated dependencies:
58 - `@remix-run/router@1.7.0`
59
60## 6.13.0
61
62### Minor Changes
63
64- Move [`React.startTransition`](https://react.dev/reference/react/startTransition) usage behind a [future flag](https://reactrouter.com/en/main/guides/api-development-strategy) to avoid issues with existing incompatible `Suspense` usages. We recommend folks adopting this flag to be better compatible with React concurrent mode, but if you run into issues you can continue without the use of `startTransition` until v7. Issues usually boils down to creating net-new promises during the render cycle, so if you run into issues you should either lift your promise creation out of the render cycle or put it behind a `useMemo`. ([#10596](https://github.com/remix-run/react-router/pull/10596))
65
66 Existing behavior will no longer include `React.startTransition`:
67
68 ```jsx
69 <BrowserRouter>
70 <Routes>{/*...*/}</Routes>
71 </BrowserRouter>
72
73 <RouterProvider router={router} />
74 ```
75
76 If you wish to enable `React.startTransition`, pass the future flag to your component:
77
78 ```jsx
79 <BrowserRouter future={{ v7_startTransition: true }}>
80 <Routes>{/*...*/}</Routes>
81 </BrowserRouter>
82
83 <RouterProvider router={router} future={{ v7_startTransition: true }}/>
84 ```
85
86### Patch Changes
87
88- Work around webpack/terser `React.startTransition` minification bug in production mode ([#10588](https://github.com/remix-run/react-router/pull/10588))
89
90## 6.12.1
91
92> **Warning**
93> Please use version `6.13.0` or later instead of `6.12.1`. This version suffers from a `webpack`/`terser` minification issue resulting in invalid minified code in your resulting production bundles which can cause issues in your application. See [#10579](https://github.com/remix-run/react-router/issues/10579) for more details.
94
95### Patch Changes
96
97- Adjust feature detection of `React.startTransition` to fix webpack + react 17 compilation error ([#10569](https://github.com/remix-run/react-router/pull/10569))
98
99## 6.12.0
100
101### Minor Changes
102
103- Wrap internal router state updates with `React.startTransition` if it exists ([#10438](https://github.com/remix-run/react-router/pull/10438))
104
105### Patch Changes
106
107- Updated dependencies:
108 - `@remix-run/router@1.6.3`
109
110## 6.11.2
111
112### Patch Changes
113
114- Fix `basename` duplication in descendant `<Routes>` inside a `<RouterProvider>` ([#10492](https://github.com/remix-run/react-router/pull/10492))
115- Updated dependencies:
116 - `@remix-run/router@1.6.2`
117
118## 6.11.1
119
120### Patch Changes
121
122- Fix usage of `Component` API within descendant `<Routes>` ([#10434](https://github.com/remix-run/react-router/pull/10434))
123- Fix bug when calling `useNavigate` from `<Routes>` inside a `<RouterProvider>` ([#10432](https://github.com/remix-run/react-router/pull/10432))
124- Fix usage of `<Navigate>` in strict mode when using a data router ([#10435](https://github.com/remix-run/react-router/pull/10435))
125- Updated dependencies:
126 - `@remix-run/router@1.6.1`
127
128## 6.11.0
129
130### Patch Changes
131
132- Log loader/action errors to the console in dev for easier stack trace evaluation ([#10286](https://github.com/remix-run/react-router/pull/10286))
133- Fix bug preventing rendering of descendant `<Routes>` when `RouterProvider` errors existed ([#10374](https://github.com/remix-run/react-router/pull/10374))
134- Fix inadvertent re-renders when using `Component` instead of `element` on a route definition ([#10287](https://github.com/remix-run/react-router/pull/10287))
135- Fix detection of `useNavigate` in the render cycle by setting the `activeRef` in a layout effect, allowing the `navigate` function to be passed to child components and called in a `useEffect` there. ([#10394](https://github.com/remix-run/react-router/pull/10394))
136- Switched from `useSyncExternalStore` to `useState` for internal `@remix-run/router` router state syncing in `<RouterProvider>`. We found some [subtle bugs](https://codesandbox.io/s/use-sync-external-store-loop-9g7b81) where router state updates got propagated _before_ other normal `useState` updates, which could lead to footguns in `useEffect` calls. ([#10377](https://github.com/remix-run/react-router/pull/10377), [#10409](https://github.com/remix-run/react-router/pull/10409))
137- Allow `useRevalidator()` to resolve a loader-driven error boundary scenario ([#10369](https://github.com/remix-run/react-router/pull/10369))
138- Avoid unnecessary unsubscribe/resubscribes on router state changes ([#10409](https://github.com/remix-run/react-router/pull/10409))
139- When using a `RouterProvider`, `useNavigate`/`useSubmit`/`fetcher.submit` are now stable across location changes, since we can handle relative routing via the `@remix-run/router` instance and get rid of our dependence on `useLocation()`. When using `BrowserRouter`, these hooks remain unstable across location changes because they still rely on `useLocation()`. ([#10336](https://github.com/remix-run/react-router/pull/10336))
140- Updated dependencies:
141 - `@remix-run/router@1.6.0`
142
143## 6.10.0
144
145### Minor Changes
146
147- Added support for [**Future Flags**](https://reactrouter.com/en/main/guides/api-development-strategy) in React Router. The first flag being introduced is `future.v7_normalizeFormMethod` which will normalize the exposed `useNavigation()/useFetcher()` `formMethod` fields as uppercase HTTP methods to align with the `fetch()` behavior. ([#10207](https://github.com/remix-run/react-router/pull/10207))
148
149 - When `future.v7_normalizeFormMethod === false` (default v6 behavior),
150 - `useNavigation().formMethod` is lowercase
151 - `useFetcher().formMethod` is lowercase
152 - When `future.v7_normalizeFormMethod === true`:
153 - `useNavigation().formMethod` is uppercase
154 - `useFetcher().formMethod` is uppercase
155
156### Patch Changes
157
158- Fix route ID generation when using Fragments in `createRoutesFromElements` ([#10193](https://github.com/remix-run/react-router/pull/10193))
159- Updated dependencies:
160 - `@remix-run/router@1.5.0`
161
162## 6.9.0
163
164### Minor Changes
165
166- React Router now supports an alternative way to define your route `element` and `errorElement` fields as React Components instead of React Elements. You can instead pass a React Component to the new `Component` and `ErrorBoundary` fields if you choose. There is no functional difference between the two, so use whichever approach you prefer 😀. You shouldn't be defining both, but if you do `Component`/`ErrorBoundary` will "win". ([#10045](https://github.com/remix-run/react-router/pull/10045))
167
168 **Example JSON Syntax**
169
170 ```jsx
171 // Both of these work the same:
172 const elementRoutes = [{
173 path: '/',
174 element: <Home />,
175 errorElement: <HomeError />,
176 }]
177
178 const componentRoutes = [{
179 path: '/',
180 Component: Home,
181 ErrorBoundary: HomeError,
182 }]
183
184 function Home() { ... }
185 function HomeError() { ... }
186 ```
187
188 **Example JSX Syntax**
189
190 ```jsx
191 // Both of these work the same:
192 const elementRoutes = createRoutesFromElements(
193 <Route path='/' element={<Home />} errorElement={<HomeError /> } />
194 );
195
196 const componentRoutes = createRoutesFromElements(
197 <Route path='/' Component={Home} ErrorBoundary={HomeError} />
198 );
199
200 function Home() { ... }
201 function HomeError() { ... }
202 ```
203
204- **Introducing Lazy Route Modules!** ([#10045](https://github.com/remix-run/react-router/pull/10045))
205
206 In order to keep your application bundles small and support code-splitting of your routes, we've introduced a new `lazy()` route property. This is an async function that resolves the non-route-matching portions of your route definition (`loader`, `action`, `element`/`Component`, `errorElement`/`ErrorBoundary`, `shouldRevalidate`, `handle`).
207
208 Lazy routes are resolved on initial load and during the `loading` or `submitting` phase of a navigation or fetcher call. You cannot lazily define route-matching properties (`path`, `index`, `children`) since we only execute your lazy route functions after we've matched known routes.
209
210 Your `lazy` functions will typically return the result of a dynamic import.
211
212 ```jsx
213 // In this example, we assume most folks land on the homepage so we include that
214 // in our critical-path bundle, but then we lazily load modules for /a and /b so
215 // they don't load until the user navigates to those routes
216 let routes = createRoutesFromElements(
217 <Route path="/" element={<Layout />}>
218 <Route index element={<Home />} />
219 <Route path="a" lazy={() => import("./a")} />
220 <Route path="b" lazy={() => import("./b")} />
221 </Route>
222 );
223 ```
224
225 Then in your lazy route modules, export the properties you want defined for the route:
226
227 ```jsx
228 export async function loader({ request }) {
229 let data = await fetchData(request);
230 return json(data);
231 }
232
233 // Export a `Component` directly instead of needing to create a React Element from it
234 export function Component() {
235 let data = useLoaderData();
236
237 return (
238 <>
239 <h1>You made it!</h1>
240 <p>{data}</p>
241 </>
242 );
243 }
244
245 // Export an `ErrorBoundary` directly instead of needing to create a React Element from it
246 export function ErrorBoundary() {
247 let error = useRouteError();
248 return isRouteErrorResponse(error) ? (
249 <h1>
250 {error.status} {error.statusText}
251 </h1>
252 ) : (
253 <h1>{error.message || error}</h1>
254 );
255 }
256 ```
257
258 An example of this in action can be found in the [`examples/lazy-loading-router-provider`](https://github.com/remix-run/react-router/tree/main/examples/lazy-loading-router-provider) directory of the repository.
259
260 🙌 Huge thanks to @rossipedia for the [Initial Proposal](https://github.com/remix-run/react-router/discussions/9826) and [POC Implementation](https://github.com/remix-run/react-router/pull/9830).
261
262- Updated dependencies:
263 - `@remix-run/router@1.4.0`
264
265### Patch Changes
266
267- Fix `generatePath` incorrectly applying parameters in some cases ([#10078](https://github.com/remix-run/react-router/pull/10078))
268- Improve memoization for context providers to avoid unnecessary re-renders ([#9983](https://github.com/remix-run/react-router/pull/9983))
269
270## 6.8.2
271
272### Patch Changes
273
274- Updated dependencies:
275 - `@remix-run/router@1.3.3`
276
277## 6.8.1
278
279### Patch Changes
280
281- Remove inaccurate console warning for POP navigations and update active blocker logic ([#10030](https://github.com/remix-run/react-router/pull/10030))
282- Updated dependencies:
283 - `@remix-run/router@1.3.2`
284
285## 6.8.0
286
287### Patch Changes
288
289- Updated dependencies:
290 - `@remix-run/router@1.3.1`
291
292## 6.7.0
293
294### Minor Changes
295
296- Add `unstable_useBlocker` hook for blocking navigations within the app's location origin ([#9709](https://github.com/remix-run/react-router/pull/9709))
297
298### Patch Changes
299
300- Fix `generatePath` when optional params are present ([#9764](https://github.com/remix-run/react-router/pull/9764))
301- Update `<Await>` to accept `ReactNode` as children function return result ([#9896](https://github.com/remix-run/react-router/pull/9896))
302- Updated dependencies:
303 - `@remix-run/router@1.3.0`
304
305## 6.6.2
306
307### Patch Changes
308
309- Ensure `useId` consistency during SSR ([#9805](https://github.com/remix-run/react-router/pull/9805))
310
311## 6.6.1
312
313### Patch Changes
314
315- Updated dependencies:
316 - `@remix-run/router@1.2.1`
317
318## 6.6.0
319
320### Patch Changes
321
322- Prevent `useLoaderData` usage in `errorElement` ([#9735](https://github.com/remix-run/react-router/pull/9735))
323- Updated dependencies:
324 - `@remix-run/router@1.2.0`
325
326## 6.5.0
327
328This release introduces support for [Optional Route Segments](https://github.com/remix-run/react-router/issues/9546). Now, adding a `?` to the end of any path segment will make that entire segment optional. This works for both static segments and dynamic parameters.
329
330**Optional Params Examples**
331
332- `<Route path=":lang?/about>` will match:
333 - `/:lang/about`
334 - `/about`
335- `<Route path="/multistep/:widget1?/widget2?/widget3?">` will match:
336 - `/multistep`
337 - `/multistep/:widget1`
338 - `/multistep/:widget1/:widget2`
339 - `/multistep/:widget1/:widget2/:widget3`
340
341**Optional Static Segment Example**
342
343- `<Route path="/home?">` will match:
344 - `/`
345 - `/home`
346- `<Route path="/fr?/about">` will match:
347 - `/about`
348 - `/fr/about`
349
350### Minor Changes
351
352- Allows optional routes and optional static segments ([#9650](https://github.com/remix-run/react-router/pull/9650))
353
354### Patch Changes
355
356- Stop incorrectly matching on partial named parameters, i.e. `<Route path="prefix-:param">`, to align with how splat parameters work. If you were previously relying on this behavior then it's recommended to extract the static portion of the path at the `useParams` call site: ([#9506](https://github.com/remix-run/react-router/pull/9506))
357
358```jsx
359// Old behavior at URL /prefix-123
360<Route path="prefix-:id" element={<Comp /> }>
361
362function Comp() {
363 let params = useParams(); // { id: '123' }
364 let id = params.id; // "123"
365 ...
366}
367
368// New behavior at URL /prefix-123
369<Route path=":id" element={<Comp /> }>
370
371function Comp() {
372 let params = useParams(); // { id: 'prefix-123' }
373 let id = params.id.replace(/^prefix-/, ''); // "123"
374 ...
375}
376```
377
378- Updated dependencies:
379 - `@remix-run/router@1.1.0`
380
381## 6.4.5
382
383### Patch Changes
384
385- Updated dependencies:
386 - `@remix-run/router@1.0.5`
387
388## 6.4.4
389
390### Patch Changes
391
392- Updated dependencies:
393 - `@remix-run/router@1.0.4`
394
395## 6.4.3
396
397### Patch Changes
398
399- `useRoutes` should be able to return `null` when passing `locationArg` ([#9485](https://github.com/remix-run/react-router/pull/9485))
400- fix `initialEntries` type in `createMemoryRouter` ([#9498](https://github.com/remix-run/react-router/pull/9498))
401- Updated dependencies:
402 - `@remix-run/router@1.0.3`
403
404## 6.4.2
405
406### Patch Changes
407
408- Fix `IndexRouteObject` and `NonIndexRouteObject` types to make `hasErrorElement` optional ([#9394](https://github.com/remix-run/react-router/pull/9394))
409- Enhance console error messages for invalid usage of data router hooks ([#9311](https://github.com/remix-run/react-router/pull/9311))
410- If an index route has children, it will result in a runtime error. We have strengthened our `RouteObject`/`RouteProps` types to surface the error in TypeScript. ([#9366](https://github.com/remix-run/react-router/pull/9366))
411- Updated dependencies:
412 - `@remix-run/router@1.0.2`
413
414## 6.4.1
415
416### Patch Changes
417
418- Preserve state from `initialEntries` ([#9288](https://github.com/remix-run/react-router/pull/9288))
419- Updated dependencies:
420 - `@remix-run/router@1.0.1`
421
422## 6.4.0
423
424Whoa this is a big one! `6.4.0` brings all the data loading and mutation APIs over from Remix. Here's a quick high level overview, but it's recommended you go check out the [docs][rr-docs], especially the [feature overview][rr-feature-overview] and the [tutorial][rr-tutorial].
425
426**New APIs**
427
428- Create your router with `createMemoryRouter`
429- Render your router with `<RouterProvider>`
430- Load data with a Route `loader` and mutate with a Route `action`
431- Handle errors with Route `errorElement`
432- Defer non-critical data with `defer` and `Await`
433
434**Bug Fixes**
435
436- Path resolution is now trailing slash agnostic (#8861)
437- `useLocation` returns the scoped location inside a `<Routes location>` component (#9094)
438
439**Updated Dependencies**
440
441- `@remix-run/router@1.0.0`
442
443[rr-docs]: https://reactrouter.com
444[rr-feature-overview]: https://reactrouter.com/start/overview
445[rr-tutorial]: https://reactrouter.com/start/tutorial