-
Notifications
You must be signed in to change notification settings - Fork 2.9k
[WEB-5429] refactor: conditional hooks #8114
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
Conversation
|
Linked to Plane Work Item(s) This comment was auto-generated by Plane |
WalkthroughThis PR introduces a useSWR hooks usage analysis report and systematically refactors work-item filter initialization across empty state components. The changes move undefined-checks from component call sites into the Changes
Sequence DiagramsequenceDiagram
participant Comp as Empty State Component
participant Hook as useWorkItemFilterInstance
participant Filter as Filter Store
rect rgba(100, 150, 200, 0.3)
Note over Comp,Filter: Before: Conditional Hook Invocation
alt ID exists
Comp->>Hook: call hook(id)
Hook->>Filter: getFilter(id)
Filter-->>Hook: filter instance
Hook-->>Comp: filter instance
else ID undefined
Note over Comp: skip hook call
Comp->>Comp: filterInstance = undefined
end
end
rect rgba(100, 150, 200, 0.3)
Note over Comp,Filter: After: Unconditional Hook Invocation
Comp->>Hook: call hook(id or undefined)
alt ID exists
Hook->>Filter: getFilter(id)
Filter-->>Hook: filter instance
else ID undefined
Hook->>Hook: early return undefined
end
Hook-->>Comp: filter instance or undefined
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (7)
🧰 Additional context used🧠 Learnings (4)📚 Learning: 2025-06-16T07:23:39.497ZApplied to files:
📚 Learning: 2025-07-08T13:41:01.659ZApplied to files:
📚 Learning: 2025-06-18T09:46:08.566ZApplied to files:
📚 Learning: 2025-10-21T17:22:05.204ZApplied to files:
🧬 Code graph analysis (6)apps/web/core/components/issues/issue-layouts/empty-states/project-issues.tsx (1)
apps/web/core/hooks/store/work-item-filters/use-work-item-filter-instance.ts (2)
apps/web/core/components/issues/issue-layouts/empty-states/module.tsx (2)
apps/web/core/components/issues/issue-layouts/calendar/base-calendar-root.tsx (1)
apps/web/core/components/issues/issue-layouts/empty-states/archived-issues.tsx (1)
apps/web/core/components/issues/issue-layouts/empty-states/cycle.tsx (2)
🪛 LanguageToolCONDITIONAL_USESWR_REPORT.md[uncategorized] ~202-~202: The official name of this software platform is spelled with a capital “H”. (GITHUB) [uncategorized] ~203-~203: The official name of this software platform is spelled with a capital “H”. (GITHUB) [uncategorized] ~207-~207: The official name of this software platform is spelled with a capital “H”. (GITHUB) [uncategorized] ~208-~208: The official name of this software platform is spelled with a capital “H”. (GITHUB) [grammar] ~236-~236: Ensure spelling is correct (QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1) [grammar] ~291-~291: Ensure spelling is correct (QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1) ⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
🔇 Additional comments (7)
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.
Pull Request Overview
This PR refactors the handling of conditional hooks to improve adherence to React's Rules of Hooks. The main change is moving conditional logic from call sites into the useWorkItemFilterInstance hook itself, allowing it to be called unconditionally while still handling undefined entity IDs gracefully.
- Modified
useWorkItemFilterInstanceto acceptstring | undefinedfor entityId and returnundefinedwhen entityId is falsy - Updated four call sites to remove conditional hook invocations (project-issues, module, cycle, archived-issues)
- Extracted conditional hook logic in calendar component to avoid calling hooks conditionally
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| apps/web/core/hooks/store/work-item-filters/use-work-item-filter-instance.ts | Updated hook signature to accept string | undefined and return undefined when entityId is falsy |
| apps/web/core/components/issues/issue-layouts/empty-states/project-issues.tsx | Removed conditional ternary, now calls hook unconditionally |
| apps/web/core/components/issues/issue-layouts/empty-states/module.tsx | Removed conditional ternary, now calls hook unconditionally |
| apps/web/core/components/issues/issue-layouts/empty-states/cycle.tsx | Removed conditional ternary, now calls hook unconditionally |
| apps/web/core/components/issues/issue-layouts/empty-states/archived-issues.tsx | Removed conditional ternary spanning multiple lines, now calls hook unconditionally |
| apps/web/core/components/issues/issue-layouts/calendar/base-calendar-root.tsx | Extracted useIssueStoreType call to avoid conditionally invoking hooks |
| CONDITIONAL_USESWR_REPORT.md | Added comprehensive documentation analyzing conditional useSWR patterns in the codebase |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Description
This PR refactors instances where hooks are initialized conditionally.
Type of Change
Summary by CodeRabbit
Refactor
Chores