Skip to content

feat: snapshot issues with global tabs - #7942

Merged
bijin-bruno merged 3 commits into
usebruno:mainfrom
sid-bruno:feat/snapshot-fixes
May 7, 2026
Merged

bijin-bruno merged 3 commits into
usebruno:mainfrom
sid-bruno:feat/snapshot-fixes

Conversation

@sid-bruno

@sid-bruno sid-bruno commented May 7, 2026 •

Copy link
Copy Markdown
Collaborator

Description

  • Fixes JIRA
  • Fixes re-opening issue for preferences and global environments

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

  • New Features

    • Send-request keybinding now works for generic request tabs.
  • Bug Fixes

    • Prevent duplicate tabs by matching existing tabs by pathname and item mapping.
    • Singleton tabs (Preferences, Global Environments, collection-scoped settings) restore reliably and avoid duplication.
    • Sidebar interactions now focus and reuse restored request tabs instead of opening duplicates.
  • Tests

    • Added end-to-end snapshot tests covering tab restoration and reuse across restarts.

@coderabbitai

coderabbitai Bot commented May 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Adds pathname-based tab deduplication and selectors that match tabs by UID or pathname, derives deterministic UIDs for collection-scoped singleton tabs, updates components to use the new lookup, and adds unit and E2E tests verifying tab restoration and reuse across restarts.

Changes

Tab Management and Singleton Tab Restoration

Layer / File(s) Summary
Tab Selector Contracts
packages/bruno-app/src/selectors/tab.js
Added getTabUidForItem selector; expanded isTabForItemActive and isTabForItemPresent to support pathname-based lookup with optional collection filtering.
Singleton Tab Type Definition
packages/bruno-app/src/utils/snapshot/index.js
Extended SINGLETON_TAB_TYPES to include preferences, environment-settings, global-environment-settings. deserializeTab now derives deterministic UIDs for these collection-scoped tabs using type-based suffixes when pathname is unavailable.
Tab State Deduplication
packages/bruno-app/src/providers/ReduxStore/slices/tabs.js
Introduced findTabByPathname helper to match tabs by collectionUid, pathname, and type. addTab reducer checks for existing tabs by pathname before creation, preventing duplicates.
Component Integration
packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js, packages/bruno-app/src/components/RequestTabPanel/index.js
CollectionItem selects tabUidForItem and uses it in focus/makeTabPermanent/folder-settings actions. RequestTabPanel keybinding condition expanded to recognize generic request tab type.
Snapshot Deserialization Tests
packages/bruno-app/src/utils/snapshot/index.spec.js
Added tests for UID restoration of collection-scoped singleton types using type suffixes, and fallback behavior when pathname is absent.
Integration and E2E Tests
tests/snapshots/global-tabs.spec.ts, tests/snapshots/sidebar-state.spec.ts, tests/utils/page/locators.ts
Added E2E tests verifying singleton tabs (Preferences, Global Environments) and request tabs restore and reuse correctly across app restarts. Extended test utils with openPreferences locator.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • usebruno/bruno#6894: Preferences migration from modal to tab—related test/locator updates and singleton tab handling.
  • usebruno/bruno#7794: Tab handling enhancements with pathname-based lookup and deduplication logic.
  • usebruno/bruno#7709: Related changes to tabs reducer and transient/restore behavior.

Suggested reviewers

  • helloanoop
  • lohit-bruno
  • naman-bruno

Poem

Tabs aligned by path and name,
Singletons hold their steady claim,
Restarts bring back the same bright view,
No duplicates — the tabs stay true. 🧭✨

🚥 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 accurately describes the main focus of the changeset—fixing snapshot-related issues with global tabs (Preferences and Global Environments).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 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.

@sid-bruno
sid-bruno marked this pull request as ready for review May 7, 2026 12:14
Copilot AI review requested due to automatic review settings May 7, 2026 12:14
bijin-bruno
bijin-bruno previously approved these changes May 7, 2026

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

