Commit 6ca37ef
committed
Check for store mutations before commit
When a store is read for the first time, or when `subscribe` or
`getSnapshot` changes, during a concurrent render, we have to check
at the end of the render phase whether the store was mutated by
an concurrent event.
In the userspace shim, we perform this check in a layout effect, and
patch up any inconsistencies by scheduling another render + commit.
However, even though we patch them up in the next render, the parent
layout effects that fire in the original render will still observe an
inconsistent tree.
In the native implementation, we can instead check for inconsistencies
right after the root is completed, before entering the commit phase. If
we do detect a mutaiton, we can discard the tree and re-render before
firing any effects. The re-render is synchronous to block further
concurrent mutations (which is also what we do to recover from tearing
bugs that result in an error). After the synchronous re-render, we can
assume the tree the tree is consistent and continue with the normal
algorithm for finishing a completed root (i.e. either suspend
or commit).
The result is that layout effects will always observe a consistent tree.1 parent 5265775 commit 6ca37ef
File tree
7 files changed
+573
-110
lines changed- packages/react-reconciler/src
- __tests__
- scripts/jest
7 files changed
+573
-110
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | | - | |
| 15 | + | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | | - | |
| 19 | + | |
| 20 | + | |
21 | 21 | | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
| 33 | + | |
33 | 34 | | |
34 | | - | |
| 35 | + | |
| 36 | + | |
35 | 37 | | |
36 | 38 | | |
37 | | - | |
| 39 | + | |
38 | 40 | | |
39 | 41 | | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
45 | 47 | | |
46 | 48 | | |
47 | 49 | | |
48 | 50 | | |
49 | 51 | | |
50 | 52 | | |
51 | | - | |
52 | | - | |
53 | | - | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
54 | 56 | | |
55 | 57 | | |
56 | 58 | | |
57 | 59 | | |
58 | | - | |
59 | | - | |
| 60 | + | |
| 61 | + | |
60 | 62 | | |
61 | 63 | | |
62 | 64 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
| |||
68 | 69 | | |
69 | 70 | | |
70 | 71 | | |
| 72 | + | |
71 | 73 | | |
72 | 74 | | |
73 | 75 | | |
| |||
166 | 168 | | |
167 | 169 | | |
168 | 170 | | |
169 | | - | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
170 | 180 | | |
171 | 181 | | |
172 | 182 | | |
| |||
689 | 699 | | |
690 | 700 | | |
691 | 701 | | |
| 702 | + | |
692 | 703 | | |
693 | 704 | | |
694 | 705 | | |
| |||
1289 | 1300 | | |
1290 | 1301 | | |
1291 | 1302 | | |
1292 | | - | |
| 1303 | + | |
1293 | 1304 | | |
1294 | | - | |
| 1305 | + | |
1295 | 1306 | | |
1296 | 1307 | | |
1297 | 1308 | | |
1298 | 1309 | | |
1299 | | - | |
1300 | | - | |
1301 | | - | |
1302 | | - | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
1303 | 1322 | | |
1304 | 1323 | | |
1305 | 1324 | | |
| |||
1348 | 1367 | | |
1349 | 1368 | | |
1350 | 1369 | | |
1351 | | - | |
1352 | | - | |
1353 | | - | |
| 1370 | + | |
1354 | 1371 | | |
1355 | | - | |
| 1372 | + | |
1356 | 1373 | | |
1357 | 1374 | | |
1358 | 1375 | | |
1359 | 1376 | | |
1360 | 1377 | | |
1361 | | - | |
| 1378 | + | |
1362 | 1379 | | |
1363 | 1380 | | |
1364 | | - | |
| 1381 | + | |
| 1382 | + | |
| 1383 | + | |
| 1384 | + | |
| 1385 | + | |
| 1386 | + | |
| 1387 | + | |
| 1388 | + | |
1365 | 1389 | | |
1366 | 1390 | | |
1367 | 1391 | | |
1368 | 1392 | | |
1369 | 1393 | | |
| 1394 | + | |
| 1395 | + | |
| 1396 | + | |
| 1397 | + | |
| 1398 | + | |
| 1399 | + | |
| 1400 | + | |
| 1401 | + | |
| 1402 | + | |
| 1403 | + | |
| 1404 | + | |
| 1405 | + | |
| 1406 | + | |
| 1407 | + | |
| 1408 | + | |
| 1409 | + | |
| 1410 | + | |
| 1411 | + | |
| 1412 | + | |
| 1413 | + | |
| 1414 | + | |
| 1415 | + | |
| 1416 | + | |
| 1417 | + | |
| 1418 | + | |
1370 | 1419 | | |
1371 | 1420 | | |
1372 | 1421 | | |
1373 | 1422 | | |
1374 | 1423 | | |
1375 | 1424 | | |
| 1425 | + | |
1376 | 1426 | | |
1377 | 1427 | | |
1378 | 1428 | | |
1379 | | - | |
1380 | | - | |
| 1429 | + | |
| 1430 | + | |
| 1431 | + | |
| 1432 | + | |
1381 | 1433 | | |
1382 | 1434 | | |
1383 | 1435 | | |
| |||
1393 | 1445 | | |
1394 | 1446 | | |
1395 | 1447 | | |
1396 | | - | |
1397 | | - | |
1398 | | - | |
1399 | | - | |
1400 | | - | |
1401 | 1448 | | |
1402 | 1449 | | |
1403 | 1450 | | |
| |||
0 commit comments