Skip to content

Bugfix/close saved deleting collections#7048

Open
chirag-bruno wants to merge 3 commits intousebruno:mainfrom
chirag-bruno:bugfix/close-saved-deleting-collections
Open

Bugfix/close saved deleting collections#7048
chirag-bruno wants to merge 3 commits intousebruno:mainfrom
chirag-bruno:bugfix/close-saved-deleting-collections

Conversation

@chirag-bruno
Copy link
Contributor

@chirag-bruno chirag-bruno commented Feb 5, 2026

Description

Fixes issues with closing transient request tabs:

  1. Fixed collection deletion bug: The "Close Saved" feature was incorrectly deleting collections because file deletions could traverse
    outside the temp directory. Added a dedicated IPC handler (renderer:delete-transient-requests) that validates files are within the collection's
    temp directory before deletion.

  2. Fixed error when closing all tabs: Closing all tabs (including transient requests) would show "An error occurred!" instead of returning to
    WorkspaceHome. The focusTab reducer now validates that the target tab exists before setting it as active.

  3. Improved tab closing reliability: Consolidated transient file cleanup into the closeTabs thunk action and introduced
    handleCloseMultipleTabs to streamline closing multiple tabs while preserving unsaved changes.

This PR addresses: https://usebruno.atlassian.net/browse/BRU-2617 and https://usebruno.atlassian.net/browse/BRU-2625

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.

Summary by CodeRabbit

  • New Features

    • Batch tab closing: close multiple tabs at once while preserving and saving unsaved changes.
  • Bug Fixes

    • Improved cleanup of transient request files with safer, directory-scoped deletion.
    • More robust tab focus handling to avoid invalid active-tab assignments.

The Close Saved feature was incorrectly triggering file deletions that
could traverse outside the temp directory, causing collections to be
deleted. This fix:

- Creates a dedicated IPC handler (renderer:delete-transient-requests)
  that validates files are within the collection's temp directory
- Consolidates transient cleanup into the closeTabs thunk action
- Removes unsafe deletion logic from the tasks middleware
- Updates all components to use the safe closeTabs action from actions.js
This update introduces a new function, handleCloseMultipleTabs, to streamline the process of closing multiple tabs while ensuring any unsaved changes are saved first. Additionally, the closeTabs action has been modified to handle asynchronous file deletion after tabs are closed, improving the reliability of transient file cleanup. The focusTab reducer now checks for the existence of a tab before setting it as active, enhancing stability.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 5, 2026

Walkthrough

Consolidates the closeTabs action into collections/actions, adds a new async closeTabs thunk that closes tabs and requests transient-file cleanup via IPC, introduces batch tab-closing in the RequestTab UI, removes the old middleware closeTabs listener, and adds an Electron IPC handler for deleting transient request files.

Changes

Cohort / File(s) Summary
Import path updates
packages/bruno-app/src/components/RequestTabPanel/..., packages/bruno-app/src/components/RequestTabs/ExampleTab/index.js, packages/bruno-app/src/components/SaveTransientRequest/*, packages/bruno-app/src/components/Sidebar/Collections/.../*, packages/bruno-app/src/providers/Hotkeys/index.js, packages/bruno-app/src/providers/ReduxStore/slices/app.js
Repointed consumers to import closeTabs from providers/ReduxStore/slices/collections/actions instead of slices/tabs. No runtime logic changes in these consumers.
Batch tab-closing UI
packages/bruno-app/src/components/RequestTabs/RequestTab/index.js
Added handleCloseMultipleTabs(tabs) to save unsaved changes per-tab then dispatch a single closeTabs({ tabUids }); replaced other/left/right/all close handlers to use the batch helper.
New closeTabs thunk
packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js
Added async closeTabs({ tabUids }) thunk that wraps existing reducer, computes transient items by tab UID, dispatches close reducer, then invokes IPC to delete transient files grouped by temp directory.
IPC transient cleanup
packages/bruno-electron/src/ipc/collection.js
Added renderer:delete-transient-requests handler to validate and delete transient request files and remove UID mappings; removed previous temp-file deletion from renderer:save-transient-request.
Middleware cleanup
packages/bruno-app/src/providers/ReduxStore/middlewares/tasks/middleware.js
Removed closeTabs listener and related cleanup logic (now handled by the new thunk); adjusted imported utilities accordingly.
Tabs reducer safeguard
packages/bruno-app/src/providers/ReduxStore/slices/tabs.js
focusTab reducer now verifies the UID exists in state.tabs before assigning activeTabUid.

Sequence Diagram(s)

sequenceDiagram
    participant UI as RequestTab Component
    participant Redux as Redux Store (thunk)
    participant IPC as Electron IPC
    participant FS as File System

    UI->>UI: handleCloseMultipleTabs(tabs)
    loop per tab
        UI->>Redux: dispatch(saveRequest(tab))
        Redux-->>UI: save result
    end

    UI->>Redux: dispatch(closeTabs({ tabUids }))
    activate Redux
    Redux->>Redux: find transient items by tabUids
    Redux->>Redux: group files by tempDirectory
    Redux->>Redux: dispatch(_closeTabs reducer)
    Redux-->>UI: tabs closed

    loop per tempDirectory
        Redux->>IPC: invoke 'renderer:delete-transient-requests' (tempDirectory, files)
        activate IPC
        IPC->>FS: validate & delete files, update UID mappings
        IPC-->>Redux: deletion results
        deactivate IPC
    end
    deactivate Redux
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

Suggested labels

size/XL

Suggested reviewers

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

Poem

Tabs gather, then kindly fold,
Transient crumbs sent off to cold,
Actions moved to one shared place,
Redux, IPC — tidy space,
Small files gone, the UI bold ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 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 (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main objective: fixing the bug where closing saved transient requests could incorrectly delete collections, combined with related tab-closing improvements.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

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/RequestTabs/RequestTab/index.js (1)

477-518: ⚠️ Potential issue | 🟠 Major

Prevent closing tabs when save fails (data-loss risk).

handleCloseMultipleTabs ignores save failures and then closes all tabs anyway. This can drop unsaved changes (including transient save failures). Keep failed-save tabs open and only close successfully saved tabs.

🔧 Proposed fix
 async function handleCloseMultipleTabs(tabs) {
-  // First, save any tabs with unsaved changes
-  for (const tab of tabs) {
-    const item = findItemInCollection(collection, tab.uid);
-    if (item && hasRequestChanges(item)) {
-      try {
-        await dispatch(saveRequest(item.uid, collection.uid, true));
-      } catch (err) {
-        // Continue even if save fails
-      }
-    }
-  }
-
-  // Then close all tabs in a single call
-  const tabUids = tabs.map((tab) => tab.uid);
-  dispatch(closeTabs({ tabUids }));
+  const tabUidsToClose = [];
+
+  // First, save any tabs with unsaved changes
+  for (const tab of tabs) {
+    const item = findItemInCollection(collection, tab.uid);
+    if (item && hasRequestChanges(item)) {
+      try {
+        await dispatch(saveRequest(item.uid, collection.uid, true));
+      } catch (err) {
+        continue;
+      }
+    }
+
+    if (tab?.uid) {
+      tabUidsToClose.push(tab.uid);
+    }
+  }
+
+  // Then close only successfully saved tabs
+  if (tabUidsToClose.length > 0) {
+    dispatch(closeTabs({ tabUids: tabUidsToClose }));
+  }
 }

This update refines the handleCloseMultipleTabs function to enhance the tab closing process. It now collects UIDs of tabs with unsaved changes and dispatches a single closeTabs action for those tabs, improving efficiency and reliability in managing transient requests.
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.

1 participant