-
Notifications
You must be signed in to change notification settings - Fork 532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix infinite loop issue due to incorrect dependencies in SearchByMultipleFields #9970
Fix infinite loop issue due to incorrect dependencies in SearchByMultipleFields #9970
Conversation
WalkthroughThe pull request focuses on optimizing the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
✅ Deploy Preview for care-ohc ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Deploying care-fe with Cloudflare Pages
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/components/Common/SearchByMultipleFields.tsx
(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: OSSAR-Scan
- GitHub Check: cypress-run (1)
- GitHub Check: CodeQL-Build
- GitHub Check: OSSAR-Scan
🔇 Additional comments (1)
src/components/Common/SearchByMultipleFields.tsx (1)
92-92
: LGTM: Optimized clearSearch dependency.The change to use
clearSearch?.value
as the dependency is a valid optimization that prevents unnecessary effect runs when other properties of the clearSearch object change.
@@ -160,7 +160,7 @@ const SearchByMultipleFields: React.FC<SearchByMultipleFieldsProps> = ({ | |||
if (selectedOption.value !== searchValue) { | |||
onSearch(selectedOption.key, searchValue); | |||
} | |||
}, [searchValue, selectedOption.key, selectedOption.value, onSearch]); | |||
}, [searchValue]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential stale closure and missed updates in search effect.
The current dependency array [searchValue]
is incomplete and could lead to bugs:
- The effect uses
selectedOption.value
in its condition but doesn't include it in dependencies - Removed
selectedOption.key
could cause stale key being used inonSearch
- Removed
onSearch
from deps could hide stale closure issues
Apply this fix to ensure all used values are properly tracked:
useEffect(() => {
if (selectedOption.value !== searchValue) {
onSearch(selectedOption.key, searchValue);
}
- }, [searchValue]);
+ }, [searchValue, selectedOption.value, selectedOption.key, onSearch]);
This ensures:
- Changes to the selected option are properly detected
- The correct search key is always used
- No stale closures of the onSearch callback
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
}, [searchValue]); | |
}, [searchValue, selectedOption.value, selectedOption.key, onSearch]); |
@rithviknishad Your efforts have helped advance digital healthcare and TeleICU systems. 🚀 Thank you for taking the time out to make CARE better. We hope you continue to innovate and contribute; your impact is immense! 🙌 |
Proposed Changes
@ohcnetwork/care-fe-code-reviewers
Merge Checklist
Summary by CodeRabbit