Skip to content

fix: prevent redundant workspace switch toast - #8229

Merged
bijin-bruno merged 5 commits into
usebruno:mainfrom
DeviSriSaiCharan:bugfix/prevent-redundant-workspace-switch
Jun 22, 2026
Merged

bijin-bruno merged 5 commits into
usebruno:mainfrom
DeviSriSaiCharan:bugfix/prevent-redundant-workspace-switch

Conversation

@DeviSriSaiCharan

@DeviSriSaiCharan DeviSriSaiCharan commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • Add a check inside handleWorkspaceSwitch to return false if 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:

  • I've used AI significantly to create this pull request
  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • Create an issue and link to the pull request.

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

  • Bug Fixes
    • Workspace switching now ignores requests to switch to the already-active workspace, preventing redundant operations. This removes misleading success notifications for no-op switches, reduces unnecessary processing, and improves UI consistency by ensuring success toasts appear only when an actual switch occurs.

- 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.
Copilot AI review requested due to automatic review settings June 10, 2026 14:14
@coderabbitai

coderabbitai Bot commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d2cb8579-a304-4f99-824e-e9a8a7614f60

📥 Commits

Reviewing files that changed from the base of the PR and between 1e1e0b0 and a56c076.

📒 Files selected for processing (1)
  • packages/bruno-app/src/components/AppTitleBar/index.js

Walkthrough

An early-return was added to handleWorkspaceSwitch to skip dispatching switchWorkspace and showing the success toast when the selected workspace is already the active workspace.

Changes

Workspace No-op Guard

Layer / File(s) Summary
Early-return guard in handleWorkspaceSwitch
packages/bruno-app/src/components/AppTitleBar/index.js
Adds a conditional early return in handleWorkspaceSwitch to skip calling switchWorkspace and avoid showing the success toast when workspaceUid === activeWorkspaceUid.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • usebruno/bruno#8096: Modifies packages/bruno-app/src/components/AppTitleBar/index.js to avoid showing a success toast on cancelled/no-op workspace selections.

Suggested reviewers

  • helloanoop
  • lohit-bruno
  • naman-bruno
  • bijin-bruno

Poem

A click that finds the same old place,
The guard steps in, avoids the race.
No needless toast, no needless call,
Quiet UX — that's the little win for all. 🎈

🚥 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 directly addresses the main change: preventing redundant workspace switch toasts by adding an early return check.
Linked Issues check ✅ Passed The PR successfully implements Issue 2 objective from #8075 by preventing workspace switch toasts when clicking an already-active workspace.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing Issue 2 from #8075; no out-of-scope modifications detected in the workspace switch logic.
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 unit tests (beta)
  • Create PR with unit tests

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 switchWorkspace return false when no switch happens (same workspace or workspace not found) and true when it completes.
  • Update AppTitleBar to 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
packages/bruno-app/src/components/AppTitleBar/index.js (1)

148-153: ⚡ Quick win

Good 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, handleWorkspaceSwitch is captured in the workspaceMenuItems useMemo (line 216) but is not listed in the dependency array (line 266). While this works correctly due to transitive dependencies through sortedWorkspaces, 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 workspaceMenuItems dependency 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

📥 Commits

Reviewing files that changed from the base of the PR and between 377cdb4 and 498e41c.

📒 Files selected for processing (2)
  • packages/bruno-app/src/components/AppTitleBar/index.js
  • packages/bruno-app/src/providers/ReduxStore/slices/workspaces/actions.js

@bijin-bruno
bijin-bruno merged commit 5f55a59 into usebruno:main Jun 22, 2026
17 of 19 checks passed
@DeviSriSaiCharan
DeviSriSaiCharan deleted the bugfix/prevent-redundant-workspace-switch branch June 22, 2026 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UI Inconsistencies with JS file and Workspace

4 participants