Commit 657d8a4
committed
Use double render to detect render phase mutation
PR facebook#20665 added a mechanism to detect when a useMutableSource source is
mutated during the render phase. It relies on the fact that we double
render components during development in Strict Mode. If the version
in the double render doesn't match the first, that indicates there must
have been a mutation during render.
However, I realized during review that is true of all errors that occur
during the double render. A pure component will never throw during the
double render, because if it were pure, it would have also thrown during
the first render... in which case it wouldn't have double rendered!
So instead of tracking and comparing the source's version, we can
instead check if we're inside a double render when the error is thrown.
We probably shouldn't be throwing during the double render at all, since
we know it won't happen in production. (It's still a tearing bug, but
that doesn't mean the component will actually throw.)
I considered suppressing the error entirely, but that requires a larger
conversation about how to handle errors that we know are only possible
in development. I think we should probably be suppressing *all* errors
(with a warning) that occur during a double render.1 parent eab1bee commit 657d8a4
4 files changed
Lines changed: 83 additions & 67 deletions
File tree
- packages/react-reconciler/src
- __tests__
- scripts/error-codes
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
904 | 904 | | |
905 | 905 | | |
906 | 906 | | |
907 | | - | |
908 | | - | |
909 | | - | |
910 | | - | |
911 | | - | |
912 | | - | |
913 | | - | |
914 | | - | |
915 | | - | |
916 | | - | |
917 | | - | |
918 | | - | |
919 | 907 | | |
920 | 908 | | |
921 | 909 | | |
| |||
978 | 966 | | |
979 | 967 | | |
980 | 968 | | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
981 | 980 | | |
982 | | - | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
983 | 994 | | |
984 | | - | |
985 | | - | |
986 | | - | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
987 | 1000 | | |
988 | 1001 | | |
989 | 1002 | | |
990 | 1003 | | |
991 | 1004 | | |
| 1005 | + | |
| 1006 | + | |
992 | 1007 | | |
993 | 1008 | | |
994 | 1009 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
885 | 885 | | |
886 | 886 | | |
887 | 887 | | |
888 | | - | |
889 | | - | |
890 | | - | |
891 | | - | |
892 | | - | |
893 | | - | |
894 | | - | |
895 | | - | |
896 | | - | |
897 | | - | |
898 | | - | |
899 | | - | |
900 | 888 | | |
901 | 889 | | |
902 | 890 | | |
| |||
959 | 947 | | |
960 | 948 | | |
961 | 949 | | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
962 | 961 | | |
963 | | - | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
964 | 975 | | |
965 | | - | |
966 | | - | |
967 | | - | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
968 | 981 | | |
969 | 982 | | |
970 | 983 | | |
971 | 984 | | |
972 | 985 | | |
| 986 | + | |
| 987 | + | |
973 | 988 | | |
974 | 989 | | |
975 | 990 | | |
| |||
Lines changed: 19 additions & 33 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1744 | 1744 | | |
1745 | 1745 | | |
1746 | 1746 | | |
1747 | | - | |
1748 | | - | |
1749 | | - | |
1750 | | - | |
1751 | | - | |
1752 | | - | |
1753 | | - | |
1754 | | - | |
1755 | | - | |
1756 | | - | |
1757 | | - | |
1758 | | - | |
1759 | | - | |
1760 | | - | |
1761 | | - | |
1762 | | - | |
1763 | | - | |
1764 | | - | |
| 1747 | + | |
| 1748 | + | |
| 1749 | + | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
1765 | 1755 | | |
1766 | 1756 | | |
1767 | 1757 | | |
| |||
1792 | 1782 | | |
1793 | 1783 | | |
1794 | 1784 | | |
1795 | | - | |
1796 | | - | |
1797 | | - | |
1798 | | - | |
1799 | | - | |
1800 | | - | |
1801 | | - | |
1802 | | - | |
1803 | | - | |
1804 | | - | |
1805 | | - | |
1806 | | - | |
1807 | | - | |
1808 | | - | |
1809 | | - | |
| 1785 | + | |
| 1786 | + | |
| 1787 | + | |
| 1788 | + | |
| 1789 | + | |
| 1790 | + | |
| 1791 | + | |
| 1792 | + | |
| 1793 | + | |
| 1794 | + | |
| 1795 | + | |
1810 | 1796 | | |
1811 | 1797 | | |
1812 | 1798 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
339 | 339 | | |
340 | 340 | | |
341 | 341 | | |
342 | | - | |
| 342 | + | |
343 | 343 | | |
344 | 344 | | |
345 | 345 | | |
| |||
373 | 373 | | |
374 | 374 | | |
375 | 375 | | |
376 | | - | |
| 376 | + | |
377 | 377 | | |
0 commit comments