Bugfix/close saved deleting collections#7048
Bugfix/close saved deleting collections#7048chirag-bruno wants to merge 3 commits intousebruno:mainfrom
Conversation
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.
WalkthroughConsolidates the Changes
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
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 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.
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 | 🟠 MajorPrevent closing tabs when save fails (data-loss risk).
handleCloseMultipleTabsignores 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.
Description
Fixes issues with closing transient request tabs:
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'stemp directory before deletion.
Fixed error when closing all tabs: Closing all tabs (including transient requests) would show "An error occurred!" instead of returning to
WorkspaceHome. The
focusTabreducer now validates that the target tab exists before setting it as active.Improved tab closing reliability: Consolidated transient file cleanup into the
closeTabsthunk action and introducedhandleCloseMultipleTabsto 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:
Summary by CodeRabbit
New Features
Bug Fixes