fix: move hook calls before early returns to comply with Rules of Hooks#76
fix: move hook calls before early returns to comply with Rules of Hooks#76g-k-s-03 wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (5)
WalkthroughAcross five page components ( ChangesRules of Hooks guard relocation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4✅ 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 |
|
Hey @Zahnentferner and @rahul-vyas-dev, requesting a review on this PR. This fixes the Rules of Hooks violations across all 5 affected page |
Addressed Issues:
Fixes #75
changes
Verified via grep on current main that all hooks appear before
their respective guards after the fix:
Production build: 1214 modules transformed, zero errors.
5 files changed, 22 insertions(+), 20 deletions(-)
What was wrong
Five page components were calling React hooks after an early
if (!model) return nullguard. React requires hooks to be calledunconditionally on every render in the same order. When the app first
loads, model is null so the component exits early, and those hooks are
skipped. Once data loads, model gets a value, and those hooks suddenly
run React detects the mismatch and throws:
Rendered more hooks than during the previous render.
This causes a crash in development and undefined behavior in production.
What was changed
Moved all hook calls above the guard in each of the five files.
Used optional chaining to handle null model safely in hooks that
previously depended on model data:
changed
model.allRepostomodel?.allRepos ?? []above guard; changed
model.contributorstomodel?.contributors ?? []Non-hook variable assignments that reference model directly were left
after the guard where they are safe.
Why ESLint did not catch this
The react-hooks/rules-of-hooks ESLint rule would normally flag this
automatically, but eslint.config.js currently targets *.{ts,tsx} while
all source files are .jsx/.js so linting never ran on these files.
Summary by CodeRabbit
Note: This release contains internal code improvements with no changes to user-facing functionality or features.