Skip to content

Commit e8fe1a5

Browse files
merging all conflicts
2 parents da5ad3d + 56df8af commit e8fe1a5

10 files changed

Lines changed: 263 additions & 14 deletions

File tree

src/content/blog/2024/04/25/react-19-upgrade-guide.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,13 @@ We expect most apps will not be affected since the transform is enabled in most
7070
To install the latest version of React and React DOM:
7171

7272
```bash
73-
npm install react@rc react-dom@rc
73+
npm install --save-exact react@rc react-dom@rc
74+
```
75+
76+
Or, if you're using Yarn:
77+
78+
```bash
79+
yarn add --exact react@rc react-dom@rc
7480
```
7581

7682
If you're using TypeScript, you also need to update the types. Once React 19 is released as stable, you can install the types as usual from `@types/react` and `@types/react-dom`. Until the stable release, the types are available in different packages which need to be enforced in your `package.json`:
@@ -405,7 +411,7 @@ root.render(<App />);
405411

406412
<Note>
407413

408-
Codemod `ReactDOM.render` to `ReactDOM.createRoot`:
414+
Codemod `ReactDOM.render` to `ReactDOMClient.createRoot`:
409415

410416
```bash
411417
npx codemod@latest react/19/replace-reactdom-render
@@ -427,6 +433,15 @@ import {hydrateRoot} from 'react-dom/client';
427433
hydrateRoot(document.getElementById('root'), <App />);
428434
```
429435

436+
<Note>
437+
438+
Codemod `ReactDOM.hydrate` to `ReactDOMClient.hydrateRoot`:
439+
440+
```bash
441+
npx codemod@latest react/19/replace-reactdom-render
442+
```
443+
444+
</Note>
430445

431446
#### Removed: `unmountComponentAtNode` {/*removed-unmountcomponentatnode*/}
432447

@@ -443,8 +458,18 @@ root.unmount();
443458

444459
For more see `root.unmount()` for [`createRoot`](https://react.dev/reference/react-dom/client/createRoot#root-unmount) and [`hydrateRoot`](https://react.dev/reference/react-dom/client/hydrateRoot#root-unmount).
445460

461+
<Note>
462+
463+
Codemod `unmountComponentAtNode` to `root.unmount`:
464+
465+
```bash
466+
npx codemod@latest react/19/replace-reactdom-render
467+
```
468+
469+
</Note>
446470

447471
#### Removed: `ReactDOM.findDOMNode` {/*removed-reactdom-finddomnode*/}
472+
448473
`ReactDOM.findDOMNode` was [deprecated in October 2018 (v16.6.0)](https://legacy.reactjs.org/blog/2018/10/23/react-v-16-6.html#deprecations-in-strictmode).
449474

450475
We're removing `findDOMNode` because it was a legacy escape hatch that was slow to execute, fragile to refactoring, only returned the first child, and broke abstraction levels (see more [here](https://legacy.reactjs.org/docs/strict-mode.html#warning-about-deprecated-finddomnode-usage)). You can replace `ReactDOM.findDOMNode` with [DOM refs](/learn/manipulating-the-dom-with-refs):

src/content/community/conferences.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Do you know of a local React.js conference? Add it here! (Please keep the list c
1010

1111
## Upcoming Conferences {/*upcoming-conferences*/}
1212

13+
<<<<<<< HEAD
1314
### React Paris 2024 {/*react-paris-2024*/}
1415
March 22, 2024. In-person in Paris, France + Remote (hybrid)
1516

@@ -53,6 +54,8 @@ June 4 - 7, 2024. Online
5354

5455
[Website](https://frontendnation.com/) - [Twitter](https://twitter.com/frontendnation)
5556

57+
=======
58+
>>>>>>> 56df8af577407c69889f24a4c7d9ddb54745a26b
5659
### React Summit 2024 {/*react-summit-2024*/}
5760
June 14 & 18, 2024. In-person in Amsterdam, Netherlands + remote (hybrid event)
5861

@@ -106,6 +109,41 @@ October 17 - 19, 2024. In-person in Goa, India (hybrid event) + Oct 15 2024 - re
106109

107110
## Past Conferences {/*past-conferences*/}
108111

112+
### Frontend Nation 2024 {/*frontend-nation-2024*/}
113+
June 4 - 7, 2024. Online
114+
115+
[Website](https://frontendnation.com/) - [Twitter](https://twitter.com/frontendnation)
116+
117+
### App.js Conf 2024 {/*appjs-conf-2024*/}
118+
May 22 - 24, 2024. In-person in Kraków, Poland + remote
119+
120+
[Website](https://appjs.co) - [Twitter](https://twitter.com/appjsconf)
121+
122+
### React Conf 2024 {/*react-conf-2024*/}
123+
May 15 - 16, 2024. In-person in Henderson, NV, USA + remote
124+
125+
[Website](https://conf.react.dev) - [Twitter](https://twitter.com/reactjs)
126+
127+
### React Native Connection 2024 {/*react-native-connection-2024*/}
128+
April 23, 2024. In-person in Paris, France
129+
130+
[Website](https://reactnativeconnection.io/) - [Twitter](https://twitter.com/ReactNativeConn)
131+
132+
### React Miami 2024 {/*react-miami-2024*/}
133+
April 19 - 20, 2024. In-person in Miami, FL, USA
134+
135+
[Website](https://reactmiami.com/) - [Twitter](https://twitter.com/ReactMiamiConf)
136+
137+
### Epic Web Conf 2024 {/*epic-web-2024*/}
138+
April 10 - 11, 2024. In-person in Park City, UT, USA
139+
140+
[Website](https://www.epicweb.dev/conf) - [YouTube](https://www.youtube.com/@EpicWebDev)
141+
142+
### React Paris 2024 {/*react-paris-2024*/}
143+
March 22, 2024. In-person in Paris, France + Remote (hybrid)
144+
145+
[Website](https://react.paris/) - [Twitter](https://twitter.com/BeJS_) - [LinkedIn](https://www.linkedin.com/events/7150816372074192900/comments/)
146+
109147
### React Day Berlin 2023 {/*react-day-berlin-2023*/}
110148
December 8 & 12, 2023. In-person in Berlin, Germany + remote first interactivity (hybrid event)
111149

src/content/learn/installation.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ export default function App() {
3737

3838
Дәл осы жерде код жазуға немесе жоғарғы оң жақ бұрыштағы «Fork» түймесін басу арқылы кодты жаңа табта ашуға болады.
3939

40+
<<<<<<< HEAD
4041
Мұндай құмжәшіктер React құжаттамасының беттерінің көпшілігінде қолжетімді. React құжаттамасынан басқа, React-ті қолдайтын көптеген онлайн құмжәшіктері бар: мысалы, [CodeSandbox](https://codesandbox.io/s/new), [StackBlitz](https://stackblitz.com/fork/react), немесе [CodePen.](https://codepen.io/pen?&editors=0010&layout=left&prefill_data_id=3f4569d1-1b11-4bce-bd46-89090eed5ddb)
42+
=======
43+
Most pages in the React documentation contain sandboxes like this. Outside of the React documentation, there are many online sandboxes that support React: for example, [CodeSandbox](https://codesandbox.io/s/new), [StackBlitz](https://stackblitz.com/fork/react), or [CodePen.](https://codepen.io/pen?template=QWYVwWN)
44+
>>>>>>> 56df8af577407c69889f24a4c7d9ddb54745a26b
4145
4246
### Локальде React-тi қолданып көріңіз {/*try-react-locally*/}
4347

src/content/reference/react-dom/components/script.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,10 @@ Props that are **not recommended** for use with React:
6868

6969
#### Special rendering behavior {/*special-rendering-behavior*/}
7070

71-
React can move `<script>` components to the document's `<head>`, de-duplicate identical scripts, and [suspend](/reference/react/Suspense) while the script is loading.
71+
React can move `<script>` components to the document's `<head>` and de-duplicate identical scripts.
7272

7373
To opt into this behavior, provide the `src` and `async={true}` props. React will de-duplicate scripts if they have the same `src`. The `async` prop must be true to allow scripts to be safely moved.
7474

75-
If you supply any of the `onLoad` or `onError` props, there is no special behavior, because these props indicate that you are managing the loading of the script manually within your component.
76-
7775
This special treatment comes with two caveats:
7876

7977
* React will ignore changes to props after the script has been rendered. (React will issue a warning in development if this happens.)
@@ -86,8 +84,10 @@ This special treatment comes with two caveats:
8684
### Rendering an external script {/*rendering-an-external-script*/}
8785

8886
If a component depends on certain scripts in order to be displayed correctly, you can render a `<script>` within the component.
87+
However, the component might be committed before the script has finished loading.
88+
You can start depending on the script content once the `load` event is fired e.g. by using the `onLoad` prop.
8989

90-
If you supply an `src` and `async` prop, your component will suspend while the script is loading. React will de-duplicate scripts that have the same `src`, inserting only one of them into the DOM even if multiple components render it.
90+
React will de-duplicate scripts that have the same `src`, inserting only one of them into the DOM even if multiple components render it.
9191

9292
<SandpackWithHTMLOutput>
9393

@@ -97,7 +97,7 @@ import ShowRenderedHTML from './ShowRenderedHTML.js';
9797
function Map({lat, long}) {
9898
return (
9999
<>
100-
<script async src="map-api.js" />
100+
<script async src="map-api.js" onLoad={() => console.log('script loaded')} />
101101
<div id="map" data-lat={lat} data-long={long} />
102102
</>
103103
);
@@ -120,7 +120,7 @@ When you want to use a script, it can be beneficial to call the [preinit](/refer
120120

121121
### Rendering an inline script {/*rendering-an-inline-script*/}
122122

123-
To include an inline script, render the `<script>` component with the script source code as its children. Inline scripts are not de-duplicated or moved to the document `<head>`, and since they don't load any external resources, they will not cause your component to suspend.
123+
To include an inline script, render the `<script>` component with the script source code as its children. Inline scripts are not de-duplicated or moved to the document `<head>`.
124124

125125
<SandpackWithHTMLOutput>
126126

src/content/reference/react-dom/preinit.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ The `preinit` function is currently only available in React's Canary and experim
2020
`preinit` lets you eagerly fetch and evaluate a stylesheet or external script.
2121

2222
```js
23-
preinit("https://example.com/script.js", {as: "style"});
23+
preinit("https://example.com/script.js", {as: "script"});
2424
```
2525

2626
</Intro>

src/content/reference/react/act.md

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
---
2+
title: act
3+
---
4+
5+
<Intro>
6+
7+
`act` is a test helper to apply pending React updates before making assertions.
8+
9+
```js
10+
await act(async actFn)
11+
```
12+
13+
</Intro>
14+
15+
To prepare a component for assertions, wrap the code rendering it and performing updates inside an `await act()` call. This makes your test run closer to how React works in the browser.
16+
17+
<Note>
18+
You might find using `act()` directly a bit too verbose. To avoid some of the boilerplate, you could use a library like [React Testing Library](https://testing-library.com/docs/react-testing-library/intro), whose helpers are wrapped with `act()`.
19+
</Note>
20+
21+
22+
<InlineToc />
23+
24+
---
25+
26+
## Reference {/*reference*/}
27+
28+
### `await act(async actFn)` {/*await-act-async-actfn*/}
29+
30+
When writing UI tests, tasks like rendering, user events, or data fetching can be considered as “units” of interaction with a user interface. React provides a helper called `act()` that makes sure all updates related to these “units” have been processed and applied to the DOM before you make any assertions.
31+
32+
The name `act` comes from the [Arrange-Act-Assert](https://wiki.c2.com/?ArrangeActAssert) pattern.
33+
34+
```js {2,4}
35+
it ('renders with button disabled', async () => {
36+
await act(async () => {
37+
root.render(<TestComponent />)
38+
});
39+
expect(container.querySelector('button')).toBeDisabled();
40+
});
41+
```
42+
43+
<Note>
44+
45+
We recommend using `act` with `await` and an `async` function. Although the sync version works in many cases, it doesn't work in all cases and due to the way React schedules updates internally, it's difficult to predict when you can use the sync version.
46+
47+
We will deprecate and remove the sync version in the future.
48+
49+
</Note>
50+
51+
#### Parameters {/*parameters*/}
52+
53+
* `async actFn`: An async function wrapping renders or interactions for components being tested. Any updates triggered within the `actFn`, are added to an internal act queue, which are then flushed together to process and apply any changes to the DOM. Since it is async, React will also run any code that crosses an async boundary, and flush any updates scheduled.
54+
55+
#### Returns {/*returns*/}
56+
57+
`act` does not return anything.
58+
59+
## Usage {/*usage*/}
60+
61+
When testing a component, you can use `act` to make assertions about its output.
62+
63+
For example, let’s say we have this `Counter` component, the usage examples below show how to test it:
64+
65+
```js
66+
function Counter() {
67+
const [count, setCount] = useState(0);
68+
const handleClick = () => {
69+
setCount(prev => prev + 1);
70+
}
71+
72+
useEffect(() => {
73+
document.title = `You clicked ${this.state.count} times`;
74+
}, [count]);
75+
76+
return (
77+
<div>
78+
<p>You clicked {this.state.count} times</p>
79+
<button onClick={this.handleClick}>
80+
Click me
81+
</button>
82+
</div>
83+
)
84+
}
85+
```
86+
87+
### Rendering components in tests {/*rendering-components-in-tests*/}
88+
89+
To test the render output of a component, wrap the render inside `act()`:
90+
91+
```js {10,12}
92+
import {act} from 'react';
93+
import ReactDOM from 'react-dom/client';
94+
import Counter from './Counter';
95+
96+
it('can render and update a counter', async () => {
97+
container = document.createElement('div');
98+
document.body.appendChild(container);
99+
100+
// ✅ Render the component inside act().
101+
await act(() => {
102+
ReactDOM.createRoot(container).render(<Counter />);
103+
});
104+
105+
const button = container.querySelector('button');
106+
const label = container.querySelector('p');
107+
expect(label.textContent).toBe('You clicked 0 times');
108+
expect(document.title).toBe('You clicked 0 times');
109+
});
110+
```
111+
112+
Here, we create a container, append it to the document, and render the `Counter` component inside `act()`. This ensures that the component is rendered and its effects are applied before making assertions.
113+
114+
Using `act` ensures that all updates have been applied before we make assertions.
115+
116+
### Dispatching events in tests {/*dispatching-events-in-tests*/}
117+
118+
To test events, wrap the event dispatch inside `act()`:
119+
120+
```js {14,16}
121+
import {act} from 'react';
122+
import ReactDOM from 'react-dom/client';
123+
import Counter from './Counter';
124+
125+
it.only('can render and update a counter', async () => {
126+
const container = document.createElement('div');
127+
document.body.appendChild(container);
128+
129+
await act( async () => {
130+
ReactDOMClient.createRoot(container).render(<Counter />);
131+
});
132+
133+
// ✅ Dispatch the event inside act().
134+
await act(async () => {
135+
button.dispatchEvent(new MouseEvent('click', { bubbles: true }));
136+
});
137+
138+
const button = container.querySelector('button');
139+
const label = container.querySelector('p');
140+
expect(label.textContent).toBe('You clicked 1 times');
141+
expect(document.title).toBe('You clicked 1 times');
142+
});
143+
```
144+
145+
Here, we render the component with `act`, and then dispatch the event inside another `act()`. This ensures that all updates from the event are applied before making assertions.
146+
147+
<Pitfall>
148+
149+
Don’t forget that dispatching DOM events only works when the DOM container is added to the document. You can use a library like [React Testing Library](https://testing-library.com/docs/react-testing-library/intro) to reduce the boilerplate code.
150+
151+
</Pitfall>
152+
153+
## Troubleshooting {/*troubleshooting*/}
154+
155+
### I'm getting an error: "The current testing environment is not configured to support act"(...)" {/*error-the-current-testing-environment-is-not-configured-to-support-act*/}
156+
157+
Using `act` requires setting `global.IS_REACT_ACT_ENVIRONMENT=true` in your test environment. This is to ensure that `act` is only used in the correct environment.
158+
159+
If you don't set the global, you will see an error like this:
160+
161+
<ConsoleBlock level="error">
162+
163+
Warning: The current testing environment is not configured to support act(...)
164+
165+
</ConsoleBlock>
166+
167+
To fix, add this to your global setup file for React tests:
168+
169+
```js
170+
global.IS_REACT_ACT_ENVIRONMENT=true
171+
```
172+
173+
<Note>
174+
175+
In testing frameworks like [React Testing Library](https://testing-library.com/docs/react-testing-library/intro), `IS_REACT_ACT_ENVIRONMENT` is already set for you.
176+
177+
</Note>

src/content/reference/react/apis.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ In addition to [Hooks](/reference/react) and [Components](/reference/react/compo
1515
* [`lazy`](/reference/react/lazy) lets you defer loading a component's code until it's rendered for the first time.
1616
* [`memo`](/reference/react/memo) lets your component skip re-renders with same props. Used with [`useMemo`](/reference/react/useMemo) and [`useCallback`.](/reference/react/useCallback)
1717
* [`startTransition`](/reference/react/startTransition) lets you mark a state update as non-urgent. Similar to [`useTransition`.](/reference/react/useTransition)
18+
* [`act`](/reference/react/act) lets you wrap renders and interactions in tests to ensure updates have processed before making assertions.
1819

1920
---
2021

src/content/reference/react/cache.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ By caching a long-running data fetch, you can kick off asynchronous work prior t
226226
```jsx [[2, 6, "await getUser(id)"], [1, 17, "getUser(id)"]]
227227
const getUser = cache(async (id) => {
228228
return await db.user.query(id);
229-
}
229+
})
230230

231231
async function Profile({id}) {
232232
const user = await getUser(id);

src/content/warnings/react-test-renderer.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ title: react-test-renderer Deprecation Warnings
66

77
react-test-renderer is deprecated. A warning will fire whenever calling ReactTestRenderer.create() or ReactShallowRender.render(). The react-test-renderer package will remain available on NPM but will not be maintained and may break with new React features or changes to React's internals.
88

9-
The React Team recommends migrating your tests to [@testing-library/react](https://testing-library.com/docs/react-testing-library/intro/) or [@testing-library/react-native](https://callstack.github.io/react-native-testing-library/docs/getting-started) for a modern and well supported testing experience.
9+
The React Team recommends migrating your tests to [@testing-library/react](https://testing-library.com/docs/react-testing-library/intro/) or [@testing-library/react-native](https://callstack.github.io/react-native-testing-library/docs/start/intro) for a modern and well supported testing experience.
1010

1111

1212
## new ShallowRenderer() warning {/*new-shallowrenderer-warning*/}

0 commit comments

Comments
 (0)