Skip to content

Fix TextInput isFocused false positive on stale refs after unmount#55570

Closed
chicio wants to merge 2 commits intofacebook:mainfrom
chicio:fix_isfocused_unmount_never_focus
Closed

Fix TextInput isFocused false positive on stale refs after unmount#55570
chicio wants to merge 2 commits intofacebook:mainfrom
chicio:fix_isfocused_unmount_never_focus

Conversation

@chicio
Copy link
Contributor

@chicio chicio commented Feb 17, 2026

Summary:

This PR fixes a false positive in in the TextInput component in the isFocused method.

Before the modification I made in this PR, the isFocused was (wrongly) returning true if both TextInputState.currentlyFocusedInput() and inputRef.current (in TextInput) were null. This can happen eg. when a TextInput is never focused and a stale ref is checked after unmount.

This fix adds an explicit not null check for TextInputState.currentlyFocusedInput(). I also added some tests to cover the unmount scenarios, including:

  • unmounted after being focused
  • unmounted and never focused (demonstrating the issue described above and in the TODO I removed)

Changelog:

[GENERAL] [FIXED] - Fixed isFocused false positive

Test Plan:

  • Ran TextInput-itest.js fantom test and verify all tests cases passed (yarn fantom TextInput-itest)
    • Added additional tests to simulate false positives and missing scenarios (all connected to unmount)
  • Ran the full React Native test suite to ensure all tests pass.

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 17, 2026
@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Feb 17, 2026
@meta-codesync
Copy link

meta-codesync bot commented Feb 23, 2026

@NickGerleman has imported this pull request. If you are a Meta employee, you can view this in D94076114.

@chicio
Copy link
Contributor Author

chicio commented Feb 23, 2026

Hi @NickGerleman , thank you so much for importing my PR! 🙏
Let me know if I have to do anything else for this one.

@meta-codesync meta-codesync bot closed this in 42cd0f0 Feb 23, 2026
@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @chicio in 42cd0f0

When will my fix make it into a release? | How to file a pick request?

@react-native-bot react-native-bot added the Merged This PR has been merged. label Feb 23, 2026
@meta-codesync
Copy link

meta-codesync bot commented Feb 23, 2026

@NickGerleman merged this pull request in 42cd0f0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants