Skip to content

Commit 73fcb9b

Browse files
authored
Stabilize viewTransiton and flushSync options (#11989)
1 parent 2dd13c6 commit 73fcb9b

18 files changed

+143
-130
lines changed

.changeset/stabilize-flush-sync.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"react-router-dom": minor
3+
"react-router": minor
4+
"@remix-run/router": minor
5+
---
6+
7+
Stabilize the `unstable_flushSync` option for navigations and fetchers
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"react-router-dom": minor
3+
"react-router": minor
4+
"@remix-run/router": minor
5+
---
6+
7+
Stabilize the `unstable_viewTransition` option for navigations and the corresponding `unstable_useViewTransitionState` hook

docs/components/form.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ interface FormProps
2727
reloadDocument?: boolean;
2828
replace?: boolean;
2929
state?: any;
30-
unstable_viewTransition?: boolean;
30+
viewTransition?: boolean;
3131
}
3232
```
3333

@@ -281,9 +281,9 @@ If you are using [`<ScrollRestoration>`][scrollrestoration], this lets you preve
281281

282282
See also: [`<Link preventScrollReset>`][link-preventscrollreset]
283283

284-
## `unstable_viewTransition`
284+
## `viewTransition`
285285

286-
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].
286+
The `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 [`useViewTransitionState()`][use-view-transition-state].
287287

288288
<docs-warning>Please note that this API is marked unstable and may be subject to breaking changes without a major release</docs-warning>
289289

docs/components/link.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ interface LinkProps
2323
reloadDocument?: boolean;
2424
replace?: boolean;
2525
state?: any;
26-
unstable_viewTransition?: boolean;
26+
viewTransition?: boolean;
2727
}
2828

2929
type To = string | Partial<Path>;
@@ -171,24 +171,24 @@ let { state } = useLocation();
171171

