Skip to content

fix(Reanimated): keep a stable shared value identity in the useSharedValue mock - #10920

Merged
tjzel merged 2 commits into
@pawicao/mock-shared-value-lazy-initfrom
@pawicao/mock-shared-value-stable-identity
Oct 26, 2026
Merged

tjzel merged 2 commits into
@pawicao/mock-shared-value-lazy-initfrom
@pawicao/mock-shared-value-stable-identity

Conversation

@pawicao

@pawicao pawicao commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator

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

  • 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.

@pawicao
pawicao added this pull request to stack #10921 October 19, 2026 14:49
@pawicao
pawicao requested a review from tjzel October 19, 2026 14:54
@pawicao
pawicao marked this pull request as ready for review October 19, 2026 14:54
@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Caution

Review failed

The pull request is closed.

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 024e6171-6f09-44a3-ae95-b9f56aafb1ca
Commits

Reviewing files that changed from the base of the PR and between 2087932 and 68cc4e1.

Files selected for processing: 1
  • packages/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; 8 remain after this review.

Walkthrough

The Jest mock of useSharedValue now creates its shared-value proxy with a lazy useState initializer and returns the stored proxy. The proxy retains its existing marker, value accessors, setter behavior, and support for assigning to value. A test checks that the returned object remains identical after a hook rerender. A changelog entry records the update.

Possibly related PRs

Priority: Not assessed

Change: Bug fix

Merge Risk: Minimal · up to 68cc4

The mock now keeps the same shared value across rerenders. No issue identified here prevents merging after normal checks.

Pre-merge checks: Passed 4
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: preserving stable shared value identity in the Reanimated Jest mock.
Description check Passed The description explains the identity bug, the implementation change, the test added, and the changelog update. It is directly related to the changeset.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

…k-shared-value-stable-identity

# Conflicts:
#	packages/react-native-reanimated/src/mock.ts
@tjzel
tjzel merged commit caa7882 into main Oct 26, 2026
24 of 25 checks passed
@tjzel
tjzel deleted the @pawicao/mock-shared-value-stable-identity branch October 26, 2026 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants