Commit 39c6545
authored
Fix indices of hooks in devtools when using useSyncExternalStore (#34547)
## Summary
This PR updates getChangedHooksIndices to account for the fact that
useSyncExternalStore internally mounts two hooks, while DevTools should
treat it as a single user-facing hook.
It introduces a helper isUseSyncExternalStoreHook to detect this case
and adjust iteration so the extra internal hook is skipped when counting
changes.
Before:
https://github.com/user-attachments/assets/0db72a4e-21f7-44c7-ba02-669a272631e5
After:
https://github.com/user-attachments/assets/4da71392-0396-408d-86a7-6fbc82d8c4f5
## How did you test this change?
I used this component to reproduce this issue locally (I followed
instructions in `packages/react-devtools/CONTRIBUTING.md`).
```ts
function Test() {
// 1
React.useSyncExternalStore(
() => {},
() => {},
() => {},
);
// 2
const [state, setState] = useState('test');
return (
<>
<div
onClick={() => setState(Math.random())}
style={{backgroundColor: 'red'}}>
{state}
</div>
</>
);
}
```1 parent 613cf80 commit 39c6545
File tree
1 file changed
+23
-6
lines changed1 file changed
+23
-6
lines changedLines changed: 23 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1913 | 1913 | | |
1914 | 1914 | | |
1915 | 1915 | | |
| 1916 | + | |
| 1917 | + | |
| 1918 | + | |
| 1919 | + | |
| 1920 | + | |
| 1921 | + | |
| 1922 | + | |
| 1923 | + | |
| 1924 | + | |
| 1925 | + | |
| 1926 | + | |
| 1927 | + | |
| 1928 | + | |
| 1929 | + | |
1916 | 1930 | | |
1917 | 1931 | | |
1918 | 1932 | | |
| |||
1929 | 1943 | | |
1930 | 1944 | | |
1931 | 1945 | | |
1932 | | - | |
1933 | | - | |
1934 | | - | |
1935 | | - | |
1936 | | - | |
1937 | | - | |
| 1946 | + | |
1938 | 1947 | | |
1939 | 1948 | | |
1940 | 1949 | | |
| |||
1955 | 1964 | | |
1956 | 1965 | | |
1957 | 1966 | | |
| 1967 | + | |
1958 | 1968 | | |
1959 | 1969 | | |
1960 | 1970 | | |
1961 | 1971 | | |
| 1972 | + | |
| 1973 | + | |
| 1974 | + | |
| 1975 | + | |
| 1976 | + | |
| 1977 | + | |
| 1978 | + | |
1962 | 1979 | | |
1963 | 1980 | | |
1964 | 1981 | | |
| |||
0 commit comments