Guard against OTA mismatch in NativeAnimatedHelper queue (#56802)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/56802

When MobileConfig flags (`cxxNativeAnimatedEnabled` and `useSharedAnimatedBackend`) are enabled server-side, `connectAnimatedNodeToShadowNodeFamily` is added to the method names list in `createNativeOperations()`. However, MobileConfig values and what is available in the AnimatedModule on the client can mismatch due to OTA updates — the JS bundle may have the flag enabled while the native module on the device does not yet implement the method. In this case, `nullthrows(NativeAnimatedModule)[methodName]` returns `undefined`, which gets queued as `() => undefined(...args)` and throws TypeError when the queue is flushed.

This fix adds a runtime check that `NativeAnimatedModule?.connectAnimatedNodeToShadowNodeFamily != null` before including the method in the list, preventing the mismatch from surfacing. The specific guard at the registration site is sufficient — if the method is not available on the native module, it will never be registered, so the general null guard in the method wrapper is unnecessary.

Fixes T270861607.

Changelog: [Internal]

Reviewed By: zeyap

Differential Revision: D104775294

fbshipit-source-id: ece86a3ab37792bf9624985eebfc53059af61677
This commit is contained in:
generatedunixname1608173377072046 authored and meta-codesync[bot] committed 2026-05-12 17:56:45 -07:00
1 parent 2991a97731
commit 1faa66551a
1 file changed
+2 -1
@@ -98,7 +98,8 @@ function createNativeOperations(): NonNullable<typeof NativeAnimatedModule> {
if (
ReactNativeFeatureFlags.cxxNativeAnimatedEnabled() &&
//eslint-disable-next-line
ReactNativeFeatureFlags.useSharedAnimatedBackend()
ReactNativeFeatureFlags.useSharedAnimatedBackend() &&
NativeAnimatedModule?.connectAnimatedNodeToShadowNodeFamily != null
) {
methodNames.push('connectAnimatedNodeToShadowNodeFamily');
}