Skip to content

Avoid exception-based nativeID parsing#9966

Draft
zxrl wants to merge 1 commit into
software-mansion:mainfrom
zxrl:fix/native-id-parsing
Draft

Avoid exception-based nativeID parsing#9966
zxrl wants to merge 1 commit into
software-mansion:mainfrom
zxrl:fix/native-id-parsing

Conversation

@zxrl

@zxrl zxrl commented Jul 15, 2026

Copy link
Copy Markdown

Summary

Follow-up to #7163.

React Native exposes nativeID as a string and uses non-numeric values internally. The legacy layout animation proxy currently parses every non-empty nativeID with stoi and relies on exceptions to reject unrelated IDs. In iOS applications whose native link graph contains code compiled with -fno-exceptions, that invalid parse can terminate the process instead of reaching the catch block.

This change moves nativeID parsing into LayoutAnimationsProxyCommon and uses the existing non-throwing digit validation from the experimental proxy. Both layout animation proxies now share one parser, non-numeric IDs are ignored, and numeric Reanimated IDs continue transferring their animation configuration.

Test plan

Formatting and common C++ validation:

clang-format --dry-run --Werror \
  packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxyCommon.{cpp,h} \
  packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Experimental.{cpp,h} \
  packages/react-native-reanimated/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Legacy.{cpp,h}

cd packages/react-native-reanimated
../../scripts/validate-common.sh

Physical iOS reproduction uses React Native 0.86, Fabric, Hermes, and a native dependency graph containing -fno-exceptions. Mounting a view with a non-numeric nativeID while Reanimated processes layout insertions previously aborted in LayoutAnimationsProxy_Legacy::transferConfigFromNativeID through std::__1::stoi.

Minimal affected view:

import Animated, { FadeIn } from 'react-native-reanimated';

export default function App() {
  return <Animated.View entering={FadeIn} nativeID="profile-avatar" />;
}

After this change, the non-numeric ID is ignored without throwing. Numeric IDs still reach LayoutAnimationsManager::transferConfigFromNativeID.

@bartlomiejbloniarz

Copy link
Copy Markdown
Member

Good catch, I forgot to backport it to Legacy! Why is it a draft still? Do you intend to do more changes?

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