Skip to content

Commit 30608d0

Browse files
MatiPl01tjzel
authored andcommitted
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.
1 parent 1d510ef commit 30608d0

File tree

2 files changed

+2
-8
lines changed

2 files changed

+2
-8
lines changed

packages/react-native-reanimated/src/hook/useDerivedValue.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,5 @@ export function useDerivedValue<Value>(
7373
};
7474
}, dependencies);
7575

76-
useEffect(() => {
77-
return () => {
78-
initRef.current = null;
79-
};
80-
}, []);
81-
8276
return sharedValue;
8377
}

packages/react-native-reanimated/src/logger/logger.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ export function updateLoggerConfig(options?: Partial<LoggerConfig>) {
110110
registerLoggerConfig({
111111
...__reanimatedLoggerConfig,
112112
// Don't reuse previous level and strict values from the global config
113-
level: options?.level ?? LogLevel.warn,
114-
strict: options?.strict ?? false,
113+
level: options?.level ?? DEFAULT_LOGGER_CONFIG.level,
114+
strict: options?.strict ?? DEFAULT_LOGGER_CONFIG.strict,
115115
});
116116
}
117117

0 commit comments

Comments
 (0)