Skip to content

fix(Reanimated): return full shared values from makeMutable, useScrollOffset and useTimestamp mocks - #11024

Merged
tjzel merged 2 commits into
mainfrom
@tjzel/fix/mock-shared-value-factory
Oct 28, 2026
Merged

tjzel merged 2 commits into
mainfrom
@tjzel/fix/mock-shared-value-factory

Conversation

@tjzel

@tjzel tjzel commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

Note

This pull request was authored by AI on behalf of @tjzel.

Summary

Follow-up to #11003, #10919 and #10920.

The Jest mocks of makeMutable, useScrollOffset, useScrollViewOffset and useTimestamp returned plain values instead of shared values. isSharedValue(makeMutable(0)) was false, and code that called addListener on a scroll offset or a timestamp crashed under the mock.

I moved the useSharedValue Proxy into a createMockSharedValue factory and used it in all of these mocks. useScrollOffset and useTimestamp keep one shared value per component with useState, like useSharedValue, and useScrollOffset returns the provided offset when one is passed, like the real hook.

Test plan

yarn workspace react-native-reanimated jest mock.sharedValueFactories runs the new tests, which fail without the change and pass with it.

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.

@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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: d36e9de6-d722-4c0a-80d4-449f2ced53a8
Commits

Reviewing files that changed from the base of the PR and between ceefd82 and 23262f7.

Files selected for processing: 2
  • packages/react-native-reanimated/__tests__/mock.sharedValueFactories.test.tsx
  • packages/react-native-reanimated/src/mock.ts
Files skipped from review as they are similar to previous changes: 2
  • packages/react-native-reanimated/src/mock.ts
  • packages/react-native-reanimated/tests/mock.sharedValueFactories.test.tsx

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 mocks now use a shared helper to create values with value, get, set, modify, listener methods, and a shared-value marker. Scroll-offset hooks, useSharedValue, useTimestamp, and makeMutable use these mock values. Tests check mutation, listener operations, stability across rerenders, and preservation of a supplied scroll offset.

Possibly related issues

  • software-mansion/react-native-reanimated#11002 — This issue reports that subscribing to a mocked shared value fails when addListener is missing. This change adds no-op listener methods to mock values created by the affected factories.

Possibly related PRs

Priority: Normal

Change: Bug fix

Merge Risk: Minimal · up to 23262

The reviewed mock behavior matches the checked shared-value and scroll-offset contracts; no issue identified here blocks merging.

Pre-merge checks: Passed 4
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: updating Reanimated Jest mocks to return full shared values for the affected APIs.
Description check Passed The description directly explains the mock behavior change, affected APIs, implementation approach, tests, and changelog update.
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.

Comment thread packages/react-native-reanimated/src/mock.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


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: 6776e1be-c4e7-46fb-af99-2d082d611d88
Commits

Reviewing files that changed from the base of the PR and between caa7882 and ceefd82.

Files selected for processing: 3
  • packages/react-native-reanimated/__tests__/mock.sharedValueFactories.test.tsx
  • packages/react-native-reanimated/changelog/mock-shared-value-factories.fix.md
  • 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.

Comment thread packages/react-native-reanimated/src/mock.ts Outdated
@tjzel
tjzel merged commit 7a3d73a into main Oct 28, 2026
32 checks passed
@tjzel
tjzel deleted the @tjzel/fix/mock-shared-value-factory branch October 28, 2026 13:23
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.

3 participants