You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: Invalid shared value access displaying when code is correct (#6631)
## Summary
The problem was caused by our `useDerivedValue` hook which set ref to
`null` in the `useEffect` cleanup method.
```tsx
useEffect(() => {
return () => {
initRef.current = null;
};
}, []);
```
The warning was shown during hot reload, because react calls cleanup
functions in hooks, thus the `initRef` was reset in the
`useDerivedValue` hook, which resulted in execution of this code that
should run only when the component mounts for the first time:
```tsx
if (initRef.current === null) {
initRef.current = makeMutable(initialUpdaterRun(updater));
}
```
Because of that, `initialUpdaterRun` executed the `updater` callback on
the JS thread during hot reload, while the component was rendered, which
resulted in reading shared value's `.value` property during the render
phase.
0 commit comments