fix(web): React 19 compatibility and type safety for findNodeHandle #2595
+31
−10
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes React 19 compatibility issue and improves type safety in the web
findNodeHandleutility.Problem
React 19 Crash (#2366)
React 19 removed
findHostInstance_DEPRECATEDand changed whenfindNodeHandlecan returnnull. With Expo SDK 53+ and React 19, the function crashes whencomponentOrHandleisnullorundefinedduring component lifecycle transitions (mount/unmount).Web Platform Crash (#2237)
On web, accessing
componentOrHandle.getNativeScrollRef()orcomponentOrHandle._scrollRefwithout null checks can crash when the component is unmounted or during hot reload.Type Safety
The existing code used
@ts-ignoreto access undocumented React Native scroll component internals, hiding potential type errors.Solution
Early null check - Return
nullimmediately ifcomponentOrHandleis nullish, preventing crashes in React 19Proper TypeScript interface - Replace
@ts-ignorewith a documented type bridge:Runtime type checking - Use
typeof scrollable.getNativeScrollRef === 'function'before calling, rather than relying on try/catch for flow controlExplicit return type - Add proper return type annotation for better type inference
Related Issues
Testing
Tested with: