Skip to content

fix: example tab not closing post delete, tab not found issue when i …#6561

Merged
bijin-bruno merged 1 commit intousebruno:mainfrom
sanish-bruno:fix/example-delete
Dec 30, 2025
Merged

fix: example tab not closing post delete, tab not found issue when i …#6561
bijin-bruno merged 1 commit intousebruno:mainfrom
sanish-bruno:fix/example-delete

Conversation

@sanish-bruno
Copy link
Collaborator

@sanish-bruno sanish-bruno commented Dec 30, 2025

Description

example tab not closing post delete, tab not found issue when i delete intermediate example

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
    • When deleting response examples, associated tabs are now automatically closed
    • Example identifiers cache is synchronized when requests are saved, ensuring consistency across operations

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 30, 2025

Walkthrough

When response examples are deleted, associated tabs are now closed via Redux before deletion. A new cache synchronization mechanism rebuilds the example UIDs index whenever requests are saved through IPC, ensuring consistency between examples and cached UIDs.

Changes

Cohort / File(s) Summary
Response Example Deletion Flow
packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/ExampleItem/DeleteResponseExampleModal/index.js
Added event propagation stop to onConfirm and dispatch of closeTabs action with example UID before proceeding with deleteResponseExample and saveRequest dispatches.
Example UIDs Cache Management
packages/bruno-electron/src/cache/requestUids.js
New syncExampleUidsCache(pathname, examples) function that clears and rebuilds example UID cache entries for a given pathname from the provided examples array.
IPC Request Save Handler
packages/bruno-electron/src/ipc/collection.js
Imported syncExampleUidsCache and added invocation in renderer:save-request handler to sync example UID cache with current request examples on each save.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Modal as DeleteResponseExampleModal
    participant Redux as Redux Store
    participant IPC as IPC Handler
    participant Cache as requestUids Cache

    User->>Modal: Click delete example
    Modal->>Modal: e.stopPropagation()
    Modal->>Redux: dispatch closeTabs(exampleUid)
    Modal->>Redux: dispatch deleteResponseExample
    Modal->>Redux: dispatch saveRequest
    
    rect rgba(200, 220, 240, 0.3)
    Note over Redux,IPC: Request persisted via IPC
    end
    
    Redux->>IPC: renderer:save-request
    IPC->>Cache: syncExampleUidsCache(pathname, examples)
    Cache->>Cache: Clear old UID entries<br/>Rebuild from examples
    IPC->>IPC: Save request to disk
    
    rect rgba(200, 240, 200, 0.3)
    Note over Cache: Cache synchronized
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • lohit-bruno
  • bijin-bruno
  • helloanoop

Poem

When examples fade and tabs must close,
The cache springs up to sync its rows—
No orphaned UIDs left behind,
Just harmony of every kind. 🎭✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main fixes: example tab not closing post-delete and tab-not-found errors for intermediate examples.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings

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.

@sanish-bruno sanish-bruno marked this pull request as ready for review December 30, 2025 08:41
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 (2)
packages/bruno-electron/src/ipc/collection.js (1)

363-379: Apply cache sync in batch save operations as well.

The renderer:save-multiple-requests handler doesn't call syncExampleUidsCache, which could leave the cache stale if examples are modified during batch operations. This inconsistency may reintroduce the "tab not found" issue.

🔎 Proposed fix
 ipcMain.handle('renderer:save-multiple-requests', async (event, requestsToSave) => {
   try {
     for (let r of requestsToSave) {
       const request = r.item;
       const pathname = r.pathname;

       if (!fs.existsSync(pathname)) {
         throw new Error(`path: ${pathname} does not exist`);
       }

+      // Sync example UIDs cache to maintain consistency when examples are added/deleted/reordered
+      syncExampleUidsCache(pathname, request.examples);
+
       const content = await stringifyRequestViaWorker(request, { format: r.format });
       await writeFile(pathname, content);
     }
   } catch (error) {
     return Promise.reject(error);
   }
 });
packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/ExampleItem/DeleteResponseExampleModal/index.js (1)

12-22: Remove e.stopPropagation() — it will crash when ENTER key is pressed.

The Modal component calls handleConfirm() without arguments when the ENTER key is pressed (line 94 of Modal/index.js), but your function expects an event parameter and calls e.stopPropagation() unconditionally. This will throw TypeError: Cannot read property 'stopPropagation' of undefined.

Either remove the line entirely (likely unnecessary) or add a guard: e?.stopPropagation?.().

The tab closure order before deletion is correct.

🧹 Nitpick comments (1)
packages/bruno-electron/src/cache/requestUids.js (1)

67-72: Cache rebuild logic is sound.

The function correctly rebuilds the cache using current example indices. The if (example.uid) check is defensive, though silently skipping examples without UIDs could mask issues during development.

Consider logging when an example lacks a UID to aid debugging:

🔎 Optional enhancement
 examples.forEach((example, index) => {
   if (example.uid) {
     exampleUids.set(`${pathname}-${index}`, example.uid);
+  } else {
+    console.warn(`Example at index ${index} for ${pathname} is missing a UID`);
   }
 });
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3a6f2f2 and 7b989c8.

📒 Files selected for processing (3)
  • packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/ExampleItem/DeleteResponseExampleModal/index.js
  • packages/bruno-electron/src/cache/requestUids.js
  • packages/bruno-electron/src/ipc/collection.js
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (CODING_STANDARDS.md)

**/*.{js,jsx,ts,tsx}: Use 2 spaces for indentation. No tabs, just spaces
Stick to single quotes for strings. For JSX/TSX attributes, use double quotes (e.g., )
Always add semicolons at the end of statements
No trailing commas
Always use parentheses around parameters in arrow functions, even for single params
For multiline constructs, put opening braces on the same line, and ensure consistency. Minimum 2 elements for multiline
No newlines inside function parentheses
Space before and after the arrow in arrow functions. () => {} is good
No space between function name and parentheses. func() not func ()
Semicolons go at the end of the line, not on a new line
Names for functions need to be concise and descriptive
Add in JSDoc comments to add more details to the abstractions if needed
Add in meaningful comments instead of obvious ones where complex code flow is explained properly

Files:

  • packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/ExampleItem/DeleteResponseExampleModal/index.js
  • packages/bruno-electron/src/ipc/collection.js
  • packages/bruno-electron/src/cache/requestUids.js
🧠 Learnings (1)
📚 Learning: 2025-12-17T21:41:24.730Z
Learnt from: naman-bruno
Repo: usebruno/bruno PR: 6407
File: packages/bruno-app/src/components/Environments/ConfirmCloseEnvironment/index.js:5-41
Timestamp: 2025-12-17T21:41:24.730Z
Learning: Do not suggest PropTypes validation for React components in the Bruno codebase. The project does not use PropTypes, so reviews should avoid proposing PropTypes and rely on the existing typing/validation approach (e.g., TypeScript or alternative runtime checks) if applicable. This guideline applies broadly to all JavaScript/JSX components in the repo.

Applied to files:

  • packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/ExampleItem/DeleteResponseExampleModal/index.js
  • packages/bruno-electron/src/ipc/collection.js
  • packages/bruno-electron/src/cache/requestUids.js
🧬 Code graph analysis (1)
packages/bruno-electron/src/ipc/collection.js (1)
packages/bruno-electron/src/cache/requestUids.js (1)
  • syncExampleUidsCache (59-73)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Playwright E2E Tests
  • GitHub Check: SSL Tests - macOS
  • GitHub Check: SSL Tests - Windows
  • GitHub Check: Unit Tests
🔇 Additional comments (6)
packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/ExampleItem/DeleteResponseExampleModal/index.js (1)

7-7: LGTM! Import follows existing pattern.

The closeTabs import is correctly placed and follows Redux naming conventions.

packages/bruno-electron/src/ipc/collection.js (2)

54-54: LGTM! Import follows existing pattern.

The syncExampleUidsCache import is correctly placed with related cache utilities.


352-353: Cache sync correctly placed before file write.

The syncExampleUidsCache call ensures UID consistency when examples are modified.

packages/bruno-electron/src/cache/requestUids.js (3)

52-59: LGTM! Well-documented function signature.

JSDoc is comprehensive, and the default parameter provides a safe fallback.


60-65: LGTM! Cache clearing logic is correct.

The prefix-based matching ensures all related entries are removed before rebuilding.


75-81: LGTM! Export follows existing pattern.

The syncExampleUidsCache is correctly added to the module exports.

@bijin-bruno bijin-bruno merged commit d7cef7a into usebruno:main Dec 30, 2025
8 checks passed
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.

2 participants