Skip to content

Conversation

@YevheniiKotyrlo
Copy link

Summary

Fixes React 19 compatibility issue and improves type safety in the web findNodeHandle utility.

Problem

React 19 Crash (#2366)

React 19 removed findHostInstance_DEPRECATED and changed when findNodeHandle can return null. With Expo SDK 53+ and React 19, the function crashes when componentOrHandle is null or undefined during component lifecycle transitions (mount/unmount).

Web Platform Crash (#2237)

On web, accessing componentOrHandle.getNativeScrollRef() or componentOrHandle._scrollRef without null checks can crash when the component is unmounted or during hot reload.

Type Safety

The existing code used @ts-ignore to access undocumented React Native scroll component internals, hiding potential type errors.

Solution

  1. Early null check - Return null immediately if componentOrHandle is nullish, preventing crashes in React 19

  2. Proper TypeScript interface - Replace @ts-ignore with a documented type bridge:

    interface ScrollComponentInternals {
      getNativeScrollRef?: () => NodeHandle | null;
      _scrollRef?: NodeHandle | null;
    }
  3. Runtime type checking - Use typeof scrollable.getNativeScrollRef === 'function' before calling, rather than relying on try/catch for flow control

  4. Explicit return type - Add proper return type annotation for better type inference

Related Issues

Testing

Tested with:

  • React 19 + Expo SDK 53
  • Web platform (React Native Web)
  • Hot reload scenarios

- Add early null check for componentOrHandle (React 19 fix)
- Replace @ts-ignore with proper TypeScript interface for scroll internals
- Add explicit return type annotation
- Use runtime type checking instead of relying on try/catch for flow control

Fixes gorhom#2366, gorhom#2237
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant