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/blog/2025/04/23/react-labs-view-transitions-activity-and-more.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12851,21 +12851,21 @@ When using Activity on a page that uses server-side rendering (SSR), there are a
12851
12851
12852
12852
If part of the page is rendered with `mode="hidden"`, then it will not be included in the SSR response. Instead, React will schedule a client render for the content inside Activity while the rest of the page hydrates, prioritizing the visible content on screen.
12853
12853
12854
-
For parts of the UI rendered with `mode="visible"`, React will de-prioirtize hydration of content within Activity, similar to how Suspense content is hydrated at a lower priority. If the user interacts with the page, we'll priorize hydration within the boundary if needed.
12854
+
For parts of the UI rendered with `mode="visible"`, React will de-prioritize hydration of content within Activity, similar to how Suspense content is hydrated at a lower priority. If the user interacts with the page, we'll prioritize hydration within the boundary if needed.
12855
12855
12856
12856
These are advanced use cases, but they show the additional benefits considered with Activity.
12857
12857
12858
12858
### Future modes for Activity {/*future-modes-for-activity*/}
12859
12859
12860
-
In the future, we may add more modes to Activity.
12860
+
In the future, we may add more modes to Activity.
12861
12861
12862
-
For example, a common use case is rendering a modal, where the previous "inactive" page is visible behind the "active" modal view. The "hidden" mode does not work for this use case, because it's not visible, and not included in SSR.
12862
+
For example, a common use case is rendering a modal, where the previous "inactive" page is visible behind the "active" modal view. The "hidden" mode does not work for this use case because it's not visible and not included in SSR.
12863
12863
12864
-
Instead, we're considering a new mode which would keep the content visible, including rendering it during SSR, but keep it unmounted and de-prioritize updates. This mode may also need to "pause" DOM updates, since it can be distracting to see backgrounded content updating while a modal is open.
12864
+
Instead, we're considering a new mode that would keep the content visible—and included in SSR—but keep it unmounted and de-prioritize updates. This mode may also need to "pause" DOM updates, since it can be distracting to see backgrounded content updating while a modal is open.
12865
12865
12866
-
Another mode we're considering for Activity is the ability to automatically destroy state for hidden Activities if there is too much memory being used. Since the component is already unmounted, it may be preferable to destroy state for the least recently used hidden parts of the app, rather than consume too many resources.
12866
+
Another mode we're considering for Activity is the ability to automatically destroy state for hidden Activities if there is too much memory being used. Since the component is already unmounted, it may be preferable to destroy state for the least recently used hidden parts of the app rather than consume too many resources.
12867
12867
12868
-
These are areas we're still exporing, and we'll share more as we make progress. For more information on what Activity includes today, [check out the docs](/reference/react/Activity).
12868
+
These are areas we're still exploring, and we'll share more as we make progress. For more information on what Activity includes today, [check out the docs](/reference/react/Activity).
Copy file name to clipboardExpand all lines: src/content/reference/react/Activity.md
+6-15Lines changed: 6 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -48,19 +48,10 @@ import {unstableActivity as Activity} from 'react';
48
48
</Activity>
49
49
```
50
50
51
-
When "hidden", the `children` of `<Activity />` are not visible on the page. If a new `<Activity>` mounts as "hidden" then it pre-renders the content at lower priority without blocking the visible content on the page, but does not mount by creating effects. When a "visible" Activity switches to "hidden" it conceptually unmounts by destroying all the effects, but saves it's state. This allows fast switching between "visible" and "hidden" states without re-creating the state for a "hidden" Activity.
51
+
When "hidden", the `children` of `<Activity />` are not visible on the page. If a new `<Activity>` mounts as "hidden" then it pre-renders the content at lower priority without blocking the visible content on the page, but it does not mount by creating Effects. When a "visible" Activity switches to "hidden" it conceptually unmounts by destroying all the Effects, but saves its state. This allows fast switching between "visible" and "hidden" states without recreating the state for a "hidden" Activity.
52
52
53
53
In the future, "hidden" Activities may automatically destroy state based on resources like memory.
54
54
55
-
56
-
<DeepDive>
57
-
58
-
#### How does `<Acivity>` work? {/*how-does-activity-work*/}
59
-
60
-
Under the hood...
61
-
62
-
</DeepDive>
63
-
64
55
#### Props {/*props*/}
65
56
66
57
*`children`: The actual UI you intend to render.
@@ -69,7 +60,7 @@ Under the hood...
69
60
#### Caveats {/*caveats*/}
70
61
71
62
- While hidden, the `children` of `<Activity>` are hidden on the page.
72
-
-`<Activity>` will unmount all Effects when switching from "visible" to "hidden" without destroying React or DOM state. This means Effects that expect to only run "once" on "mount" will run again when switching from "hidden" to "visible". Conceptually, "hidden" Activities are unmounted, but they are not destroyed either. We recommend using [`<StrictMode>`](/reference/react/StrictMode) to catch any unexpected side-effects from this behavior.
63
+
-`<Activity>` will unmount all Effects when switching from "visible" to "hidden" without destroying React or DOM state. This means Effects that are expected to run only once on mount will run again when switching from "hidden" to "visible". Conceptually, "hidden" Activities are unmounted, but they are not destroyed either. We recommend using [`<StrictMode>`](/reference/react/StrictMode) to catch any unexpected side-effects from this behavior.
73
64
- When used with `<ViewTransition>`, hidden activities that reveal in a transition will activate an "enter" animation. Visible Activities hidden in a transition will activate an "exit" animation.
74
65
- Parts of the UI wrapped in `<Activity mode="hidden">` are not included in the SSR response.
75
66
- Parts of the UI wrapped in `<Activity mode="visible">` will hydrate at a lower priority than other content.
@@ -88,7 +79,7 @@ You can pre-render part of the UI using `<Activity mode="hidden">`:
88
79
</Activity>
89
80
```
90
81
91
-
When an Activity is rendered with `mode`"hidden"`, the `children` are not visible on the page, but are rendered at lower prioirty than the visible content on the page.
82
+
When an Activity is rendered with `mode="hidden"`, the `children` are not visible on the page, but are rendered at lower priority than the visible content on the page.
92
83
93
84
When the `mode` later switches to "visible", the pre-rendered children will mount and become visible. This can be used to prepare parts of the UI the user is likely to interact with next to reduce loading times.
94
85
@@ -488,7 +479,7 @@ You can keep state for parts of the UI by switching `<Activity>` from "visible"
488
479
</Activity>
489
480
```
490
481
491
-
When an Activity switches from `mode`"visible"` to`"hidden", the `children` will become hidden on the page, and unmount by destroying all Effects, but will keep their React and DOM state.
482
+
When an Activity switches from `mode="visible"` to"hidden", the `children` will become hidden on the page, and unmount by destroying all Effects, but will keep their React and DOM state.
492
483
493
484
When the `mode` later switches to "visible", the saved state will be re-used when mounting the children by creating all the Effects. This can be used to keep state in parts of the UI the user is likely to interact with again to maintain DOM or React state.
This experience results in losing DOM state the user has input. We can keep the state for the Contact tab by hiding the inactive Tabs with `<Activity>`:
679
+
This results in losing DOM state the user has input. We can keep the state for the Contact tab by hiding the inactive Tabs with `<Activity>`:
This is similar to what would happen if Activity mounted effects when hidden. Similarly, if Activity didn't unmount effects when hiding, the videos would continue to play in the background.
1042
+
This is similar to what would happen if Activity mounted Effects when hidden. Similarly, if Activity didn't unmount Effects when hiding, the videos would continue to play in the background.
1052
1043
1053
1044
Activity solves this by not creating Effects when first rendered as "hidden" and destroying all Effects when switching from "visible" to "hidden":
Copy file name to clipboardExpand all lines: src/content/reference/react/ViewTransition.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -53,7 +53,7 @@ By default, `<ViewTransition>` animates with a smooth cross-fade (the browser de
53
53
54
54
#### How does `<ViewTransition>` work? {/*how-does-viewtransition-work*/}
55
55
56
-
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 siblings 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.
56
+
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.
57
57
58
58
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.
59
59
@@ -67,7 +67,7 @@ Then React calls `startViewTransition`. Inside the `updateCallback`, React will:
67
67
- Wait for fonts to load.
68
68
- Call componentDidMount, componentDidUpdate, useLayoutEffect and refs.
69
69
- Wait for any pending Navigation to finish.
70
-
- Then React will measure any changes to the layout to see which boundaries will need to animation.
70
+
- Then React will measure any changes to the layout to see which boundaries will need to animate.
71
71
72
72
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.
73
73
@@ -94,7 +94,7 @@ These callbacks allow you to adjust the animation imperatively using the [animat
94
94
95
95
***optional**`onEnter`: A function. React calls `onEnter` after an "enter" animation.
96
96
***optional**`onExit`: A function. React calls `onExit` after an "exit" animation.
97
-
***optional**`onShare`: A function. React calls `onShare` after an "share" animation.
97
+
***optional**`onShare`: A function. React calls `onShare` after a "share" animation.
98
98
***optional**`onUpdate`: A function. React calls `onUpdate` after an "update" animation.
99
99
100
100
Each callback receives as arguments:
@@ -113,7 +113,7 @@ The value `'none'` can be used to prevent a View Transition from activating for
113
113
114
114
<Note>
115
115
116
-
In many early examples of View Transitions around the web you'll have seen using a [`view-transition-name`](https://developer.mozilla.org/en-US/docs/Web/CSS/view-transition-name) and then style it using `::view-transition-...(my-name)` selectors. We don't recommend that for styling. Instead, we normally recommend using a View Transition Class instead.
116
+
In many early examples of View Transitions around the web, you'll have seen using a [`view-transition-name`](https://developer.mozilla.org/en-US/docs/Web/CSS/view-transition-name) and then style it using `::view-transition-...(my-name)` selectors. We don't recommend that for styling. Instead, we normally recommend using a View Transition Class instead.
117
117
118
118
</Note>
119
119
@@ -1308,14 +1308,14 @@ Enter/Exit:
1308
1308
</Suspense>
1309
1309
```
1310
1310
1311
-
In this scenario, these are two separate ViewTransition instances each with their own `view-transition-name`. This will be treated as an "exit" of the `<A>` and an "enter of the `<B>`.
1311
+
In this scenario, these are two separate ViewTransition instances each with their own `view-transition-name`. This will be treated as an "exit" of the `<A>` and an "enter" of the `<B>`.
1312
1312
1313
1313
You can achieve different effects depending on where you choose to place the `<ViewTransition>` boundary.
1314
1314
1315
1315
---
1316
1316
### Opting-out of an animation {/*opting-out-of-an-animation*/}
1317
1317
1318
-
Sometimes you're wrapping a large existing component, like a whole page, and you want to animate some updates to, such as changing the theme. However, you don't want it to opt-in all updates inside the whole page to cross-fade when they're updating. Especially if you're incrementally adding more animations.
1318
+
Sometimes you're wrapping a large existing component, like a whole page, and you want to animate some updates, such as changing the theme. However, you don't want it to opt-in all updates inside the whole page to cross-fade when they're updating. Especially if you're incrementally adding more animations.
1319
1319
1320
1320
You can use the class "none" to opt-out of an animation. By wrapping your children in a "none" you can disable animations for updates to them while the parent still triggers.
0 commit comments