This PR adds snapshot-restoration coverage and adjusts tab/snapshot logic so restored tabs (including singleton “global” tabs like Preferences and Global Environments) are re-associated with the correct sidebar items and are not duplicated after an app restart.

Changes:

  • Add Playwright snapshot tests for sidebar tab restoration and singleton tab restoration across restarts.
  • Update snapshot tab (de)serialization to treat additional singleton tab types as type-accessed and to scope certain singleton UIDs to collection UIDs.
  • Improve tab reuse by enabling pathname-based tab lookup/focus in selectors and in the tabs slice.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/utils/page/locators.ts Adds a locator for opening Preferences via the status bar button.
tests/snapshots/sidebar-state.spec.ts New E2E snapshot test for sidebar ↔ restored tab association and reuse.
tests/snapshots/global-tabs.spec.ts New E2E snapshot test for restoring/reusing Preferences + Global Environments tabs.
packages/bruno-app/src/utils/snapshot/index.spec.js Adds unit tests for collection-scoped singleton UID restoration.
packages/bruno-app/src/utils/snapshot/index.js Expands singleton tab handling and adds fallback logic for legacy/partial snapshot entries.
packages/bruno-app/src/selectors/tab.js Introduces selectors to resolve/focus tabs by UID or pathname within a collection.
packages/bruno-app/src/providers/ReduxStore/slices/tabs.js Adds pathname-based de-dupe when adding a tab.
packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js Uses new selectors to focus the correct restored tab UID (including pathname-restored tabs).
packages/bruno-app/src/components/RequestTabPanel/index.js Treats type: 'request' as request-like for keybinding enablement.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/bruno-app/src/selectors/tab.js Resolved
Comment thread packages/bruno-app/src/selectors/tab.js Resolved
Comment thread tests/snapshots/sidebar-state.spec.ts Resolved

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/bruno-app/src/components/RequestTabPanel/index.js (1)

67-73: ⚠️ Potential issue | 🔴 Critical

Add a case in renderRequestPane for 'request' type, or remove 'request' from the keybinding guard.

The type 'request' is explicitly set in ScriptError/index.js:130 when navigating to a request from script errors, and the tabs reducer defaults to it. However, renderRequestPane() has no case for 'request' and returns null. Enabling the keybinding for type: 'request' tabs means the send command works but renders no UI, which is contradictory. Either handle 'request' in the switch statement (likely same as 'http-request') or exclude it from isRequestTab if it's not a valid/intended request type.

🤖 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/RequestTabPanel/index.js` around lines 67 -
73, The keybinding is enabled for focusedTab.type === 'request' but
renderRequestPane() has no case for 'request' so a focused 'request' tab sends a
request with no UI; either add a 'request' branch in renderRequestPane (treat it
the same as 'http-request' / other request panes) or remove 'request' from the
isRequestTab list so the sendRequest keybinding is not enabled for that
type—locate the focusedTab/type check (isRequestTab) and the renderRequestPane
switch to implement the chosen change (e.g., add a 'request' case mirroring
'http-request' or delete 'request' from the includes array).
🧹 Nitpick comments (3)
tests/snapshots/global-tabs.spec.ts (1)

32-35: 💤 Low value

Step name 'Close and restart app' is slightly misleading — restart happens in the next step.

The step body only closes the app; the relaunch is inside 'Verify restored singleton tabs...'. Consider splitting or renaming to 'Close app' to keep step descriptions accurate in reports.

🤖 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 `@tests/snapshots/global-tabs.spec.ts` around lines 32 - 35, The step named
'Close and restart app' is misleading because it only calls
closeElectronApp(app) and the relaunch happens in the subsequent step ('Verify
restored singleton tabs...'); update the test.step invocation to a more accurate
name like 'Close app' (or split into two steps if you prefer) by changing the
step description string where test.step(...) wraps closeElectronApp(app) to
reflect that it only closes the app (refer to test.step and closeElectronApp in
the diff).
packages/bruno-app/src/utils/snapshot/index.spec.js (1)

250-281: ⚡ Quick win

Missing test case for environment-settings collection-scoped UID.

index.js now derives tab.uid = \${collection.uid}-environment-settings`for theenvironment-settingstype (same code path aspreferencesandglobal-environment-settings), but there's no corresponding test case here. Given that environment-settingswas already a pre-existingSINGLETON_TAB_TYPE` with a different UID strategy, this change is worth a regression guard.

