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
Copy file name to clipboardExpand all lines: src/content/reference/react/ViewTransition.md
+12-12Lines changed: 12 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -51,25 +51,25 @@ Wrap a component tree in `<ViewTransition>` to animate it:
51
51
52
52
Under the hood, React applies `view-transition-name` to inline styles of the nearest DOM node nested inside the `<ViewTransition>` component. If there are multiple sibling DOM nodes like `<ViewTransition><div /><div /></ViewTransition>` then React adds a suffix to the name to make each unique but conceptually they're part of the same one. React doesn't apply these eagerly but only at the time that boundary should participate in an animation.
53
53
54
-
React automatically calls `startViewTransition` itself behind the scenes so you should never do that yourself. In fact, if you have something else on the page running a ViewTransition React will interrupt it. So it's recommended that you use React itself to coordinate these. If you had other ways of trigger ViewTransitions in the past, we recommend that you migrate to the built-in way.
54
+
React automatically calls `startViewTransition` itself behind the scenes so you should never do that yourself. In fact, if you have something else on the page running a ViewTransition React will interrupt it. So it's recommended that you use React itself to coordinate these. If you had other ways to trigger ViewTransitions in the past, we recommend that you migrate to the built-in way.
55
55
56
56
If there are other React ViewTransitions already running then React will wait for them to finish before starting the next one. However, importantly if there are multiple updates happening while the first one is running, those will all be batched into one. If you start A->B. Then in the meantime you get an update to go to C and then D. When the first A->B animation finishes the next one will animate from B->D.
57
57
58
-
The `getSnapshotBeforeUpdate`life-cycle will be called before `startViewTransition` and some `view-transition-name` will update at the same time.
58
+
The `getSnapshotBeforeUpdate`lifecycle will be called before `startViewTransition` and some `view-transition-name` will update at the same time.
59
59
60
60
Then React calls `startViewTransition`. Inside the `updateCallback`, React will:
61
61
62
-
- Apply its mutations to the DOM and invoke useInsertionEffects.
62
+
- Apply its mutations to the DOM and invoke `useInsertionEffect`.
63
63
- Wait for fonts to load.
64
-
- Call componentDidMount, componentDidUpdate, useLayoutEffect and refs.
64
+
- Call `componentDidMount`, `componentDidUpdate`, `useLayoutEffect` and refs.
65
65
- Wait for any pending Navigation to finish.
66
66
- Then React will measure any changes to the layout to see which boundaries will need to animate.
67
67
68
-
After the ready Promise of the `startViewTransition` is resolved, React will then revert the `view-transition-name`. Then React will invoke the `onEnter`, `onExit`, `onUpdate` and `onShare` callbacks to allow for manual programmatic control over the Animations. This will be after the built-in default ones have already been computed.
68
+
After the ready Promise of the `startViewTransition` is resolved, React will then revert the `view-transition-name`. Then React will invoke the `onEnter`, `onExit`, `onUpdate` and `onShare` callbacks to allow for manual programmatic control over the animations. This will be after the built-in default ones have already been computed.
69
69
70
70
If a `flushSync` happens to get in the middle of this sequence, then React will skip the Transition since it relies on being able to complete synchronously.
71
71
72
-
After the finished Promise of the `startViewTransition` is resolved, React will then invoke `useEffect`. This prevents those from interfering with the performance of the Animation. However, this is not a guarantee because if another `setState` happens while the Animation is running it'll still have to invoke the `useEffect` earlier to preserve the sequential guarantees.
72
+
After the finished Promise of the `startViewTransition` is resolved, React will then invoke `useEffect`. This prevents those from interfering with the performance of the animation. However, this is not a guarantee because if another `setState` happens while the animation is running it'll still have to invoke the `useEffect` earlier to preserve the sequential guarantees.
73
73
74
74
</DeepDive>
75
75
@@ -462,7 +462,7 @@ function Component() {
462
462
463
463
### Animating a shared element {/*animating-a-shared-element*/}
464
464
465
-
Normally, we don't recommend assigning a name to a `<ViewTransition>` and instead let React assign it an automatic name. The reason you might want to assign a name is to animate between completely different components when one tree unmounts and another tree mounts at the same time. To preserve continuity.
465
+
Normally, we don't recommend assigning a name to a `<ViewTransition>` and instead let React assign it an automatic name. The reason you might want to assign a name is to animate between completely different components when one tree unmounts and another tree mounts at the same time, to preserve continuity.
466
466
467
467
```js
468
468
<ViewTransition name={UNIQUE_NAME}>
@@ -684,9 +684,9 @@ button:hover {
684
684
685
685
If either the mounted or unmounted side of a pair is outside the viewport, then no pair is formed. This ensures that it doesn't fly in or out of the viewport when something is scrolled. Instead it's treated as a regular enter/exit by itself.
686
686
687
-
This does not happen if the same Component instance changes position, which triggers an "update". Those animate regardless if one position is outside the viewport.
687
+
This does not happen if the same Component instance changes position, which triggers an "update". Those animate regardless of whether one position is outside the viewport.
688
688
689
-
There's currently a quirk where if a deeply nested unmounted `<ViewTransition>` is inside the viewport but the mounted side is not within the viewport, then the unmounted side animates as its own "exit" animation even if it's deeply nested instead of as part of the parent animation.
689
+
There is a known case where if a deeply nested unmounted `<ViewTransition>` is inside the viewport but the mounted side is not within the viewport, then the unmounted side animates as its own "exit" animation even if it's deeply nested instead of as part of the parent animation.
690
690
691
691
</Note>
692
692
@@ -1135,7 +1135,7 @@ It's important to properly use keys to preserve identity when reordering lists.
1135
1135
1136
1136
### Animating from Suspense content {/*animating-from-suspense-content*/}
1137
1137
1138
-
Just like any Transition, React waits for data and new CSS (`<link rel="stylesheet" precedence="...">`) before running the animation. In addition to this, ViewTransitions also wait up to 500ms for new fonts to load before starting the animation to avoid them flickering in later. For the same reason, an image wrapped in ViewTransition will wait for the image to load.
1138
+
Like any Transition, React waits for data and new CSS (`<link rel="stylesheet" precedence="...">`) before running the animation. In addition to this, ViewTransitions also wait up to 500ms for new fonts to load before starting the animation to avoid them flickering in later. For the same reason, an image wrapped in ViewTransition will wait for the image to load.
1139
1139
1140
1140
If it's inside a new Suspense boundary instance, then the fallback is shown first. After the Suspense boundary fully loads, it triggers the `<ViewTransition>` to animate the reveal to the content.
1141
1141
@@ -2207,7 +2207,7 @@ Each callback receives an `instance` with `.old` and `.new` properties represent
2207
2207
</ViewTransition>
2208
2208
```
2209
2209
2210
-
This allows you to combine CSSdriven animations and JavaScriptdriven animations.
2210
+
This allows you to combine CSS-driven animations and JavaScript-driven animations.
2211
2211
2212
2212
In the following example, the default cross-fade is handled by CSS, and the slide animations are driven by JavaScript in the `onEnter` and `onExit` animations:
2213
2213
@@ -2660,7 +2660,7 @@ button:hover {
2660
2660
2661
2661
React waits for any pending Navigation to finish to ensure that scroll restoration happens within the animation. If the Navigation is blocked on React, your router must unblock in `useLayoutEffect` since `useEffect` would lead to a deadlock.
2662
2662
2663
-
If a `startTransition` is started from the legacy popstate event, such as during a "back"-navigation then it must finish synchronously to ensure scroll and form restoration works correctly. This is in conflict with running a View Transition animation. Therefore, React will skip animations from popstate. Therefore animations won't run for the back button. You can fix this by upgrading your router to use the Navigation API.
2663
+
If a `startTransition` is started from the legacy popstate event, such as during a "back"-navigation then it must finish synchronously to ensure scroll and form restoration works correctly. This is in conflict with running a View Transition animation. Therefore, React will skip animations from popstate and animations won't run for the back button. You can fix this by upgrading your router to use the Navigation API.
0 commit comments