Repository navigation
feat: snapshot issues with global tabs - #7942
Conversation
WalkthroughAdds 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. ChangesTab Management and Singleton Tab Restoration
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 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
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.
There was a problem hiding this comment.
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 | 🔴 CriticalAdd a case in
renderRequestPanefor'request'type, or remove'request'from the keybinding guard.The type
'request'is explicitly set inScriptError/index.js:130when navigating to a request from script errors, and the tabs reducer defaults to it. However,renderRequestPane()has no case for'request'and returnsnull. Enabling the keybinding fortype: '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 fromisRequestTabif 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 valueStep 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 winMissing test case for
environment-settingscollection-scoped UID.
index.jsnow derivestab.uid = \${collection.uid}-environment-settings`for theenvironment-settingstype (same code path aspreferencesandglobal-environment-settings), but there's no corresponding test case here. Given thatenvironment-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 winSelector factory instances recreated on every render — reselect memoization is not preserved.
isTabForItemActiveSelector(selectorInput)etc. are called at the component render level with a freshly constructedselectorInputobject each time. If these factories returncreateSelector-based selectors, each call produces a new instance with a cold memoization cache, meaning the selector always recomputes on every Redux state change.CollectionItemis 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
📒 Files selected for processing (9)
packages/bruno-app/src/components/RequestTabPanel/index.jspackages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.jspackages/bruno-app/src/providers/ReduxStore/slices/tabs.jspackages/bruno-app/src/selectors/tab.jspackages/bruno-app/src/utils/snapshot/index.jspackages/bruno-app/src/utils/snapshot/index.spec.jstests/snapshots/global-tabs.spec.tstests/snapshots/sidebar-state.spec.tstests/utils/page/locators.ts
There was a problem hiding this comment.
🧹 Nitpick comments (2)
packages/bruno-app/src/selectors/tab.js (2)
19-21: 💤 Low valueOptional-chaining inconsistency between
state.tabs?.activeTabUidandstate.tabs.tabs.Line 20 uses
?.onstate.tabsbut line 21 accessesstate.tabs.tabswithout a guard. Ifstate.tabswere everundefined, line 21 would throw while line 20 would silently returnundefined. Either both selectors should guard, or neither should (since the store shape guaranteesstate.tabsexists).♻️ 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
getTabUidForItemalways returnsitemUidon a UID hit — minor redundancy.
tabByUid.uid(line 8) is always identical toitemUidbecause that's the find predicate on line 6. ReturningitemUiddirectly 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
📒 Files selected for processing (1)
packages/bruno-app/src/selectors/tab.js
* chore: fix for sidebar state * fix: global and sidebar state sync * fix: re-priroritise how tab uid is synced
Description
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
New Features
Bug Fixes
Tests