Skip to content

Commit 779536c

Browse files
committed
Merge branch 'release-next'
2 parents 7ce38dc + edd9ad4 commit 779536c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+3455
-123
lines changed

contributors.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
- avipatel97
2626
- awreese
2727
- aymanemadidi
28+
- ayushmanchhabra
2829
- babafemij-k
2930
- bavardage
3031
- bbrowning918
@@ -52,6 +53,7 @@
5253
- danielberndt
5354
- daniilguit
5455
- dauletbaev
56+
- david-bezero
5557
- david-crespo
5658
- decadentsavant
5759
- DigitalNaut
@@ -236,4 +238,6 @@
236238
- xcsnowcity
237239
- yionr
238240
- yuleicul
241+
- yracnet
239242
- zheng-chuang
243+
- sgrishchenko

docs/components/form.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,32 @@ new: true
55

66
# `<Form>`
77

8+
<details>
9+
<summary>Type declaration</summary>
10+
11+
```tsx
12+
declare function Form(props: FormProps): React.ReactElement;
13+
14+
interface FormProps
15+
extends React.FormHTMLAttributes<HTMLFormElement> {
16+
method?: "get" | "post" | "put" | "patch" | "delete";
17+
encType?:
18+
| "application/x-www-form-urlencoded"
19+
| "multipart/form-data"
20+
| "text/plain";
21+
action?: string;
22+
onSubmit?: React.FormEventHandler<HTMLFormElement>;
23+
preventScrollReset?: boolean;
24+
relative?: "route" | "path";
25+
reloadDocument?: boolean;
26+
replace?: boolean;
27+
state?: any;
28+
unstable_viewTransition?: boolean;
29+
}
30+
```
31+
32+
</details>
33+
834
The Form component is a wrapper around a plain HTML [form][htmlform] that emulates the browser for client side routing and data mutations. It is _not_ a form validation/state management library like you might be used to in the React ecosystem (for that, we recommend the browser's built in [HTML Form Validation][formvalidation] and data validation on your backend server).
935

1036
<docs-warning>This feature only works if using a data router, see [Picking a Router][pickingarouter]</docs-warning>
@@ -243,6 +269,12 @@ If you are using [`<ScrollRestoration>`][scrollrestoration], this lets you preve
243269

244270
See also: [`<Link preventScrollReset>`][link-preventscrollreset]
245271

272+
## `unstable_viewTransition`
273+
274+
The `unstable_viewTransition` prop enables a [View Transition][view-transitions] for this navigation by wrapping the final state update in `document.startViewTransition()`. If you need to apply specific styles for this view transition, you will also need to leverage the [`unstable_useViewTransitionState()`][use-view-transition-state].
275+
276+
<docs-warning>Please note that this API is marked unstable and may be subject to breaking changes without a major release</docs-warning>
277+
246278
# Examples
247279

248280
TODO: More examples
@@ -349,3 +381,5 @@ You can access those values from the `request.url`
349381
[scrollrestoration]: ./scroll-restoration
350382
[link-preventscrollreset]: ./link#preventscrollreset
351383
[history-state]: https://developer.mozilla.org/en-US/docs/Web/API/History/state
384+
[use-view-transition-state]: ../hooks//use-view-transition-state
385+
[view-transitions]: https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API

docs/components/link.md

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ interface LinkProps
1717
React.AnchorHTMLAttributes<HTMLAnchorElement>,
1818
"href"
1919
> {
20-
replace?: boolean;
21-
state?: any;
2220
to: To;
23-
reloadDocument?: boolean;
2421
preventScrollReset?: boolean;
2522
relative?: "route" | "path";
23+
reloadDocument?: boolean;
24+
replace?: boolean;
25+
state?: any;
26+
unstable_viewTransition?: boolean;
2627
}
2728

2829
type To = string | Partial<Path>;
@@ -146,8 +147,57 @@ let { state } = useLocation();
146147

147148
The `reloadDocument` property can be used to skip client side routing and let the browser handle the transition normally (as if it were an `<a href>`).
148149

150+
## `unstable_viewTransition`
151+
152+
The `unstable_viewTransition` prop enables a [View Transition][view-transitions] for this navigation by wrapping the final state update in `document.startViewTransition()`:
153+
154+
```jsx
155+
<Link to={to} unstable_viewTransition>
156+
Click me
157+
</Link>
158+
```
159+
160+
If you need to apply specific styles for this view transition, you will also need to leverage the [`unstable_useViewTransitionState()`][use-view-transition-state] hook (or check out the `transitioning` class and `isTransitioning` render prop in [NavLink][navlink]):
161+
162+
```jsx
163+
function ImageLink(to) {
164+
const isTransitioning =
165+
unstable_useViewTransitionState(to);
166+
return (
167+
<Link to={to} unstable_viewTransition>
168+
<p
169+
style={{
170+
viewTransitionName: isTransitioning
171+
? "image-title"
172+
: "",
173+
}}
174+
>
175+
Image Number {idx}
176+
</p>
177+
<img
178+
src={src}
179+
alt={`Img ${idx}`}
180+
style={{
181+
viewTransitionName: isTransitioning
182+
? "image-expand"
183+
: "",
184+
}}
185+
/>
186+
</Link>
187+
);
188+
}
189+
```
190+
191+
<docs-warning>`unstable_viewTransition` only works when using a data router, see [Picking a Router][picking-a-router]</docs-warning>
192+
193+
<docs-warning>Please note that this API is marked unstable and may be subject to breaking changes without a major release</docs-warning>
194+
149195
[link-native]: ./link-native
150196
[scrollrestoration]: ./scroll-restoration
151197
[history-replace-state]: https://developer.mozilla.org/en-US/docs/Web/API/History/replaceState
152198
[history-push-state]: https://developer.mozilla.org/en-US/docs/Web/API/History/pushState
153199
[history-state]: https://developer.mozilla.org/en-US/docs/Web/API/History/state
200+
[use-view-transition-state]: ../hooks//use-view-transition-state
201+
[view-transitions]: https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API
202+
[picking-a-router]: ../routers/picking-a-router
203+
[navlink]: ./nav-link

docs/components/nav-link.md

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ title: NavLink
44

55
# `<NavLink>`
66

7-
A `<NavLink>` is a special kind of `<Link>` that knows whether or not it is "active" or "pending". This is useful when building a navigation menu, such as a breadcrumb or a set of tabs where you'd like to show which of them is currently selected. It also provides useful context for assistive technology like screen readers.
7+
A `<NavLink>` is a special kind of `<Link>` that knows whether or not it is "active", "pending", or "transitioning". This is useful in a few different scenarios:
8+
9+
- When building a navigation menu, such as a breadcrumb or a set of tabs where you'd like to show which of them is currently selected
10+
- It provides useful context for assistive technology like screen readers
11+
- It provides a "transitioning" value to give you finer-grained control over [View Transitions][view-transitions]
812

913
```tsx
1014
import { NavLink } from "react-router-dom";
@@ -42,8 +46,12 @@ The `className` prop works like a normal className, but you can also pass it a f
4246
```tsx
4347
<NavLink
4448
to="/messages"
45-
className={({ isActive, isPending }) =>
46-
isPending ? "pending" : isActive ? "active" : ""
49+
className={({ isActive, isPending, isTransitioning }) =>
50+
[
51+
isPending ? "pending" : "",
52+
isActive ? "active" : "",
53+
isTransitioning ? "transitioning" : "",
54+
].join(" ")
4755
}
4856
>
4957
Messages
@@ -57,10 +65,11 @@ The `style` prop works like a normal style prop, but you can also pass it a func
5765
```tsx
5866
<NavLink
5967
to="/messages"
60-
style={({ isActive, isPending }) => {
68+
style={({ isActive, isPending, isTransitioning }) => {
6169
return {
6270
fontWeight: isActive ? "bold" : "",
6371
color: isPending ? "red" : "black",
72+
viewTransitionName: isTransitioning ? "slide" : "",
6473
};
6574
}}
6675
>
@@ -74,7 +83,7 @@ You can pass a render prop as children to customize the content of the `<NavLink
7483

7584
```tsx
7685
<NavLink to="/tasks">
77-
{({ isActive, isPending }) => (
86+
{({ isActive, isPending, isTransitioning }) => (
7887
<span className={isActive ? "active" : ""}>Tasks</span>
7988
)}
8089
</NavLink>
@@ -112,4 +121,59 @@ When a `NavLink` is active it will automatically apply `<a aria-current="page">`
112121

113122
The `reloadDocument` property can be used to skip client side routing and let the browser handle the transition normally (as if it were an `<a href>`).
114123

124+
## `unstable_viewTransition`
125+
126+
The `unstable_viewTransition` prop enables a [View Transition][view-transitions] for this navigation by wrapping the final state update in `document.startViewTransition()`. By default, during the transition a `transitioning` class will be added to the `<a>` element that you can use to customize the view transition.
127+
128+
```css
129+
a.transitioning p {
130+
view-transition-name: "image-title";
131+
}
132+
133+
a.transitioning img {
134+
view-transition-name: "image-expand";
135+
}
136+
```
137+
138+
```jsx
139+
<NavLink to={to} unstable_viewTransition>
140+
<p>Image Number {idx}</p>
141+
<img src={src} alt={`Img ${idx}`} />
142+
</NavLink>
143+
```
144+
145+
You may also use the `className`/`style` props or the render props passed to `children` to further customize based on the `isTransitioning` value.
146+
147+
```jsx
148+
<NavLink to={to} unstable_viewTransition>
149+
{({ isTransitioning }) => (
150+
<>
151+
<p
152+
style={{
153+
viewTransitionName: isTransitioning
154+
? "image-title"
155+
: "",
156+
}}
157+
>
158+
Image Number {idx}
159+
</p>
160+
<img
161+
src={src}
162+
alt={`Img ${idx}`}
163+
style={{
164+
viewTransitionName: isTransitioning
165+
? "image-expand"
166+
: "",
167+
}}
168+
/>
169+
</>
170+
)}
171+
</NavLink>
172+
```
173+
174+
<docs-warning>
175+
Please note that this API is marked unstable and may be subject to breaking changes without a major release.
176+
</docs-warning>
177+
115178
[aria-current]: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-current
179+
[view-transitions]: https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API

docs/hooks/use-navigate.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,20 @@ function EditContact() {
8585
}
8686
```
8787

88+
## `options.unstable_viewTransition`
89+
90+
The `unstable_viewTransition` option enables a [View Transition][view-transitions] for this navigation by wrapping the final state update in `document.startViewTransition()`. If you need to apply specific styles for this view transition, you will also need to leverage the [`unstable_useViewTransitionState()`][use-view-transition-state].
91+
92+
<docs-warning>`unstable_viewTransition` only works when using a data router, see [Picking a Router][picking-a-router]</docs-warning>
93+
94+
<docs-warning>Please note that this API is marked unstable and may be subject to breaking changes without a major release</docs-warning>
95+
8896
[link]: ../components/link
8997
[redirect]: ../fetch/redirect
9098
[loaders]: ../route/loader
9199
[actions]: ../route/action
92100
[history-state]: https://developer.mozilla.org/en-US/docs/Web/API/History/state
93101
[scrollrestoration]: ../components/scroll-restoration
102+
[use-view-transition-state]: ../hooks//use-view-transition-state
103+
[view-transitions]: https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API
104+
[picking-a-router]: ../routers/picking-a-router

docs/hooks/use-submit.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ submit(null, {
150150
<Form action="/logout" method="post" />;
151151
```
152152

153-
Because submissions are navigations, the options may also contain the other navigation related props from [`<Form>`][form] such as `replace`, `state`, `preventScrollReset`, `relative`, etc.
153+
Because submissions are navigations, the options may also contain the other navigation related props from [`<Form>`][form] such as `replace`, `state`, `preventScrollReset`, `relative`, `unstable_viewTransition` etc.
154154

155155
[pickingarouter]: ../routers/picking-a-router
156156
[form]: ../components/form
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
title: unstable_useViewTransitionState
3+
---
4+
5+
# `unstable_useViewTransitionState`
6+
7+
<details>
8+
<summary>Type declaration</summary>
9+
10+
```tsx
11+
declare function unstable_useViewTransitionState(
12+
to: To,
13+
opts: { relative?: "route" : "path" } = {}
14+
): boolean;
15+
16+
type To = string | Partial<Path>;
17+
18+
interface Path {
19+
pathname: string;
20+
search: string;
21+
hash: string;
22+
}
23+
```
24+
25+
</details>
26+
27+
This hook returns `true` when there is an active [View Transition][view-transitions] to the specified location. This can be used to apply finer-grained styles to elements to further customize the view transition. This requires that view transitions have been enabled for the given navigation via the [unstable_viewTransition][link-view-transition] prop on the `Link` (or the `Form`, `navigate`, or `submit` call).
28+
29+
Consider clicking on an image in a list that you need to expand into the hero image on the destination page:
30+
31+
```jsx
32+
function NavImage({ src, alt, id }) {
33+
let to = `/images/${idx}`;
34+
let vt = unstable_useViewTransitionState(href);
35+
return (
36+
<Link to={to} unstable_viewTransition>
37+
<img
38+
src={src}
39+
alt={alt}
40+
style={{
41+
viewTransitionName: vt ? "image-expand" : "",
42+
}}
43+
/>
44+
</Link>
45+
);
46+
}
47+
```
48+
49+
[link-view-transition]: ../components/link#unstable_viewtransition
50+
[view-transitions]: https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API

docs/routers/picking-a-router.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ The following APIs are introduced in React Router 6.4 and will only work when us
109109
- [`useRouteError`][userouteerror]
110110
- [`useRouteLoaderData`][userouteloaderdata]
111111
- [`useSubmit`][usesubmit]
112+
- `startViewTransition` support on [Link][viewtransition-link] and [useNavigate][viewtransition-navigate]
112113

113114
[createbrowserrouter]: ./create-browser-router
114115
[createhashrouter]: ./create-hash-router
@@ -142,3 +143,5 @@ The following APIs are introduced in React Router 6.4 and will only work when us
142143
[userouteerror]: ../hooks/use-route-error
143144
[userouteloaderdata]: ../hooks/use-route-loader-data
144145
[usesubmit]: ../hooks/use-submit
146+
[viewtransition-link]: ../components/link#unstable_viewtransition
147+
[viewtransition-navigate]: ../hooks/use-navigate#optionsunstable_viewtransition

docs/routers/router-provider.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ declare function RouterProvider(
1616
interface RouterProviderProps {
1717
fallbackElement?: React.ReactNode;
1818
router: Router;
19-
future?: FutureConfig;
19+
future?: Partial<FutureConfig>;
2020
}
2121
```
2222

examples/view-transitions/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
.DS_Store
3+
dist
4+
dist-ssr
5+
*.local

0 commit comments

Comments
 (0)