Skip to content

Crash in valueSetter: animation.onStart is undefined (useDerivedValue) #8974

@manticarodrigo

Description

@manticarodrigo

Description

We're seeing a crash in production that traces back to valueSetter.ts line 42, where animation.onStart(...) is called without checking that onStart actually exists on the animation object.

The guard on lines 16-21 checks for value.onFrame !== undefined, but never checks onStart. So if an object enters the animation path that has onFrame but is missing onStart, it blows up with "undefined is not a function".

From our Sentry data this is happening inside the useDerivedValue mapper path — the minified stack looks like:

initializeAnimation → valueSetter → set value → useDerivedValue updater → mapperRun

It's not tied to any specific screen or component. We see it across the whole app, on all iOS versions (18.x through 26.x), all device models.

We've been on 4.1.6 and I checked the source in 4.2.0 and 4.2.1 as well — valueSetter.ts is identical in all three, so the bug is still present.

The bug

In src/valueSetter.ts:

// line 16-21: guard only checks onFrame
if (
  typeof value === 'function' ||
  (value !== null &&
    typeof value === 'object' &&
    (value as unknown as AnimationObject).onFrame !== undefined)
) {
  // ...
  // line 42: calls onStart without checking it exists
  const initializeAnimation = (timestamp: number) => {
    animation.onStart(animation, mutable.value, timestamp, previousAnimation);
  };

If onFrame is defined but onStart is not, the code enters the animation branch and then crashes on animation.onStart(...).

Suggested fix

Add a guard before calling initializeAnimation:

if (!animation.onStart || !animation.onFrame) {
  mutable._value = animation.current ?? value;
  return;
}

const initializeAnimation = (timestamp: number) => {
  animation.onStart(animation, mutable.value, timestamp, previousAnimation);
};

Or at minimum, check onStart alongside onFrame in the initial guard on line 16-21.

Steps to reproduce

Hard to give a minimal repro since it happens intermittently in production across many screens. The common thread is useDerivedValue returning objects that end up triggering the animation code path. We've confirmed it's not specific to any particular derived value — it happens app-wide.

Snack or a link to a repository

N/A — production-only crash, but the bug is clearly visible in the source.

Reanimated version

4.1.6 (also verified source is identical in 4.2.0, 4.2.1)

React Native version

0.79.2

Platforms

iOS

JavaScript runtime

Hermes

Workflow

Expo

Architecture

New Architecture (Fabric)

Build type

Release

Device

Real device (all models)

Device model

All — iPhone 12 through 16 Pro Max

Acknowledgements

  • I searched for similar issues in the repository and found none that match
  • I understand that the team needs a minimal reproducible scenario

Metadata

Metadata

Assignees

No one assigned

    Labels

    Missing reproThis issue need minimum repro scenarioPlatform: iOSThis issue is specific to iOS

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions