Commit 9598c41
authored
useActionState: On error, cancel remaining actions (#29695)
Based on
- #29694
---
If an action in the useActionState queue errors, we shouldn't run any
subsequent actions. The contract of useActionState is that the actions
run in sequence, and that one action can assume that all previous
actions have completed successfully.
For example, in a shopping cart UI, you might dispatch an "Add to cart"
action followed by a "Checkout" action. If the "Add to cart" action
errors, the "Checkout" action should not run.
An implication of this change is that once useActionState falls into an
error state, the only way to recover is to reset the component tree,
i.e. by unmounting and remounting. The way to customize the error
handling behavior is to wrap the action body in a try/catch.1 parent 67b05be commit 9598c41
File tree
2 files changed
+77
-49
lines changed- packages
- react-dom/src/__tests__
- react-reconciler/src
2 files changed
+77
-49
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1237 | 1237 | | |
1238 | 1238 | | |
1239 | 1239 | | |
1240 | | - | |
1241 | 1240 | | |
1242 | 1241 | | |
1243 | 1242 | | |
1244 | 1243 | | |
1245 | 1244 | | |
1246 | 1245 | | |
1247 | | - | |
1248 | 1246 | | |
1249 | 1247 | | |
1250 | 1248 | | |
| |||
1284 | 1282 | | |
1285 | 1283 | | |
1286 | 1284 | | |
1287 | | - | |
1288 | | - | |
1289 | | - | |
1290 | | - | |
1291 | | - | |
1292 | | - | |
1293 | | - | |
1294 | | - | |
1295 | | - | |
1296 | | - | |
1297 | | - | |
1298 | | - | |
1299 | | - | |
1300 | 1285 | | |
1301 | 1286 | | |
1302 | 1287 | | |
1303 | 1288 | | |
1304 | | - | |
1305 | 1289 | | |
1306 | 1290 | | |
1307 | 1291 | | |
1308 | 1292 | | |
1309 | 1293 | | |
1310 | 1294 | | |
1311 | | - | |
1312 | 1295 | | |
1313 | 1296 | | |
1314 | 1297 | | |
| |||
1346 | 1329 | | |
1347 | 1330 | | |
1348 | 1331 | | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
1349 | 1362 | | |
1350 | | - | |
1351 | | - | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
| 1370 | + | |
1352 | 1371 | | |
1353 | 1372 | | |
1354 | | - | |
1355 | | - | |
1356 | | - | |
1357 | | - | |
1358 | | - | |
1359 | | - | |
1360 | | - | |
1361 | | - | |
1362 | | - | |
1363 | | - | |
| 1373 | + | |
| 1374 | + | |
| 1375 | + | |
| 1376 | + | |
| 1377 | + | |
| 1378 | + | |
| 1379 | + | |
| 1380 | + | |
| 1381 | + | |
| 1382 | + | |
| 1383 | + | |
| 1384 | + | |
| 1385 | + | |
| 1386 | + | |
| 1387 | + | |
| 1388 | + | |
| 1389 | + | |
| 1390 | + | |
1364 | 1391 | | |
1365 | 1392 | | |
1366 | 1393 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1994 | 1994 | | |
1995 | 1995 | | |
1996 | 1996 | | |
1997 | | - | |
| 1997 | + | |
| 1998 | + | |
| 1999 | + | |
1998 | 2000 | | |
1999 | 2001 | | |
2000 | 2002 | | |
| |||
2033 | 2035 | | |
2034 | 2036 | | |
2035 | 2037 | | |
| 2038 | + | |
| 2039 | + | |
| 2040 | + | |
| 2041 | + | |
| 2042 | + | |
| 2043 | + | |
2036 | 2044 | | |
2037 | 2045 | | |
2038 | | - | |
| 2046 | + | |
2039 | 2047 | | |
2040 | 2048 | | |
2041 | 2049 | | |
| |||
2218 | 2226 | | |
2219 | 2227 | | |
2220 | 2228 | | |
2221 | | - | |
2222 | | - | |
2223 | | - | |
2224 | | - | |
2225 | | - | |
2226 | | - | |
2227 | | - | |
| 2229 | + | |
2228 | 2230 | | |
| 2231 | + | |
2229 | 2232 | | |
2230 | 2233 | | |
2231 | | - | |
2232 | | - | |
2233 | | - | |
2234 | | - | |
2235 | | - | |
2236 | | - | |
2237 | | - | |
2238 | | - | |
2239 | | - | |
2240 | | - | |
2241 | | - | |
| 2234 | + | |
| 2235 | + | |
| 2236 | + | |
| 2237 | + | |
| 2238 | + | |
| 2239 | + | |
2242 | 2240 | | |
| 2241 | + | |
| 2242 | + | |
| 2243 | + | |
2243 | 2244 | | |
2244 | 2245 | | |
2245 | 2246 | | |
| |||
0 commit comments