Commit dd448d3
committed
Bugfix: Nested useOpaqueIdentifier calls
Fixes an issue where multiple useOpaqueIdentifier hooks are upgraded
to client ids within the same render.
The way the upgrade works is that useOpaqueIdentifier schedules a
render phase update then throws an error to trigger React's error
recovery mechanism.
The normal error recovery mechanism is designed for errors that occur
as a result of interleaved mutations, so we usually only retry a single
time, synchronously, before giving up.
useOpaqueIdentifier is different because the error its throws when
upgrading is not caused by an interleaved mutation. Rather, it happens
when an ID is referenced for the first time inside a client-rendered
tree (i.e. sommething that wasn't part of the initial server render).
The fact that it relies on the error recovery mechanism is an
implementation detail. And a single recovery attempt may be
insufficient. For example, if a parent and a child component may
reference different ids, and both are mounted as a result of the same
client update, that will trigger two separate error recovery attempts.
Because render phase updates are not allowed when triggered from
userspace — we log a warning in developement to prevent them —
we can assume that if something does update during the render phase, it
is one of our "legit" implementation details like useOpaqueIdentifier.
So we can keep retrying until we succeed — up to a limit, to protect
against inifite loops. I chose 50 since that's the limit we use for
commit phase updates.1 parent c71d3ab commit dd448d3
4 files changed
Lines changed: 169 additions & 30 deletions
File tree
- packages
- react-dom/src/__tests__
- react-reconciler/src
- __tests__
Lines changed: 35 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1975 | 1975 | | |
1976 | 1976 | | |
1977 | 1977 | | |
| 1978 | + | |
| 1979 | + | |
| 1980 | + | |
| 1981 | + | |
| 1982 | + | |
| 1983 | + | |
| 1984 | + | |
| 1985 | + | |
| 1986 | + | |
| 1987 | + | |
| 1988 | + | |
| 1989 | + | |
| 1990 | + | |
| 1991 | + | |
| 1992 | + | |
| 1993 | + | |
| 1994 | + | |
| 1995 | + | |
| 1996 | + | |
| 1997 | + | |
| 1998 | + | |
| 1999 | + | |
| 2000 | + | |
| 2001 | + | |
| 2002 | + | |
| 2003 | + | |
| 2004 | + | |
| 2005 | + | |
| 2006 | + | |
| 2007 | + | |
| 2008 | + | |
| 2009 | + | |
| 2010 | + | |
| 2011 | + | |
| 2012 | + | |
1978 | 2013 | | |
1979 | 2014 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
294 | 294 | | |
295 | 295 | | |
296 | 296 | | |
297 | | - | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
298 | 300 | | |
299 | 301 | | |
300 | 302 | | |
| |||
474 | 476 | | |
475 | 477 | | |
476 | 478 | | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
477 | 485 | | |
478 | 486 | | |
479 | 487 | | |
| |||
514 | 522 | | |
515 | 523 | | |
516 | 524 | | |
517 | | - | |
518 | | - | |
| 525 | + | |
| 526 | + | |
519 | 527 | | |
520 | 528 | | |
521 | 529 | | |
| |||
878 | 886 | | |
879 | 887 | | |
880 | 888 | | |
881 | | - | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
882 | 908 | | |
883 | 909 | | |
884 | 910 | | |
| |||
1055 | 1081 | | |
1056 | 1082 | | |
1057 | 1083 | | |
1058 | | - | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
1059 | 1088 | | |
1060 | 1089 | | |
1061 | 1090 | | |
| |||
1081 | 1110 | | |
1082 | 1111 | | |
1083 | 1112 | | |
1084 | | - | |
1085 | | - | |
1086 | | - | |
1087 | | - | |
1088 | | - | |
1089 | | - | |
1090 | | - | |
1091 | | - | |
1092 | | - | |
1093 | | - | |
1094 | | - | |
1095 | | - | |
1096 | | - | |
1097 | 1113 | | |
1098 | 1114 | | |
1099 | 1115 | | |
1100 | 1116 | | |
1101 | 1117 | | |
1102 | 1118 | | |
1103 | 1119 | | |
1104 | | - | |
| 1120 | + | |
1105 | 1121 | | |
1106 | | - | |
1107 | | - | |
1108 | 1122 | | |
1109 | 1123 | | |
1110 | 1124 | | |
| |||
1313 | 1327 | | |
1314 | 1328 | | |
1315 | 1329 | | |
1316 | | - | |
| 1330 | + | |
| 1331 | + | |
1317 | 1332 | | |
1318 | 1333 | | |
1319 | 1334 | | |
| |||
1456 | 1471 | | |
1457 | 1472 | | |
1458 | 1473 | | |
1459 | | - | |
| 1474 | + | |
1460 | 1475 | | |
1461 | 1476 | | |
1462 | 1477 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
294 | 294 | | |
295 | 295 | | |
296 | 296 | | |
297 | | - | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
298 | 300 | | |
299 | 301 | | |
300 | 302 | | |
| |||
474 | 476 | | |
475 | 477 | | |
476 | 478 | | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
477 | 485 | | |
478 | 486 | | |
479 | 487 | | |
| |||
514 | 522 | | |
515 | 523 | | |
516 | 524 | | |
517 | | - | |
518 | | - | |
| 525 | + | |
| 526 | + | |
519 | 527 | | |
520 | 528 | | |
521 | 529 | | |
| |||
878 | 886 | | |
879 | 887 | | |
880 | 888 | | |
881 | | - | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
882 | 908 | | |
883 | 909 | | |
884 | 910 | | |
| |||
1055 | 1081 | | |
1056 | 1082 | | |
1057 | 1083 | | |
1058 | | - | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
1059 | 1088 | | |
1060 | 1089 | | |
1061 | 1090 | | |
| |||
1313 | 1342 | | |
1314 | 1343 | | |
1315 | 1344 | | |
1316 | | - | |
| 1345 | + | |
| 1346 | + | |
1317 | 1347 | | |
1318 | 1348 | | |
1319 | 1349 | | |
| |||
1456 | 1486 | | |
1457 | 1487 | | |
1458 | 1488 | | |
1459 | | - | |
| 1489 | + | |
1460 | 1490 | | |
1461 | 1491 | | |
1462 | 1492 | | |
| |||
Lines changed: 59 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1915 | 1915 | | |
1916 | 1916 | | |
1917 | 1917 | | |
| 1918 | + | |
| 1919 | + | |
| 1920 | + | |
| 1921 | + | |
| 1922 | + | |
| 1923 | + | |
| 1924 | + | |
| 1925 | + | |
| 1926 | + | |
| 1927 | + | |
| 1928 | + | |
| 1929 | + | |
| 1930 | + | |
| 1931 | + | |
| 1932 | + | |
| 1933 | + | |
| 1934 | + | |
| 1935 | + | |
| 1936 | + | |
| 1937 | + | |
| 1938 | + | |
| 1939 | + | |
| 1940 | + | |
| 1941 | + | |
| 1942 | + | |
| 1943 | + | |
| 1944 | + | |
| 1945 | + | |
| 1946 | + | |
| 1947 | + | |
| 1948 | + | |
| 1949 | + | |
| 1950 | + | |
| 1951 | + | |
| 1952 | + | |
| 1953 | + | |
| 1954 | + | |
| 1955 | + | |
| 1956 | + | |
| 1957 | + | |
| 1958 | + | |
| 1959 | + | |
| 1960 | + | |
| 1961 | + | |
| 1962 | + | |
| 1963 | + | |
| 1964 | + | |
| 1965 | + | |
| 1966 | + | |
| 1967 | + | |
| 1968 | + | |
| 1969 | + | |
| 1970 | + | |
| 1971 | + | |
| 1972 | + | |
| 1973 | + | |
| 1974 | + | |
| 1975 | + | |
| 1976 | + | |
1918 | 1977 | | |
1919 | 1978 | | |
1920 | 1979 | | |
| |||
0 commit comments