Repository navigation
fix: prevent redundant workspace switch toast - #8229
bijin-bruno merged 5 commits into
Conversation
- Added an early return check in the switchWorkspace Redux action. - Prevents unnecessary state hydration and toast notifications when a user clicks on the already active workspace.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughAn early-return was added to handleWorkspaceSwitch to skip dispatching switchWorkspace and showing the success toast when the selected workspace is already the active workspace. ChangesWorkspace No-op Guard
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Update workspace switching to return a success boolean and only show the “Switched to …” toast when a switch actually occurred.
Changes:
- Make
switchWorkspacereturnfalsewhen no switch happens (same workspace or workspace not found) andtruewhen it completes. - Update
AppTitleBarto await the dispatch result and conditionally show the success toast.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| packages/bruno-app/src/providers/ReduxStore/slices/workspaces/actions.js | Adds boolean return semantics to switchWorkspace for “did switch?” signaling. |
| packages/bruno-app/src/components/AppTitleBar/index.js | Awaits switchWorkspace and suppresses success toast unless the switch succeeded. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
packages/bruno-app/src/components/AppTitleBar/index.js (1)
148-153: ⚡ Quick winGood implementation of conditional toast, but consider memoizing the handler.
The async/await pattern and conditional toast based on the result correctly implements the intended behavior.
However,
handleWorkspaceSwitchis captured in theworkspaceMenuItemsuseMemo (line 216) but is not listed in the dependency array (line 266). While this works correctly due to transitive dependencies throughsortedWorkspaces, it technically violates React hooks rules (exhaustive-deps).♻️ Suggested refactor to use useCallback
- const handleWorkspaceSwitch = async (workspaceUid) => { + const handleWorkspaceSwitch = useCallback(async (workspaceUid) => { const result = await dispatch(switchWorkspace(workspaceUid)); if (result) { toast.success(`Switched to ${getWorkspaceDisplayName(workspaces.find((w) => w.uid === workspaceUid)?.name)}`); } - }; + }, [dispatch, workspaces]);Then add it to the
workspaceMenuItemsdependency array:- }, [sortedWorkspaces, activeWorkspaceUid, preferences, handlePinWorkspace, handleCreateWorkspace]); + }, [sortedWorkspaces, activeWorkspaceUid, preferences, handlePinWorkspace, handleCreateWorkspace, handleWorkspaceSwitch]);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/bruno-app/src/components/AppTitleBar/index.js` around lines 148 - 153, The handler handleWorkspaceSwitch is used inside the workspaceMenuItems memo but isn’t stable across renders, violating exhaustive-deps; wrap handleWorkspaceSwitch in useCallback (keep its async logic and the dispatch(switchWorkspace(...)) call and the toast.success call) and then include that memoized handleWorkspaceSwitch in the dependency array of workspaceMenuItems so the memoization is correct and React hooks rules are satisfied.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/bruno-app/src/components/AppTitleBar/index.js`:
- Around line 148-153: Update handleOpenWorkspace to await the dispatch of the
switchWorkspace thunk and only show the success toast when the thunk returns a
truthy result: replace the current non-awaited
dispatch(switchWorkspace(workspace.uid)) and unconditional toast.success call
with an awaited const result = await dispatch(switchWorkspace(workspace.uid));
and then conditionally call toast.success(`Switched to
${getWorkspaceDisplayName(workspaces.find(w => w.uid ===
workspace.uid)?.name)}`) only if result is truthy, mirroring AppTitleBar's
handleWorkspaceSwitch behavior.
In `@packages/bruno-app/src/providers/ReduxStore/slices/workspaces/actions.js`:
- Around line 707-708: The action currently always returns true at the end even
when an exception is caught; update the workspace switch action in this file
(the function wrapping the try/catch that currently logs an error at the catch
and then returns true) to track and return an explicit success flag: initialize
success = false before the try, set success = true only after the successful
path (e.g., after the awaited operations that indicate a completed switch), and
return success at the end (or return false inside the catch) so callers receive
false on failure instead of a misleading true.
---
Nitpick comments:
In `@packages/bruno-app/src/components/AppTitleBar/index.js`:
- Around line 148-153: The handler handleWorkspaceSwitch is used inside the
workspaceMenuItems memo but isn’t stable across renders, violating
exhaustive-deps; wrap handleWorkspaceSwitch in useCallback (keep its async logic
and the dispatch(switchWorkspace(...)) call and the toast.success call) and then
include that memoized handleWorkspaceSwitch in the dependency array of
workspaceMenuItems so the memoization is correct and React hooks rules are
satisfied.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: be806a69-8de0-4b0f-87e4-82b26f9d9388
📒 Files selected for processing (2)
packages/bruno-app/src/components/AppTitleBar/index.jspackages/bruno-app/src/providers/ReduxStore/slices/workspaces/actions.js
…ess and error states correctly
…dto the already active workspace
Description
Fixes: #8075
JIRA
This PR fixes only one bug that was mentioned in that issue.
Issue:
Issue 2: Workspace switch toast appears unnecessarily
Steps to Reproduce:
Open a workspace
Click on the same currently active workspace again
Actual Result
A workspace switch toast/notification is displayed even though the user is already inside the selected workspace.
Expected Result
No toast or workspace switch action should occur when clicking the currently active workspace.
Fix:
handleWorkspaceSwitchto returnfalseif the selected workspace is already active.Before
596771987-d5c26eff-5ff1-443a-8ead-66c3973766b3.mov
After
Screen.Recording.2026-06-10.at.7.04.17.PM.mov
Contribution Checklist:
Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.
Publishing to New Package Managers
Please see here for more information.
Summary by CodeRabbit