172172
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>`).
173173

174-
## `unstable_viewTransition`
174+
## `viewTransition`
175175

176-
The `unstable_viewTransition` prop enables a [View Transition][view-transitions] for this navigation by wrapping the final state update in `document.startViewTransition()`:
176+
The `viewTransition` prop enables a [View Transition][view-transitions] for this navigation by wrapping the final state update in `document.startViewTransition()`:
177177

178178
```jsx
179-
<Link to={to} unstable_viewTransition>
179+
<Link to={to} viewTransition>
180180
Click me
181181
</Link>
182182
```
183183

184-
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]):
184+
If you need to apply specific styles for this view transition, you will also need to leverage the [`useViewTransitionState()`][use-view-transition-state] hook (or check out the `transitioning` class and `isTransitioning` render prop in [NavLink][navlink]):
185185

186186
```jsx
187187
function ImageLink(to) {
188188
const isTransitioning =
189-
unstable_useViewTransitionState(to);
189+
useViewTransitionState(to);
190190
return (
191-
<Link to={to} unstable_viewTransition>
191+
<Link to={to} viewTransition>
192192
<p
193193
style={{
194194
viewTransitionName: isTransitioning
@@ -212,7 +212,7 @@ function ImageLink(to) {
212212
}
213213
```
214214

215-
<docs-warning>`unstable_viewTransition` only works when using a data router, see [Picking a Router][picking-a-router]</docs-warning>
215+
<docs-warning>`viewTransition` only works when using a data router, see [Picking a Router][picking-a-router]</docs-warning>
216216

217217
<docs-warning>Please note that this API is marked unstable and may be subject to breaking changes without a major release</docs-warning>
218218

docs/components/nav-link.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ When a `NavLink` is active it will automatically apply `<a aria-current="page">`
123123

124124
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>`).
125125

126-
## `unstable_viewTransition`
126+
## `viewTransition`
127127

128-
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.
128+
The `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.
129129

130130
```css
131131
a.transitioning p {
@@ -138,7 +138,7 @@ a.transitioning img {
138138
```
139139

140140
```jsx
141-
<NavLink to={to} unstable_viewTransition>
141+
<NavLink to={to} viewTransition>
142142
<p>Image Number {idx}</p>
143143
<img src={src} alt={`Img ${idx}`} />
144144
</NavLink>
@@ -147,7 +147,7 @@ a.transitioning img {
147147
You may also use the `className`/`style` props or the render props passed to `children` to further customize based on the `isTransitioning` value.
148148

149149
```jsx
150-
<NavLink to={to} unstable_viewTransition>
150+
<NavLink to={to} viewTransition>
151151
{({ isTransitioning }) => (
152152
<>
153153
<p

docs/hooks/use-fetcher.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ If you find yourself calling this function inside of click handlers, you can pro
133133

134134
<docs-info>Any `fetcher.load` calls that are active on the page will be re-executed as part of revalidation (either after a navigation submission, another fetcher submission, or a `useRevalidator()` call)</docs-info>
135135

136-
#### `options.unstable_flushSync`
136+
#### `options.flushSync`
137137

138-
The `unstable_flushSync` option tells React Router DOM to wrap the initial state update for this `fetcher.load` in a [`ReactDOM.flushSync`][flush-sync] call instead of the default [`React.startTransition`][start-transition]. This allows you to perform synchronous DOM actions immediately after the update is flushed to the DOM.
138+
The `flushSync` option tells React Router DOM to wrap the initial state update for this `fetcher.load` in a [`ReactDOM.flushSync`][flush-sync] call instead of the default [`React.startTransition`][start-transition]. This allows you to perform synchronous DOM actions immediately after the update is flushed to the DOM.
139139

140140
<docs-warning>Please note that this API is marked unstable and may be subject to breaking changes without a major release</docs-warning>
141141

docs/hooks/use-navigate.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ interface NavigateOptions {
2020
state?: any;
2121
preventScrollReset?: boolean;
2222
relative?: RelativeRoutingType;
23-
unstable_flushSync?: boolean;
24-
unstable_viewTransition?: boolean;
23+
flushSync?: boolean;
24+
viewTransition?: boolean;
2525
}
2626

2727
type RelativeRoutingType = "route" | "path";
@@ -114,19 +114,19 @@ new URL("..", window.origin + location.pathname + "/");
114114
// 'https://remix.run/docs/en/main/start/'
115115
```
116116

117-
## `options.unstable_flushSync`
117+
## `options.flushSync`
118118

119-
The `unstable_flushSync` option tells React Router DOM to wrap the initial state update for this navigation in a [`ReactDOM.flushSync`][flush-sync] call instead of the default [`React.startTransition`][start-transition]. This allows you to perform synchronous DOM actions immediately after the update is flushed to the DOM.
119+
The `flushSync` option tells React Router DOM to wrap the initial state update for this navigation in a [`ReactDOM.flushSync`][flush-sync] call instead of the default [`React.startTransition`][start-transition]. This allows you to perform synchronous DOM actions immediately after the update is flushed to the DOM.
120120

121-
<docs-warning>`unstable_flushSync` only works when using a data router, see [Picking a Router][picking-a-router]</docs-warning>
121+
<docs-warning>`flushSync` only works when using a data router, see [Picking a Router][picking-a-router]</docs-warning>
122122

123123
<docs-warning>Please note that this API is marked unstable and may be subject to breaking changes without a major release</docs-warning>
124124

125-
## `options.unstable_viewTransition`
125+
## `options.viewTransition`
126126

127-
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].
127+
The `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 [`useViewTransitionState()`][use-view-transition-state].
128128

129-
<docs-warning>`unstable_viewTransition` only works when using a data router, see [Picking a Router][picking-a-router]</docs-warning>
129+
<docs-warning>`viewTransition` only works when using a data router, see [Picking a Router][picking-a-router]</docs-warning>
130130

131131
<docs-warning>Please note that this API is marked unstable and may be subject to breaking changes without a major release</docs-warning>
132132

docs/hooks/use-submit.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,11 @@ Because submissions are navigations, the options may also contain the other navi
160160
- `relative`
161161
- `replace`
162162
- `state`
163-
- `unstable_viewTransition`
163+
- `viewTransition`
164164

165-
### `options.unstable_flushSync`
165+
### `options.flushSync`
166166

167-
The `unstable_flushSync` option tells React Router DOM to wrap the initial state update for this submission in a [`ReactDOM.flushSync`][flush-sync] call instead of the default [`React.startTransition`][start-transition]. This allows you to perform synchronous DOM actions immediately after the update is flushed to the DOM.
167+
The `flushSync` option tells React Router DOM to wrap the initial state update for this submission in a [`ReactDOM.flushSync`][flush-sync] call instead of the default [`React.startTransition`][start-transition]. This allows you to perform synchronous DOM actions immediately after the update is flushed to the DOM.
168168

169169
<docs-warning>Please note that this API is marked unstable and may be subject to breaking changes without a major release</docs-warning>
170170

docs/hooks/use-view-transition-state.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
---
2-
title: unstable_useViewTransitionState
2+
title: useViewTransitionState
33
---
44

5-
# `unstable_useViewTransitionState`
5+
# `useViewTransitionState`
66

77
<details>
88
<summary>Type declaration</summary>
99

1010
```tsx
11-
declare function unstable_useViewTransitionState(
11+
declare function useViewTransitionState(
1212
to: To,
1313
opts: { relative?: "route" : "path" } = {}
1414
): boolean;
@@ -24,17 +24,16 @@ interface Path {
2424

2525
</details>
2626

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).
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 [viewTransition][link-view-transition] prop on the `Link` (or the `Form`, `navigate`, or `submit` call).
2828

2929
Consider clicking on an image in a list that you need to expand into the hero image on the destination page:
3030

3131
```jsx
3232
function NavImage({ src, alt, id }) {
3333
const to = `/images/${id}`;
34-
const isTransitioning =
35-
unstable_useViewTransitionState(to);
34+
const isTransitioning = useViewTransitionState(to);
3635
return (
37-
<Link to={to} unstable_viewTransition>
36+
<Link to={to} viewTransition>
3837
<img
3938
src={src}
4039
alt={alt}
@@ -49,5 +48,5 @@ function NavImage({ src, alt, id }) {
4948
}
5049
```
5150

52-
[link-view-transition]: ../components/link#unstable_viewtransition
51+
[link-view-transition]: ../components/link#viewtransition
5352
[view-transitions]: https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API

docs/routers/picking-a-router.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,5 +146,5 @@ The following APIs are introduced in React Router 6.4 and will only work when us
146146
[userouteloaderdata]: ../hooks/use-route-loader-data
147147
[usesubmit]: ../hooks/use-submit
148148
[useblocker]: ../hooks/use-blocker
149-
[viewtransition-link]: ../components/link#unstable_viewtransition
150-
[viewtransition-navigate]: ../hooks/use-navigate#optionsunstable_viewtransition
149+
[viewtransition-link]: ../components/link#viewtransition
150+
[viewtransition-navigate]: ../hooks/use-navigate#optionsviewtransition

0 commit comments

Comments
 (0)