Skip to content

Fix team switching not refreshing data across views#33

Merged
fakechris merged 1 commit into
mainfrom
fix/team-switch-refresh
May 15, 2026
Merged

Fix team switching not refreshing data across views#33
fakechris merged 1 commit into
mainfrom
fix/team-switch-refresh

Conversation

@fakechris
Copy link
Copy Markdown
Owner

@fakechris fakechris commented May 15, 2026

Summary

  • 根因: 侧栏切换团队派发 involute:active-team-key 事件,但 BoardPage 和 CyclesPage 未监听该事件,路由不变时组件不重挂载,数据不刷新
  • BoardPage: 添加事件监听,通过 pendingTeamKey 机制触发 GraphQL 重新查询
  • CyclesPage: teamKey 改为响应式 useState + 事件监听
  • BacklogPage: 无需修改(作为 BoardPage 子组件,自动生效)

Test plan

  • 在 Team A 的 Issues 页面,点击侧栏 Team B → Issues 列表刷新为 Team B 数据
  • 在 Backlog 页面切换团队 → 数据刷新
  • 在 Cycles 页面切换团队 → 数据刷新

Made with Cursor

Summary by CodeRabbit

  • Bug Fixes
    • Team selection changes now synchronize in real-time across board and cycles pages, ensuring consistent state when switching teams without requiring manual page refresh.

Review Change Stack

BoardPage and CyclesPage maintained their own team key state initialized
from localStorage on mount, but never listened for the
`involute:active-team-key` event dispatched when clicking a different
team in the sidebar. Because the route stays the same (e.g. `/`),
components were not remounted and stale team data persisted.

- BoardPage: listen for the active-team-key event and feed changes
  through the existing pendingTeamKey mechanism so the GraphQL query
  re-fetches with the new team filter
- CyclesPage: convert the one-shot readStoredTeamKey() call into
  reactive state with the same event listener so cycles reload for
  the selected team

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 15, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1b173bdc-eb75-49ca-81c5-0f4a6ca78eed

📥 Commits

Reviewing files that changed from the base of the PR and between 9115700 and dd2b472.

📒 Files selected for processing (2)
  • packages/web/src/routes/BoardPage.tsx
  • packages/web/src/routes/CyclesPage.tsx

📝 Walkthrough

Walkthrough

BoardPage and CyclesPage now synchronize their team key values by listening to a shared involute:active-team-key custom DOM event. BoardPage uses a ref-based approach to conditionally update pendingTeamKey, while CyclesPage converts its team key to state and updates it when the event fires, with proper cleanup on unmount.

Changes

Event-driven team key synchronization

Layer / File(s) Summary
BoardPage team key event listener
packages/web/src/routes/BoardPage.tsx
BoardPage introduces activeTeamKeyRef to track the active team key and registers a mount/unmount useEffect listener for the involute:active-team-key custom event, updating pendingTeamKey only when the incoming key differs from the ref's current value.
CyclesPage team key event listener
packages/web/src/routes/CyclesPage.tsx
CyclesPage converts teamKey from a constant to state initialized from readStoredTeamKey(), adds the useEffect import, and registers a window listener for involute:active-team-key to synchronize state with the event detail, cleaning up on unmount.

🎯 2 (Simple) | ⏱️ ~10 minutes

🐰 Two pages now listen with care,
To events floating through the air,
Team keys sync without a fuss,
Custom events bring harmony to us! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly addresses the main problem: team switching not refreshing data across multiple views (BoardPage and CyclesPage), which matches the core changes and objectives.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/team-switch-refresh

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


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
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements a synchronization mechanism for the active team key across the BoardPage and CyclesPage components by listening to a custom 'involute:active-team-key' event. The review feedback highlights three main areas for improvement: refining the state update logic in BoardPage to prevent potential race conditions when switching teams, moving the assignment of activeTeamKeyRef.current into a useEffect hook to adhere to React best practices, and extracting the hardcoded event name into a shared constant to improve maintainability and reduce the risk of typos.

Comment on lines +147 to +149
if (nextTeamKey !== activeTeamKeyRef.current) {
setPendingTeamKey(nextTeamKey);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

在处理 involute:active-team-key 事件时,如果 nextTeamKey 与当前 activeTeamKey 相同,建议显式将 pendingTeamKey 重置为 null。这可以避免在快速切换团队(例如 A -> B -> A)时,由于 pendingTeamKey 仍停留在旧值('B')而导致组件最终错误地切换到团队 B 的竞态问题。

      setPendingTeamKey(nextTeamKey === activeTeamKeyRef.current ? null : nextTeamKey);

const [activeTeamKey, setActiveTeamKey] = useState<string | null>(() => readStoredTeamKey());
const [pendingTeamKey, setPendingTeamKey] = useState<string | null>(null);
const activeTeamKeyRef = useRef(activeTeamKey);
activeTeamKeyRef.current = activeTeamKey;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

避免在渲染过程中直接修改 ref.current。根据 React 官方文档建议,这类副作用操作应放在 useEffectuseLayoutEffect 中,以确保在并发渲染模式下的行为正确性。

  useEffect(() => {
    activeTeamKeyRef.current = activeTeamKey;
  }, [activeTeamKey]);

}
}

window.addEventListener('involute:active-team-key', handleActiveTeamKeyChange as EventListener);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

事件名称 'involute:active-team-key' 在多个组件中硬编码使用。建议将其提取到 utils.ts 中的常量(例如 ACTIVE_TEAM_EVENT),以提高代码的可维护性并减少因拼写错误导致的 Bug。

@fakechris fakechris merged commit d5f5223 into main May 15, 2026
2 checks passed
@fakechris fakechris deleted the fix/team-switch-refresh branch May 15, 2026 07:15
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.

1 participant