Repository navigation
Conversation
…p regardless of receiver name The rule was incorrectly checking variable names before analyzing the actual initializer, causing false positives when the useNavigation() result was renamed to something other than 'navigation'. The fix: 1. First checks if initialized from useNavigation() from @react-navigation/ (accepts regardless of variable name) 2. Recursively checks initializer chains 3. Falls back to name check only when there's no initializer (preserves support for navigation props) Fixes #1956 Co-authored-by: Skosh <skoshx@users.noreply.github.com>
commit: |
Co-authored-by: Skosh <skoshx@users.noreply.github.com>
Contributor
|
React Doctor found no new issues. 🎉 Reviewed by React Doctor for commit |
Contributor
Interactive terminal E2ETerminal Control verified the built CLI at
|
This branch has not been deployed
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 #1956 -
effect-needs-cleanupwas incorrectly checking variable names before analyzing initializers, causing false positives when theuseNavigation()result was renamed to something other thannavigation.Root Cause
The rule's
isKnownReactNavigationReceiverfunction checkedif (receiver.name === "navigation") return true;at the start, before checking if the receiver was initialized fromuseNavigation()from@react-navigation/. This caused two issues:navigationwere accepted without verifying they came from React NavigationuseNavigation()but renamed (e.g.,coveredNavigation) were rejectedSolution
Reordered the checks to:
useNavigation()from@react-navigation/(accepts regardless of variable name)navigationprops, a common React Navigation pattern)Testing
effect-needs-cleanup-issue-1956.test.tscovering:useNavigation()useNavigation()navigationeffect-needs-cleanup.test.tsValidation
Tested with the exact reproduction case from #1956:
$ node packages/react-doctor/bin/react-doctor.js test.tsx --verbose --no-score ✔ No issues found!Before fix: reported 1 false positive on line 13 (renamed receiver)
After fix: no issues (correct)
Scope
This is a targeted fix that only affects React Navigation
addListenercleanup detection. The change:useNavigation()result is renamednavigationprops (common pattern)The fix only reorders existing checks - no new logic added, making it safe and minimal.
Closes #1956