Commit e0c9b2f
committed
feat: necessary api changes for React 19 compatibility (#10)
BREAKING CHANGE: This release has to break some old APIs to stay compatible with React 19.
\#\# `render` is now `async` and should be `await`ed
This is the core change - due to the impementation of sibling prerendering on the React side, rendering has become more `async` and tests that interacted with `render` in a synchronous fashion would end up with not-resolving suspense boundaries.
Please adjust your tests accordingly:
```diff
const {takeRender, render} = createRenderStream({ /* ... */ })
- const utils = render(<Counter />)
+ const utils = await render(<Counter />)
```
\#\# enforcing of `IS_REACT_ACT_ENVIRONMENT == false`
In combination with [issues we have have seen in the past](facebook/react#29855), we have deduced that the testing approach of this library only really works in a "real-world" scenario, not in an `act` environment.
As a result, we will now throw an error if you try to use it in an environment where `IS_REACT_ACT_ENVIRONMENT` is truthy.
We are shipping a new tool, `disableActEnvironment` to prepare your environment for the duration of a test in a safe manner.
This helper can either be used with explicit resource management using the `using` keyword:
```ts
test('my test', () => {
using _disabledAct = disableActEnvironment()
// your test code here
// as soon as this scope is left, the environment will be cleaned up
})
```
of by manually calling `cleanup`:
```ts
test('my test', () => {
const {cleanup} = disableActEnvironment()
try {
// your test code here
} finally {
cleanup()
}
})
```
This function does not only adjust your `IS_REACT_ACT_ENVIRONMENT` value, but it will also temporarily adjust the `@testing-library/dom` configuration in a way so that e.g. calls to `userEvent` will not automatically be wrapped in `act`.
Of course you can also use this tool on a per-file basis instead of a per-test basis, but keep in mind that doing so will break any React Testing Library tests that might be in the same file.
\#\# `render` is now it's own implementation
Previously, we used the `render` function of React Testing Library, but with the new restrictions this is no longer possible and we are shipping our own implementation.
As a result, some less-common options are not supported in the new implementation.
If you have a need for these, please let us know!
* `hydrate` was removed
* `legacyRoot` was removed. If you are using React 17, it will automatically switch to `ReactDOM.render`, otherwise we will use `createRoot`
> [!CAUTION]
> React 17 does not look for `IS_REACT_ACT_ENVIRONMENT` to determine if it is running in an `act`-environment, but rather `typeof jest !== "undefined"`.
> If you have to test React 17, we recommend to patch it with a [`patch-package` patch](https://github.com/apollographql/apollo-client/blob/8a4738a8ad7284d247513671628a4ac5917e104c/patches/react-dom-17+17.0.2.patch)
\#\# `renderToRenderStream` was removed
As you now have to `await` the `render` call, `renderToRenderStream` had no real value anymore.
Where previously, the second line of
```js
const renderStream = renderToRenderStream(<Component />, combinedOptions)
// this was optional in the past
const utils = await renderStream.renderResultPromise
```
could be omitted and could save you some code, now that second line would become required.
This now was not any shorter than calling `createRenderStream` and `renderStream.render` instead, and as both of these APIs now did the same thing in a different fashion, this would lead to confusion to no more benefit, so the API was removed.1 parent 5c44c14 commit e0c9b2f
File tree
19 files changed
+628
-318
lines changed- src
- __testHelpers__
- __tests__
- expect/__tests__
- renderStream
- __tests__
- tests
19 files changed
+628
-318
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
7 | | - | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | 61 | | |
84 | 62 | | |
85 | 63 | | |
86 | 64 | | |
87 | 65 | | |
88 | 66 | | |
89 | 67 | | |
90 | | - | |
| 68 | + | |
91 | 69 | | |
92 | 70 | | |
93 | 71 | | |
| |||
105 | 83 | | |
106 | 84 | | |
107 | 85 | | |
108 | | - | |
| 86 | + | |
109 | 87 | | |
110 | 88 | | |
111 | 89 | | |
| |||
146 | 124 | | |
147 | 125 | | |
148 | 126 | | |
149 | | - | |
| 127 | + | |
150 | 128 | | |
151 | 129 | | |
152 | 130 | | |
| |||
179 | 157 | | |
180 | 158 | | |
181 | 159 | | |
182 | | - | |
| 160 | + | |
183 | 161 | | |
184 | 162 | | |
185 | 163 | | |
| |||
215 | 193 | | |
216 | 194 | | |
217 | 195 | | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
228 | 204 | | |
229 | 205 | | |
230 | 206 | | |
| |||
247 | 223 | | |
248 | 224 | | |
249 | 225 | | |
250 | | - | |
| 226 | + | |
251 | 227 | | |
252 | 228 | | |
253 | 229 | | |
| |||
285 | 261 | | |
286 | 262 | | |
287 | 263 | | |
288 | | - | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
289 | 269 | | |
290 | | - | |
| 270 | + | |
| 271 | + | |
291 | 272 | | |
292 | | - | |
293 | | - | |
294 | | - | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
295 | 277 | | |
296 | | - | |
297 | | - | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
298 | 281 | | |
299 | | - | |
300 | | - | |
301 | | - | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
87 | | - | |
| 86 | + | |
| 87 | + | |
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
1 | 3 | | |
2 | 4 | | |
3 | 5 | | |
| |||
33 | 35 | | |
34 | 36 | | |
35 | 37 | | |
36 | | - | |
| 38 | + | |
37 | 39 | | |
38 | 40 | | |
39 | 41 | | |
| |||
44 | 46 | | |
45 | 47 | | |
46 | 48 | | |
| 49 | + | |
| 50 | + | |
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | | - | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | | - | |
| 62 | + | |
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| |||
This file was deleted.
0 commit comments