-
Notifications
You must be signed in to change notification settings - Fork 13.1k
fix: resolve react-hooks/exhaustive-deps violations in admin settings components #38466
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
base: develop
Are you sure you want to change the base?
fix: resolve react-hooks/exhaustive-deps violations in admin settings components #38466
Conversation
…ents - Add useMemo to extract editor value from setting to avoid type-cast in dependency array - Update useEffect to properly track editorValue dependency - Update onResetButtonClick callback with correct dependencies - Remove eslint-disable react-hooks/exhaustive-deps comments This fixes exhaustive-deps violations in: - apps/meteor/client/views/admin/settings/Setting/Setting.tsx (lines 73, 99) - apps/meteor/client/views/admin/ABAC/ABACSettingTab/SettingField.tsx (lines 66, 92) The root cause was using type-cast (setting as ISettingColor).editor directly in dependency arrays, which React couldn't properly track. Using useMemo ensures React can correctly detect when the editor value changes and re-run effects.
|
Looks like this PR is not ready to merge, because of the following issues:
Please fix the issues and try again If you have any trouble, please check the PR guidelines |
|
WalkthroughTwo admin settings components extract a color-setting editor into a memoized value and replace inline type-casts in hook dependency arrays with that memoized value, preserving behavior while fixing react-hooks/exhaustive-deps issues. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@apps/meteor/client/views/admin/ABAC/ABACSettingTab/SettingField.tsx`:
- Around line 60-63: Remove the inline comment above the useMemo in
SettingField.tsx: delete the line "// Memoize editor value extraction to avoid
type-cast in dependency array" and keep the useMemo implementation as-is (the
code using useMemo(() => isSettingColor(setting) ? setting.editor : undefined,
[setting]) with functions isSettingColor and variable setting unchanged).
In `@apps/meteor/client/views/admin/settings/Setting/Setting.tsx`:
- Around line 67-70: Remove the inline implementation comment above the
memoization; keep the logic as-is. Specifically, in the useMemo block that
computes editorValue (using isSettingColor(setting) ? setting.editor :
undefined) simply delete the comment "// Memoize editor value extraction to
avoid type-cast in dependency array" and leave the useMemo, editorValue,
isSettingColor, and setting code unchanged.
apps/meteor/client/views/admin/ABAC/ABACSettingTab/SettingField.tsx
Outdated
Show resolved
Hide resolved
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.
No issues found across 2 files
Address CodeRabbit review feedback to remove inline comments from implementation files as per project coding guidelines.
TypeScript CI was failing due to unused import after removing type-casts. Removed ISettingColor from both Setting.tsx and SettingField.tsx imports.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #38466 +/- ##
===========================================
+ Coverage 70.43% 70.45% +0.01%
===========================================
Files 3161 3162 +1
Lines 110151 110343 +192
Branches 19872 19893 +21
===========================================
+ Hits 77588 77744 +156
- Misses 30532 30573 +41
+ Partials 2031 2026 -5
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
fixes: #38465 Fix react-hooks/exhaustive-deps violations in admin settings components
This PR fixes
react-hooks/exhaustive-depsviolations in two admin settings components by removing suppressed lint rules and properly tracking hook dependencies.The issue was caused by type-cast expressions used directly in dependency arrays, which the hooks linter cannot statically analyze. As a result,
eslint-disable react-hooks/exhaustive-depswas used instead of addressing the root cause.What was changed
eslint-disable react-hooks/exhaustive-depscomments in the affected filesuseMemoto safely derive and memoize theeditorvalue fromsettinguseEffectanduseCallbackdependency arrays to rely on stable, lint-trackable valuesFiles modified
apps/meteor/client/views/admin/settings/Setting/Setting.tsxapps/meteor/client/views/admin/ABAC/ABACSettingTab/SettingField.tsxWhy this approach
useMemois the recommended pattern for derived state used by hooksTesting
SettingField.tsxpassreact-hooks/exhaustive-depswarnings in the modified filesManual verification performed:
Scope
Summary by CodeRabbit