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
+19-22Lines changed: 19 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,7 @@ In React Labs posts, we write about projects in active research and development.
20
20
21
21
React Conf 2025 is scheduled for October 7–8 in Henderson, Nevada!
22
22
23
-
We're looking for speakers to help us create talks about the features covered in this post. If you're interested in speaking at ReactConf, [please apply here](https://forms.reform.app/react-conf/call-for-speakers/piaae1?ga4_visitor_id=c3e8f3ce-2004-47a5-b801-f6b308280acd) (no talk proposal required).
23
+
We're looking for speakers to help us create talks about the features covered in this post. If you're interested in speaking at ReactConf, [please apply here](https://forms.reform.app/react-conf/call-for-speakers/) (no talk proposal required).
24
24
25
25
For more info on tickets, free streaming, sponsoring, and more, see [the React Conf website](https://conf.react.dev).
26
26
@@ -59,7 +59,7 @@ Read on to learn how to use these features in your app, or check out the newly p
59
59
60
60
## View Transitions {/*view-transitions*/}
61
61
62
-
React View Transitions are a new experimental feature that makes it easier to add animations to UI transitions in your app. Under-the-hood, these animations APIs use the new [`startViewTransition`](https://developer.mozilla.org/en-US/docs/Web/API/Document/startViewTransition) API available in most modern browsers.
62
+
React View Transitions are a new experimental feature that makes it easier to add animations to UI transitions in your app. Under-the-hood, these animations use the new [`startViewTransition`](https://developer.mozilla.org/en-US/docs/Web/API/Document/startViewTransition) API available in most modern browsers.
63
63
64
64
To opt-in to animating an element, wrap it in the new `<ViewTransition>` component:
65
65
@@ -4905,7 +4905,7 @@ With transition types, you can provide custom animations via props to `<ViewTran
4905
4905
</ViewTransition>
4906
4906
```
4907
4907
4908
-
Here we pass a `share` prop to define how to animate based on the transiton type. When the share transition activates from `nav-forward`, the view transition class `slide-forward` is applied. When it's from `nav-back`, the `slide-back` animation is activated. Let's define these animations in CSS:
4908
+
Here we pass a `share` prop to define how to animate based on the transition type. When the share transition activates from `nav-forward`, the view transition class `slide-forward` is applied. When it's from `nav-back`, the `slide-back` animation is activated. Let's define these animations in CSS:
4909
4909
4910
4910
```css
4911
4911
::view-transition-old(.slide-forward) {
@@ -10143,9 +10143,9 @@ We're now ready to share the API and how it works, so you can start testing it i
10143
10143
</Activity>
10144
10144
```
10145
10145
10146
-
When an Activity is <CodeStepstep={1}>visible</CodeStep> it's rendered as normal. When an Activity is <CodeStepstep={2}>hidden</CodeStep> it is unmounted, but will save it's state and continue to render at a lower priority than anything visible on screen.
10146
+
When an Activity is <CodeStepstep={1}>visible</CodeStep> it's rendered as normal. When an Activity is <CodeStepstep={2}>hidden</CodeStep> it is unmounted, but will save its state and continue to render at a lower priority than anything visible on screen.
10147
10147
10148
-
You can use `Activity` save state for parts of the UI the user isn't using, or pre-render parts that a user is likely to use next.
10148
+
You can use `Activity`to save state for parts of the UI the user isn't using, or pre-render parts that a user is likely to use next.
10149
10149
10150
10150
Let's look at some examples improving the View Transition examples above.
10151
10151
@@ -10176,7 +10176,7 @@ function App() {
10176
10176
}
10177
10177
```
10178
10178
10179
-
However, this means if the user goes back to the old page, all of the previous state is lost. For example, if the `<Home />` page has an `<input>` field, when the user leaves the page the `<input`> is unmouted, and all of the text they had typed is lost.
10179
+
However, this means if the user goes back to the old page, all of the previous state is lost. For example, if the `<Home />` page has an `<input>` field, when the user leaves the page the `<input`> is unmounted, and all of the text they had typed is lost.
10180
10180
10181
10181
Activity allows you to keep the state around as the user changes pages, so when they come back they can resume where they left off. This is done by wrapping part of the tree in `<Activity>` and toggling the `mode`:
10182
10182
@@ -11516,7 +11516,7 @@ root.render(
11516
11516
11517
11517
Sometimes, you may want to prepare the next part of the UI a user is likely to use ahead of time, so it's ready by the time they are ready to use it. This is especially useful if the next route needs to suspend on data it needs to render, because you can help ensure the data is already fetched before the user navigates.
11518
11518
11519
-
For example, our app currently needs to suspend to load the data for each video when you select one. We can improve this by rendering all of the pages is a hidden `<Activity>` until the user navigates:
11519
+
For example, our app currently needs to suspend to load the data for each video when you select one. We can improve this by rendering all of the pages in a hidden `<Activity>` until the user navigates:
11520
11520
11521
11521
```js {2,5,8}
11522
11522
<ViewTransition>
@@ -11560,16 +11560,13 @@ export default function App() {
@@ -12884,7 +12881,7 @@ Earlier this week [we shared](/blog/2025/04/21/react-compiler-rc) the React Comp
12884
12881
12885
12882
We've also begun exploring ways to use the React Compiler to provide information that can improve understanding and debugging your code. One idea we've started exploring is a new experimental LSP-based React IDE extension powered by React Compiler, similar to the extension used in [Lauren Tan's React Conf talk](https://conf2024.react.dev/talks/5).
12886
12883
12887
-
Our idea is that we can use the compiler's static analysis to provide more information, suggestions, and optimization opportunities directly in your IDE. For example, we can provide diagnostics for code breaking the Rules of React, hovers to show if components and hooks were optimized by the compiler, or a CodeLens to see [automatically inserted Effect dependencies](/#automatic-effect-dependencies).
12884
+
Our idea is that we can use the compiler's static analysis to provide more information, suggestions, and optimization opportunities directly in your IDE. For example, we can provide diagnostics for code breaking the Rules of React, hovers to show if components and hooks were optimized by the compiler, or a CodeLens to see [automatically inserted Effect dependencies](#automatic-effect-dependencies).
12888
12885
12889
12886
The IDE extension is still an early exploration, but we'll share our progress in future updates.
12890
12887
@@ -12902,11 +12899,11 @@ Since their release, hooks have been successful at *sharing code between compone
12902
12899
12903
12900
### Effects can be hard {/*effects-can-be-hard*/}
12904
12901
12905
-
Unfortunately, some hooks are still hard to think in terms of function instead of lifecycles. Effects specifically are still hard to understand and is the most common pain point we hear from developers. Last year, we spent a significant amount of time researching how effects were used, and how those use cases could be simplified and easier to understand.
12902
+
Unfortunately, some hooks are still hard to think in terms of function instead of lifecycles. Effects specifically are still hard to understand and is the most common pain point we hear from developers. Last year, we spent a significant amount of time researching how Effects were used, and how those use cases could be simplified and easier to understand.
12906
12903
12907
-
We found that often, the confusion is from using an Effect when you don't need to. The [You Probably Don't Need an Effect guide](/TODO), covers many cases for when Effects are not the right solution. However, even when an Effect is the right fit for a problem, Effects can still be harder to understand than class component lifecyles.
12904
+
We found that often, the confusion is from using an Effect when you don't need to. The [You Might Not Need an Effect](/learn/you-might-not-need-an-effect) guide, covers many cases for when Effects are not the right solution. However, even when an Effect is the right fit for a problem, Effects can still be harder to understand than class component lifecyles.
12908
12905
12909
-
We believe one of the reasons for confusion is the dependency array, which allows developers to think of effects from the _components_ perspective (like a lifecycle), instead of the _effects_ point of view (what the effect does).
12906
+
We believe one of the reasons for confusion is that developers to think of Effects from the _components_ perspective (like a lifecycle), instead of the _Effects_ point of view (what the Effect does).
12910
12907
12911
12908
Let's look at an example [from the docs](/learn/lifecycle-of-reactive-effects#thinking-from-the-effects-perspective):
12912
12909
@@ -12926,7 +12923,7 @@ Many users would read this code as "on mount, connect to the roomId. whenever `r
12926
12923
12927
12924
### Effects without dependencies {/*effects-without-dependencies*/}
12928
12925
12929
-
Instaed, it's better to think from the Effect's perspective. The effect doesn't know about about the component lifecycles. It only describes how to start synchronization and how to stop it. When users think of Effects in this way, their Effects tend to be easier to write, and more resilient to being started and stopped as many times as it’s needed.
12926
+
Instead, it's better to think from the Effect's perspective. The effect doesn't know about the component lifecycles. It only describes how to start synchronization and how to stop it. When users think of Effects in this way, their Effects tend to be easier to write, and more resilient to being started and stopped as many times as it’s needed.
12930
12927
12931
12928
We spent some time researching why Effects are thought of from the component perspective, and we think one of the resons is the dependency array. Since you have to write it, it's right there and in your face reminding you of what you're "reacting" to and baiting you into the mental model of 'do this when these values change'.
12932
12929
@@ -12942,7 +12939,7 @@ useEffect(() => {
12942
12939
}); // compiler inserted dependencies.
12943
12940
```
12944
12941
12945
-
With this code, the React Compiler can infer the dependencies for you and insert them automatically so you don't need to see or write them. With features like the IDE exension and `useEffectEvent`, we can provide a CodeLens to show you what the Compiler inserted for times you need to debug, or to optimize by removing a dependency. This helps reinforce the correct mental model for writing Effects, which can run at any time to synchronize your component or hook's state with something else
12942
+
With this code, the React Compiler can infer the dependencies for you and insert them automatically so you don't need to see or write them. With features like the IDE exension and `useEffectEvent`, we can provide a CodeLens to show you what the Compiler inserted for times you need to debug, or to optimize by removing a dependency. This helps reinforce the correct mental model for writing Effects, which can run at any time to synchronize your component or hook's state with something else.
12946
12943
12947
12944
Our hope is that automatically inserting dependencies is not only easier to write, but that it also makes them easier to understand by forcing you to think in terms of what the effect does, and not in component lifecycles.
12948
12945
@@ -12990,4 +12987,4 @@ This research is still early. We'll share more, and what the new APIs will look
12990
12987
12991
12988
---
12992
12989
12993
-
_TODO: Thanks to [Dan Abramov](https://bsky.app/profile/danabra.mov), [Lauren Tan](https://bsky.app/profile/no.lol), [Matt Carroll](https://twitter.com/mattcarrollcode), [Jack Pope](https://jackpope.me), [Jason Bonta](https://threads.net/someextent), [Jordan Brown](https://github.com/jbrown215), [Jordan Eldredge](https://bsky.app/profile/capt.dev), and [Mofei Zhang](https://threads.net/z_mofei) for reviewing this post.
12990
+
_TODO: Thanks to [Aurora Scharff](https://bsky.app/profile/aurorascharff.no), [Dan Abramov](https://bsky.app/profile/danabra.mov), [Lauren Tan](https://bsky.app/profile/no.lol), [Luna Wei](https://github.com/lunaleaps), [Matt Carroll](https://twitter.com/mattcarrollcode), [Jack Pope](https://jackpope.me), [Jason Bonta](https://threads.net/someextent), [Jordan Brown](https://github.com/jbrown215), [Jordan Eldredge](https://bsky.app/profile/capt.dev), [Mofei Zhang](https://threads.net/z_mofei), [Sebastien Lorber](https://bsky.app/profile/sebastienlorber.com), and [Sebastian Markbåge](https://bsky.app/profile/sebmarkbage.calyptus.eu) for reviewing this post.
When an <CodeStepstep={1}>Activity</CodeStep> is rendered with <CodeStepstep={2}>mode</CodeStep> "hidden", the `children` are not visible on the page, but are rendered at lower prioirty than the visible content on the page.
90
+
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.
91
91
92
-
When the <CodeStepstep={2}>mode</CodeStep> later switches to <CodeStepstep={4}>visible</CodeStep>, 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.
92
+
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.
93
93
94
-
In the follow example from [`useTransition`](/reference/react/useTransition#preventing-unwanted-loading-indicators), the `PostsTab` component fetches some data using `use`. When you click the “Posts” tab, the `PostsTab` component suspends, causing the button loading state to appear:
94
+
In the following example from [`useTransition`](/reference/react/useTransition#preventing-unwanted-loading-indicators), the `PostsTab` component fetches some data using `use`. When you click the “Posts” tab, the `PostsTab` component suspends, causing the button loading state to appear:
When an <CodeStepstep={1}>Activity</CodeStep> is switches from <CodeStepstep={2}>mode</CodeStep> <CodeStepstep={3}>visible</CodeStep> to <CodeStepstep={4}>hidden</CodeStep>, the `children` will become hidden on the page, and unmount by destroying all Effects, but will keep their React and DOM state.
490
+
When an Activityswitches 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.
491
491
492
-
When the <CodeStepstep={2}>mode</CodeStep> later switches to <CodeStepstep={4}>visible</CodeStep>, 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.
492
+
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.
493
493
494
-
In the follow example from [`useTransition`](/reference/react/useTransition#preventing-unwanted-loading-indicators), the `ContactsTab` includes a `<textarea>` with a draft message to send. If you enter some text and change to a different tab, then when you click the “Contact” tab again, the draft message is lost:
494
+
In the following example from [`useTransition`](/reference/react/useTransition#preventing-unwanted-loading-indicators), the `ContactTab` includes a `<textarea>` with a draft message to send. If you enter some text and change to a different tab, then when you click the “Contact” tab again, the draft message is lost:
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
@@ -40,7 +40,7 @@ import {unstableViewTransition as ViewTransition} from 'react';
40
40
41
41
### `<ViewTransition>` {/*viewtransition*/}
42
42
43
-
Wrap elements in `<ViewTransition>` to animate them when they update inside a [Transition](/reference/react/useTransition). React uses [heuristics](#heuristics) to determine if a View Transition activates for an animation:
43
+
Wrap elements in `<ViewTransition>` to animate them when they update inside a [Transition](/reference/react/useTransition). React uses the following heuristics to determine if a View Transition activates for an animation:
44
44
45
45
-`enter`: If a `ViewTransition` itself gets inserted in this Transition, then this will activate.
46
46
-`exit`: If a `ViewTransition` itself gets deleted in this Transition, then this will activate.
@@ -101,7 +101,7 @@ Each callback receives as arguments:
101
101
-`element`: The DOM element that was animated.
102
102
-`types`: The [Transition Types](/reference/react/addTransitionType) included in the animation.
103
103
104
-
### View Transition Class {/*view-transition-classes*/}
104
+
### View Transition Class {/*view-transition-class*/}
105
105
106
106
The View Transition Class is the CSS class name(s) applied by React during the transition when the ViewTransition activates. It can be a string or an object.
107
107
-`string`: the `class` added on the child elements when activated. If `'none'` is provided, no class will be added.
@@ -122,11 +122,11 @@ To customize the animation for a `<ViewTransition>` you can provide a View Trans
122
122
For example, to customize an "enter" animation, provide a class name to the `enter` prop:
123
123
124
124
125
-
```js [[1, 1, "enter"], [2, 1, "slide-in"]]
125
+
```js
126
126
<ViewTransition enter="slide-in">
127
127
```
128
128
129
-
When the ViewTransition activates an <CodeStepstep={1}>"enter"</CodeStep> animation, React will add the class name <CodeStepstep={2}>slide-in</CodeStep>. Then you can refer to this class using [view transition pseudo selectors](https://developer.mozilla.org/en-US/docs/Web/API/View_Transition_API#pseudo-elements) to build reusable animations:
129
+
When the `<ViewTransition>` activates an "enter" animation, React will add the class name `slide-in`. Then you can refer to this class using [view transition pseudo selectors](https://developer.mozilla.org/en-US/docs/Web/API/View_Transition_API#pseudo-elements) to build reusable animations:
130
130
131
131
```css
132
132
::view-transition-group(.slide-in) {
@@ -171,9 +171,9 @@ function Parent() {
171
171
}
172
172
```
173
173
174
-
When `setShow` is called, `show`switched to `true` and the `Child` component is rendered. Since`setShow` is called inside <CodeStepstep={1}>startTransition</CodeStep>, and `Child` renders a <CodeStepstep={2}>ViewTransition</CodeStep> before any other DOM nodes, an `enter` animation is triggered.
174
+
When `setShow` is called, `show`switches to `true` and the `Child` component is rendered. When`setShow` is called inside `startTransition`, and `Child` renders a `ViewTransition` before any other DOM nodes, an `enter` animation is triggered.
175
175
176
-
When `show`is switched back to `false`, an `exit` animation is triggered.
176
+
When `show`switches back to `false`, an `exit` animation is triggered.
0 commit comments