Fix rules-of-hooks violation in getFilePicker#10370
Conversation
…ith a regular variable
📝 WalkthroughWalkthroughThis PR fixes a React rules-of-hooks violation in the ChangesHook violation fix in getFilePicker
Possibly related issues:
🚥 Pre-merge checks | ✅ 6✅ Passed checks (6 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
features/admin.connections.v1/components/edit/forms/helpers/form-fields-helper.tsx (1)
593-596:⚠️ Potential issue | 🔴 Critical | ⚡ Quick winCritical bug: callback ignores
newDataand passes stale value.The
onCertificateChangecallback receivesnewDataas its parameter but ignores it, passing the staledataconstant instead. Sincedatais derived once from the initialeachProp?.value, it will always contain the original certificate value, not the newly selected one. This breaks the certificate change notification flow.🐛 Proposed fix
<Pkcs12FileField onCertificateChange={ (newData: string) => { - onCertificateChange(data); + onCertificateChange(newData); } } />🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@features/admin.connections.v1/components/edit/forms/helpers/form-fields-helper.tsx` around lines 593 - 596, The callback passed to the onCertificateChange prop is using the stale local variable `data` instead of the new value parameter `newData`, so update the JSX handler (the anonymous arrow passed to onCertificateChange) to forward `newData` to the parent handler (call onCertificateChange(newData) instead of onCertificateChange(data)); locate the occurrence in the form-fields helper where onCertificateChange is assigned and replace the argument accordingly so the new certificate value is propagated.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In
`@features/admin.connections.v1/components/edit/forms/helpers/form-fields-helper.tsx`:
- Around line 593-596: The callback passed to the onCertificateChange prop is
using the stale local variable `data` instead of the new value parameter
`newData`, so update the JSX handler (the anonymous arrow passed to
onCertificateChange) to forward `newData` to the parent handler (call
onCertificateChange(newData) instead of onCertificateChange(data)); locate the
occurrence in the form-fields helper where onCertificateChange is assigned and
replace the argument accordingly so the new certificate value is propagated.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: eab31155-fafe-40ea-8ec7-68686f062374
📒 Files selected for processing (2)
.changeset/solid-pigs-laugh.mdfeatures/admin.connections.v1/components/edit/forms/helpers/form-fields-helper.tsx
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #10370 +/- ##
=======================================
Coverage 98.79% 98.79%
=======================================
Files 165 165
Lines 51763 51764 +1
Branches 165 165
=======================================
+ Hits 51137 51138 +1
Misses 626 626
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Were you able to validate this fix?
This component seems to be used when submitting the certificate while editing IDP settings. Since the onCertificateChange method no longer updates the data variable with the changes in this PR, this could cause issues when the certificate is submitted.
PS: just noticed coderabbit has also pointed this out. see #10370 (review)
Hi @pavinduLakshan, you're right, removing I think the cleanest fix would be to convert |
please see the suggested solution in the bot comment. any reason why we can't proceed with just that? |
Got it! I'll proceed with CodeRabbit's suggested fix and update |
|
Hi @pavinduLakshan, I've addressed the earlier feedback. Happy to make any further changes if needed...thanks! |
Thanks, could you please add a screen recording of the functionality of the certificate picker to the PR description as well? |
|
Hi @pavinduLakshan, I've updated the PR description with a screen recording demonstrating the Private Key field (certificate picker) in the Google Outbound Provisioning connector. The value updates correctly after save and page reload. |
Purpose
Fixes the react-hooks/rules-of-hooks ESLint violation in getFilePicker function inside form-fields-helper.tsx by replacing the useState hook with a plain variable.
Related Issues
useStateis called in functiongetFilePickerthat is neither a... (1 occurrence) product-is#27958Related PRs
Checklist
Security checks
Developer Checklist (Mandatory)
product-isissue to track any behavioral change or migration impact.Screen.Recording.mov