✅ Suggested test to add
+  it('restores environment-settings uid scoped to collection uid', () => {
+    const snapshotTab = {
+      type: 'environment-settings',
+      accessor: 'type',
+      permanent: true
+    };
+
+    const tab = deserializeTab(snapshotTab, collection);
+    expect(tab.uid).toBe('collection-uid-environment-settings');
+  });
🤖 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/utils/snapshot/index.spec.js` around lines 250 - 281,
Add a new unit test in the same spec that verifies deserializeTab restores a
collection-scoped UID for the "environment-settings" singleton type;
specifically create a snapshotTab with type: 'environment-settings', accessor:
'type' (and optionally a second test with accessor: 'pathname') then call
deserializeTab(snapshotTab, collection) and assert tab.uid ===
`${collection.uid}-environment-settings` to mirror the existing tests for
'preferences' and 'global-environment-settings'.
packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js (1)

67-80: ⚡ Quick win

Selector factory instances recreated on every render — reselect memoization is not preserved.

isTabForItemActiveSelector(selectorInput) etc. are called at the component render level with a freshly constructed selectorInput object each time. If these factories return createSelector-based selectors, each call produces a new instance with a cold memoization cache, meaning the selector always recomputes on every Redux state change. CollectionItem is rendered once per sidebar item, so the impact scales with collection size.

Memoize both the input and the derived selectors:

⚡ Proposed fix
-  const selectorInput = {
-    itemUid: item.uid,
-    itemPathname: item.pathname,
-    collectionUid
-  };
-
-  const _isTabForItemActiveSelector = isTabForItemActiveSelector(selectorInput);
+  const selectorInput = useMemo(
+    () => ({ itemUid: item.uid, itemPathname: item.pathname, collectionUid }),
+    [item.uid, item.pathname, collectionUid]
+  );
+
+  const _isTabForItemActiveSelector = useMemo(
+    () => isTabForItemActiveSelector(selectorInput),
+    [selectorInput]
+  );
   const isTabForItemActive = useSelector(_isTabForItemActiveSelector, isEqual);
 
-  const _isTabForItemPresentSelector = isTabForItemPresentSelector(selectorInput);
+  const _isTabForItemPresentSelector = useMemo(
+    () => isTabForItemPresentSelector(selectorInput),
+    [selectorInput]
+  );
   const isTabForItemPresent = useSelector(_isTabForItemPresentSelector, isEqual);
 
-  const _tabUidForItemSelector = getTabUidForItemSelector(selectorInput);
-  const tabUidForItem = useSelector(_tabUidForItemSelector, isEqual);
+  const _tabUidForItemSelector = useMemo(
+    () => getTabUidForItemSelector(selectorInput),
+    [selectorInput]
+  );
+  const tabUidForItem = useSelector(_tabUidForItemSelector, isEqual);
🤖 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/Sidebar/Collections/Collection/CollectionItem/index.js`
around lines 67 - 80, The component recreates selectorInput and calls the
selector factories (isTabForItemActiveSelector, isTabForItemPresentSelector,
getTabUidForItemSelector) on every render which defeats reselect memoization;
fix by memoizing selectorInput with useMemo (depend on item.uid, item.pathname,
collectionUid) and then memoize each derived selector instance with useMemo
(call each factory with the memoized selectorInput) before passing them to
useSelector (still use isEqual); update CollectionItem to compute selectorInput
and the three selector instances via useMemo to preserve reselect caches.
🤖 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/Sidebar/Collections/Collection/CollectionItem/index.js`:
- Around line 48-52: The import of getTabUidForItemSelector,
isTabForItemActiveSelector, and isTabForItemPresentSelector currently uses a
hardcoded 'src/selectors/tab' path which violates project alias conventions; add
a path alias for selectors/* to jsconfig.json (pointing to the appropriate
src/selectors/* folder) and then update the imports in CollectionItem (and the
similar import in Collection/index.js) to use the new alias (e.g.,
'selectors/tab') so imports are consistent with other modules.

In `@packages/bruno-app/src/selectors/tab.js`:
- Around line 27-42: The early return in isTabForItemActive that returns true
when activeTabUid === itemUid ignores the optional collectionUid filter; to fix,
ensure the collection filter is applied before returning true by locating the
active tab (use the tabs.find lookup currently in the function) and only return
true when activeTabUid === itemUid AND (collectionUid is not provided OR
activeTab.collectionUid === collectionUid); i.e., either move the activeTab
lookup above the UID check or replace the early UID-return with a conditional
that checks activeTab.collectionUid when collectionUid is present so the
function honors the collectionUid parameter.

---

Outside diff comments:
In `@packages/bruno-app/src/components/RequestTabPanel/index.js`:
- Around line 67-73: The keybinding is enabled for focusedTab.type === 'request'
but renderRequestPane() has no case for 'request' so a focused 'request' tab
sends a request with no UI; either add a 'request' branch in renderRequestPane
(treat it the same as 'http-request' / other request panes) or remove 'request'
from the isRequestTab list so the sendRequest keybinding is not enabled for that
type—locate the focusedTab/type check (isRequestTab) and the renderRequestPane
switch to implement the chosen change (e.g., add a 'request' case mirroring
'http-request' or delete 'request' from the includes array).

---

Nitpick comments:
In
`@packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js`:
- Around line 67-80: The component recreates selectorInput and calls the
selector factories (isTabForItemActiveSelector, isTabForItemPresentSelector,
getTabUidForItemSelector) on every render which defeats reselect memoization;
fix by memoizing selectorInput with useMemo (depend on item.uid, item.pathname,
collectionUid) and then memoize each derived selector instance with useMemo
(call each factory with the memoized selectorInput) before passing them to
useSelector (still use isEqual); update CollectionItem to compute selectorInput
and the three selector instances via useMemo to preserve reselect caches.

In `@packages/bruno-app/src/utils/snapshot/index.spec.js`:
- Around line 250-281: Add a new unit test in the same spec that verifies
deserializeTab restores a collection-scoped UID for the "environment-settings"
singleton type; specifically create a snapshotTab with type:
'environment-settings', accessor: 'type' (and optionally a second test with
accessor: 'pathname') then call deserializeTab(snapshotTab, collection) and
assert tab.uid === `${collection.uid}-environment-settings` to mirror the
existing tests for 'preferences' and 'global-environment-settings'.

In `@tests/snapshots/global-tabs.spec.ts`:
- Around line 32-35: The step named 'Close and restart app' is misleading
because it only calls closeElectronApp(app) and the relaunch happens in the
subsequent step ('Verify restored singleton tabs...'); update the test.step
invocation to a more accurate name like 'Close app' (or split into two steps if
you prefer) by changing the step description string where test.step(...) wraps
closeElectronApp(app) to reflect that it only closes the app (refer to test.step
and closeElectronApp in the diff).
🪄 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: ef5080ef-9d06-4dfe-8278-3384d5a7e6a9

📥 Commits

Reviewing files that changed from the base of the PR and between f8bf146 and edfb4a2.

📒 Files selected for processing (9)
  • packages/bruno-app/src/components/RequestTabPanel/index.js
  • packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js
  • packages/bruno-app/src/providers/ReduxStore/slices/tabs.js
  • packages/bruno-app/src/selectors/tab.js
  • packages/bruno-app/src/utils/snapshot/index.js
  • packages/bruno-app/src/utils/snapshot/index.spec.js
  • tests/snapshots/global-tabs.spec.ts
  • tests/snapshots/sidebar-state.spec.ts
  • tests/utils/page/locators.ts

Comment thread packages/bruno-app/src/selectors/tab.js Resolved

@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.

🧹 Nitpick comments (2)
packages/bruno-app/src/selectors/tab.js (2)

19-21: 💤 Low value

Optional-chaining inconsistency between state.tabs?.activeTabUid and state.tabs.tabs.

Line 20 uses ?. on state.tabs but line 21 accesses state.tabs.tabs without a guard. If state.tabs were ever undefined, line 21 would throw while line 20 would silently return undefined. Either both selectors should guard, or neither should (since the store shape guarantees state.tabs exists).

♻️ Suggested fix
 export const isTabForItemActive = ({ itemUid, itemPathname, collectionUid }) => createSelector([
-  (state) => state.tabs?.activeTabUid,
+  (state) => state.tabs.activeTabUid,
   (state) => state.tabs.tabs
 ], (activeTabUid, tabs) => {
🤖 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/selectors/tab.js` around lines 19 - 21, The selector
isTabForItemActive mixes optional-chaining and direct access — (state) =>
state.tabs?.activeTabUid vs (state) => state.tabs.tabs — which can throw if
state.tabs is undefined; make them consistent by either using optional chaining
for both (e.g., change the second selector to use state.tabs?.tabs) or remove
the ?. from the first if the store always guarantees tabs exist (change the
first to state.tabs.activeTabUid); update the selectors inside createSelector to
match that decision so both accesses behave the same.

3-17: 💤 Low value

getTabUidForItem always returns itemUid on a UID hit — minor redundancy.

tabByUid.uid (line 8) is always identical to itemUid because that's the find predicate on line 6. Returning itemUid directly would make the intent clearer, though the behaviour is identical.

♻️ Suggested simplification
-  if (tabByUid) {
-    return tabByUid.uid;
-  }
+  if (tabByUid) {
+    return itemUid;
+  }
🤖 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/selectors/tab.js` around lines 3 - 17, The function
getTabUidForItem currently returns tabByUid.uid after finding a tab by matching
uid, which is redundant because tabByUid.uid === itemUid; update the logic in
getTabUidForItem to return itemUid directly when a UID match is found (instead
of tabByUid.uid) to clarify intent while keeping behavior identical; reference
the existing variables tabByUid, itemUid and tabByPathname to locate the change.
🤖 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.

Nitpick comments:
In `@packages/bruno-app/src/selectors/tab.js`:
- Around line 19-21: The selector isTabForItemActive mixes optional-chaining and
direct access — (state) => state.tabs?.activeTabUid vs (state) =>
state.tabs.tabs — which can throw if state.tabs is undefined; make them
consistent by either using optional chaining for both (e.g., change the second
selector to use state.tabs?.tabs) or remove the ?. from the first if the store
always guarantees tabs exist (change the first to state.tabs.activeTabUid);
update the selectors inside createSelector to match that decision so both
accesses behave the same.
- Around line 3-17: The function getTabUidForItem currently returns tabByUid.uid
after finding a tab by matching uid, which is redundant because tabByUid.uid ===
itemUid; update the logic in getTabUidForItem to return itemUid directly when a
UID match is found (instead of tabByUid.uid) to clarify intent while keeping
behavior identical; reference the existing variables tabByUid, itemUid and
tabByPathname to locate the change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: eed8c0eb-b0a7-411a-8b48-8d44da96523a

📥 Commits

Reviewing files that changed from the base of the PR and between edfb4a2 and d5ad2aa.

📒 Files selected for processing (1)
  • packages/bruno-app/src/selectors/tab.js

@bijin-bruno
bijin-bruno merged commit 415b75d into usebruno:main May 7, 2026
11 checks passed
sharan-bruno pushed a commit to sharan-bruno/bruno that referenced this pull request Jun 4, 2026
* chore: fix for sidebar state

* fix: global and sidebar state sync

* fix: re-priroritise how tab uid is synced
@coderabbitai coderabbitai Bot mentioned this pull request Jun 17, 2026
6 tasks
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.

3 participants