Repository navigation
fix(Reanimated): call lazy initializer in the useSharedValue mock - #10919
Conversation
|
Caution Review failedThe pull request is closed. Walkthrough
Priority: Change: Bug fix Pre-merge checks:
|
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
b41b1a04-abea-43a7-aa68-452dc38adcb9
📒 Files selected for processing: 3
packages/react-native-reanimated/__tests__/mock.useSharedValue.test.tsxpackages/react-native-reanimated/changelog/mock-shared-value-lazy-init.fix.mdpackages/react-native-reanimated/src/mock.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
…Value mock (#10920) > [!NOTE] > This pull request was authored by AI on behalf of @pawicao. ## Summary Stacked on #10919. The real `useSharedValue` keeps one shared value for the lifetime of the component. The Jest mock created a new object on every call, so the shared value changed identity on every render. Code that used it as a `useEffect` or `useMemo` dependency ran again on every render under the mock. I moved the mock shared value creation into the `useState` initializer, so each component keeps one shared value. ## Test plan I added a test to `__tests__/mock.useSharedValue.test.tsx` that re-renders the hook and compares the results. Before the fix it failed, after the fix it passes. The full reanimated Jest suite passes. ## Changelog - [x] I added a changelog fragment with `yarn changelog:add` for each changed package, or this PR does not change `react-native-reanimated` or `react-native-worklets`. Co-authored-by: Tomasz Żelawski <tzelawski@gmail.com>
Note
This pull request was authored by AI on behalf of @pawicao.
Summary
The real
useSharedValueaccepts a function as the initial value and calls it once on mount since 4.4.0. The Jest mock did not call the function. It stored the function as the value, souseSharedValue(() => 5).get()returned the function. I changed the mock to call the initializer wheninitis a function.Test plan
I added
__tests__/mock.useSharedValue.test.tsx. Before the fix it failed withExpected: 5, Received: [Function anonymous]. After the fix it passes.Changelog
yarn changelog:addfor each changed package, or this PR does not changereact-native-reanimatedorreact-native-worklets.