fix(web): React 19 compatibility and type safety for findNodeHandle#2595
Open
YevheniiKotyrlo wants to merge 1 commit intogorhom:masterfrom
Open
fix(web): React 19 compatibility and type safety for findNodeHandle#2595YevheniiKotyrlo wants to merge 1 commit intogorhom:masterfrom
YevheniiKotyrlo wants to merge 1 commit intogorhom:masterfrom
Conversation
- 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
|
This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 10 days. |
Author
|
up |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: