Skip to content

fix: 修复空分类场景白屏(Hook 调用顺序问题)#46

Merged
AmintaCCCP merged 1 commit intomainfrom
fix/issue-38-empty-category-white-screen
Mar 6, 2026
Merged

fix: 修复空分类场景白屏(Hook 调用顺序问题)#46
AmintaCCCP merged 1 commit intomainfrom
fix/issue-38-empty-category-white-screen

Conversation

@AmintaCCCP
Copy link
Owner

@AmintaCCCP AmintaCCCP commented Mar 6, 2026

根因分析

Issue #38(分类数量为 0 时白屏)的根因是 RepositoryList 中存在 条件分支内调用 Hook

  • filteredRepositories.length === 0 时,代码路径里调用了 useAppStore()
  • 当列表非空时,这个 Hook 不会被调用

这违反了 React Hook 规则(Hooks 必须在组件顶层且每次渲染顺序一致),会导致运行时异常,表现为白屏。

修复方案

  • searchFilters 从组件顶层一次性通过 useAppStore() 解构出来
  • 删除空列表分支内的 useAppStore() 调用

这样无论分类是否为空,Hook 调用顺序都一致,避免白屏。

影响范围

  • 仅修改 src/components/RepositoryList.tsx
  • 不改变业务逻辑,只修复 Hook 调用位置

验证

  • 前端构建通过:npm run build
  • 逻辑上可覆盖“分类数量为 0”场景,不再触发 Hook 顺序错误

Closes #38

Summary by CodeRabbit

  • New Features

    • Added search query integration to repository cards for improved search result display.
  • Refactor

    • Updated repository list component to leverage centralized search state management.

@coderabbitai
Copy link

coderabbitai bot commented Mar 6, 2026

📝 Walkthrough

Walkthrough

RepositoryList now consumes searchFilters from the app store and passes the searchQuery prop to RepositoryCard for client-side search integration. A redundant local searchFilters declaration was removed, reducing duplication.

Changes

Cohort / File(s) Summary
Store-driven search integration
src/components/RepositoryList.tsx
Updated component to destructure searchFilters from app store, removed local re-declaration, and passed searchQuery prop to RepositoryCard sourced from store state. Extended RepositoryCard interface with new searchQuery prop.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Possibly related PRs

  • PR #45: Modifies RepositoryCard/RepositoryList interaction by changing timestamp display/source logic, indicating shared component refinement patterns.

Poem

🐰 A query hops through the store so bright,
RepositoryList passes props left and right,
CardComponents now search with delight,
No more duplicates cluttering the sight! 🌟

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title in Chinese refers to fixing a white-screen issue related to Hook call order in empty category scenarios, which directly matches the root cause and fix described in the PR objectives.
Linked Issues check ✅ Passed The PR successfully addresses Issue #38 by fixing the Hook call order violation that caused the white-screen bug in empty category scenarios, ensuring consistent Hook invocation across all rendering paths.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the Hook call order issue in RepositoryList.tsx; no unrelated modifications or scope creep detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/issue-38-empty-category-white-screen

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/components/RepositoryList.tsx (1)

509-509: Use the already-destructured searchFilters.query instead of getState().

searchFilters is already destructured from useAppStore() at line 30. Using useAppStore.getState() here is redundant and inconsistent with the reactive pattern used elsewhere in this component.

♻️ Proposed fix
           <RepositoryCard 
             key={repo.id}
             repository={repo} 
             showAISummary={showAISummary}
-            searchQuery={useAppStore.getState().searchFilters.query}
+            searchQuery={searchFilters.query}
           />
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/RepositoryList.tsx` at line 509, Replace the non-reactive call
useAppStore.getState().searchFilters.query used for the searchQuery prop with
the already-destructured searchFilters.query (the searchFilters variable
obtained from useAppStore() at the top of the component) so the component uses
the reactive local binding (searchFilters.query) consistently; update the
searchQuery prop where it's passed (searchQuery=...) to use searchFilters.query.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/components/RepositoryList.tsx`:
- Line 509: Replace the non-reactive call
useAppStore.getState().searchFilters.query used for the searchQuery prop with
the already-destructured searchFilters.query (the searchFilters variable
obtained from useAppStore() at the top of the component) so the component uses
the reactive local binding (searchFilters.query) consistently; update the
searchQuery prop where it's passed (searchQuery=...) to use searchFilters.query.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 48e90d2e-3032-4e2a-86d8-c69825fd11b2

📥 Commits

Reviewing files that changed from the base of the PR and between 5504a6f and 397d61e.

📒 Files selected for processing (1)
  • src/components/RepositoryList.tsx

@AmintaCCCP AmintaCCCP merged commit 02f921a into main Mar 6, 2026
5 checks passed
@AmintaCCCP AmintaCCCP deleted the fix/issue-38-empty-category-white-screen branch March 6, 2026 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

【Bug】某个分类数量为0时点开白屏

1 participant