Skip to content

feature/autoSave (#582) - #6225

Merged
sid-bruno merged 14 commits into
usebruno:feat/autosave-internal-582from
pooja-bruno:add/auto-save-in-pref
Dec 2, 2025
Merged

sid-bruno merged 14 commits into
usebruno:feat/autosave-internal-582from
pooja-bruno:add/auto-save-in-pref

Conversation

@pooja-bruno

@pooja-bruno pooja-bruno commented Nov 27, 2025 •

Copy link
Copy Markdown
Collaborator

Description

JIRA

Contribution Checklist:

  • 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.
Screen.Recording.2025-11-27.at.5.23.33.PM.mov

Summary by CodeRabbit

Release Notes

  • New Features

    • Added Auto Save feature to automatically save requests, folders, and collections at a configurable interval (minimum 500ms).
    • New Auto Save settings in Preferences allow toggling the feature and customizing the save interval.
    • Auto Save persists existing drafts automatically when enabled.
  • Tests

    • Added comprehensive auto save functionality tests.

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

chirag-bruno and others added 7 commits November 26, 2025 17:57
…sebruno#6209)

When jsonwebtoken throws errors inside the NodeVM context, those errors
were instances of the VM's isolated Error class, which caused
instanceOf(Error) checks in tests to fail.

By adding Error constructors (Error, TypeError, ReferenceError,
SyntaxError, RangeError) from the global scope to the scriptContext,
errors thrown by jsonwebtoken and other modules now use the same Error
class that tests check against, ensuring instanceOf checks pass correctly.

This fixes jsonwebtoken test failures when using the NodeVM runtime.
…ebruno#6212)

* feat: add deprecation warnings for presets and post response vars

* refactor: update deprecation warnings for presets and post response vars to include version
* add: opencollection

---------

Co-authored-by: Anoop M D <[email protected]>
@pooja-bruno
pooja-bruno marked this pull request as ready for review November 28, 2025 08:08
@sid-bruno

Copy link
Copy Markdown
Collaborator

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Dec 2, 2025

Copy link
Copy Markdown
Contributor
✅ Actions performed

Full review triggered.

@coderabbitai

coderabbitai Bot commented Dec 2, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

This PR introduces an Auto Save feature allowing users to enable automatic persistence of draft changes. The implementation spans preferences UI configuration, Redux middleware for intercepting and debouncing save actions, updated action signatures to support silent notifications, theme styling additions, and comprehensive end-to-end test coverage validating the feature across multiple scenarios.

Changes

Cohort / File(s) Summary
Preferences UI & Configuration
packages/bruno-app/src/components/Preferences/General/index.js, packages/bruno-electron/src/store/preferences.js
Added Auto Save checkbox and interval input controls to preferences with validation schema (enabled flag, interval ≥ 500ms), persisted to Redux and Electron store
Redux Core
packages/bruno-app/src/providers/ReduxStore/index.js, packages/bruno-app/src/providers/ReduxStore/slices/app.js
Integrated autosaveMiddleware into middleware pipeline; added autoSave.enabled and autoSave.interval to initial app state (default: disabled, 1000ms)
Auto Save Middleware
packages/bruno-app/src/providers/ReduxStore/middlewares/autosave/middleware.js
New middleware that intercepts collection/request/folder mutations, debounces saves per entity, and triggers draft persistence using configurable intervals
Collection Actions
packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js
Added silent parameter (default false) to saveRequest(), saveFolderRoot(), and saveCollectionSettings() to conditionally suppress success toast notifications
Themes
packages/bruno-app/src/themes/dark.js, packages/bruno-app/src/themes/light.js
Added preferences.sidebar.border color definitions (dark: '#444444', light: '#EFEFEF')
Component Updates
packages/bruno-app/src/components/RequestPane/QueryUrl/index.js
Changed onSave callback signature from (finalValue) to () (parameter no longer used)
Test Suite
tests/preferences/autosave/autosave.spec.ts
Comprehensive Playwright tests covering: enable/disable auto save, draft persistence, auto-save debounce behavior, and existing draft handling on preference toggle

Sequence Diagram

sequenceDiagram
    actor User
    participant UI as Preferences UI
    participant Redux as Redux Store
    participant Middleware as AutoSave Middleware
    participant Action as Collection Actions
    participant Disk as File System

    User->>UI: Enable Auto Save + Set Interval
    UI->>Redux: Dispatch updatePreferences(autoSave)
    Redux->>Middleware: dispatch app/updatePreferences
    Middleware->>Middleware: saveExistingDrafts()
    Middleware->>Action: Trigger save actions (silent: true)
    Action->>Disk: Persist existing drafts

    User->>UI: Edit Request URL
    UI->>Redux: Dispatch collection/setActiveRequestDraft
    Redux->>Middleware: Intercept action
    Middleware->>Middleware: scheduleAutoSave() (debounce)
    Note over Middleware: Wait (interval ms)
    Middleware->>Action: Trigger saveRequest(silent: true)
    Action->>Disk: Persist draft changes
    UI->>UI: Clear draft indicator
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~35 minutes

  • Middleware logic: The autosaveMiddleware contains debouncing logic, entity type detection, and state scanning that requires careful review for correctness
  • Action signature changes: Verify all callsites of saveRequest(), saveFolderRoot(), and saveCollectionSettings() respect the new silent parameter semantics
  • State initialization: Confirm autoSave preferences are properly initialized across Redux and Electron stores with consistent defaults
  • Test coverage: Validate the test suite captures all edge cases (enable/disable toggles, existing drafts, debounce behavior, persistence verification)

Poem

✨ Drafts now save themselves with grace,
No manual work to keep their place.
Auto persistence, debounced and clean,
The finest auto-save you've ever seen! 🚀

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 identifies the main feature being added: autosave functionality. It directly relates to the primary changeset objective.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

@sid-bruno
sid-bruno changed the base branch from main to feat/autosave-internal-582 December 2, 2025 08:14
@sid-bruno
sid-bruno merged commit 4ce5deb into usebruno:feat/autosave-internal-582 Dec 2, 2025

@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: 1

🧹 Nitpick comments (5)
packages/bruno-app/src/components/RequestPane/QueryUrl/index.js (1)

113-113: Simplify the onSave callback.

Since onSave no longer accepts parameters, you can simplify this:

-          onSave={(finalValue) => onSave(finalValue)}
+          onSave={onSave}
tests/preferences/autosave/autosave.spec.ts (3)

50-66: Consider using Playwright's built-in waiting mechanisms.

At line 62, page.waitForTimeout(1000) is used to wait for autosave. While this works for time-based behavior, consider using Playwright's expect() with a timeout option for better reliability:

-      // Wait for autosave to trigger (interval + some buffer)
-      await page.waitForTimeout(1000);
-
-      // Verify draft indicator disappears after autosave
-      await expect(requestTab.locator('.has-changes-icon')).not.toBeVisible();
+      // Verify draft indicator disappears after autosave (with timeout for autosave interval)
+      await expect(requestTab.locator('.has-changes-icon')).not.toBeVisible({ timeout: 2000 });

This approach waits for the condition rather than a fixed time, making the test more robust and potentially faster.

As per coding guidelines, reduce usage of page.waitForTimeout() where possible.


101-121: Optional: Reduce timeout for negative assertion.

At line 113, the timeout of 1500ms could be reduced slightly since we're testing that autosave doesn't trigger. Consider 1200ms (interval + 20% buffer) for a faster test while still providing sufficient validation time.

-      // Wait a bit (longer than autosave interval would be)
-      await page.waitForTimeout(1500);
+      // Wait longer than autosave interval to verify it doesn't trigger
+      await page.waitForTimeout(1200);

As per coding guidelines, minimize timeout durations where practical.


159-182: Consider using Playwright's built-in waiting mechanisms.

At line 177, page.waitForTimeout(1000) is used to wait for autosave of the existing draft. Similar to the first test, consider using Playwright's expect() with a timeout:

-      // Wait for autosave to trigger for existing draft
-      await page.waitForTimeout(1000);
-
-      // Verify draft indicator disappears (existing draft was auto-saved)
+      // Verify draft indicator disappears after autosave of existing draft (with timeout)
       const requestTab = page.locator('.request-tab').filter({ has: page.locator('.tab-label', { hasText: 'Draft Request' }) });
-      await expect(requestTab.locator('.has-changes-icon')).not.toBeVisible();
+      await expect(requestTab.locator('.has-changes-icon')).not.toBeVisible({ timeout: 2000 });

As per coding guidelines, reduce usage of page.waitForTimeout() where possible.

packages/bruno-app/src/providers/ReduxStore/middlewares/autosave/middleware.js (1)

77-90: Consider adding error handling for save operations.

The scheduleAutoSave function implements debouncing correctly, but the save() call at line 87 lacks error handling. If a save operation fails, it could result in an unhandled promise rejection.

 const scheduleAutoSave = (key, save, interval) => {
   // Clear any existing timer for this entity
   clearTimeout(pendingTimers[key]);

   // Schedule a new save
   pendingTimers[key] = setTimeout(() => {
-    save();
+    save().catch((err) => {
+      console.error('Autosave failed:', err);
+      // Error is already handled in save actions (toast.error), but log for debugging
+    });
     delete pendingTimers[key];
   }, interval);
 };

Note: The save actions already handle errors with toasts, but catching here prevents unhandled promise rejections in the console.

📜 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 6e88671 and 3906c28.

📒 Files selected for processing (10)
  • packages/bruno-app/src/components/Preferences/General/index.js (4 hunks)
  • packages/bruno-app/src/components/RequestPane/QueryUrl/index.js (1 hunks)
  • packages/bruno-app/src/providers/ReduxStore/index.js (1 hunks)
  • packages/bruno-app/src/providers/ReduxStore/middlewares/autosave/middleware.js (1 hunks)
  • packages/bruno-app/src/providers/ReduxStore/slices/app.js (1 hunks)
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js (6 hunks)
  • packages/bruno-app/src/themes/dark.js (1 hunks)
  • packages/bruno-app/src/themes/light.js (1 hunks)
  • packages/bruno-electron/src/store/preferences.js (2 hunks)
  • tests/preferences/autosave/autosave.spec.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{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
Always add semicolons at the end of statements
No trailing commas
Always use parentheses around parameters in arrow functions, even for single parameters
For multiline constructs, put opening braces on the same line, and ensure consistency. Minimum 2 elements for multiline
No newlines inside function parentheses. Keep 'em tight
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
Avoid single line abstractions where all that's being done is increasing the call stack with one additional function
Add in meaningful comments instead of obvious ones where complex code flow is explained properly

Files:

  • tests/preferences/autosave/autosave.spec.ts
  • packages/bruno-app/src/components/RequestPane/QueryUrl/index.js
  • packages/bruno-app/src/themes/light.js
  • packages/bruno-app/src/providers/ReduxStore/slices/app.js
  • packages/bruno-electron/src/store/preferences.js
  • packages/bruno-app/src/providers/ReduxStore/middlewares/autosave/middleware.js
  • packages/bruno-app/src/components/Preferences/General/index.js
  • packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js
  • packages/bruno-app/src/themes/dark.js
  • packages/bruno-app/src/providers/ReduxStore/index.js
tests/**/**.*

⚙️ CodeRabbit configuration file

tests/**/**.*: Review the following e2e test code written using the Playwright test library. Ensure that:

  • Follow best practices for Playwright code and e2e automation

  • Try to reduce usage of page.waitForTimeout(); in code unless absolutely necessary and the locator cannot be found using existing expect() playwright calls

  • Avoid using page.pause() in code

  • Use locator variables for locators

  • Avoid using test.only

  • Use multiple assertions

  • Promote the use of test.step as much as possible so the generated reports are easier to read

  • Ensure that the fixtures like the collections are nested inside the fixtures folder

    Fixture Example*: Here's an example of possible fixture and test pair

    .
    ├── fixtures
    │   └── collection
    │       ├── base.bru
    │       ├── bruno.json
    │       ├── collection.bru
    │       ├── ws-test-request-with-headers.bru
    │       ├── ws-test-request-with-subproto.bru
    │       └── ws-test-request.bru
    ├── connection.spec.ts # <- Depends on the collection in ./fixtures/collection
    ├── headers.spec.ts
    ├── persistence.spec.ts
    ├── variable-interpolation
    │   ├── fixtures
    │   │   └── collection
    │   │       ├── environments
    │   │       ├── bruno.json
    │   │       └── ws-interpolation-test.bru
    │   ├── init-user-data
    │   └── variable-interpolation.spec.ts # <- Depends on the collection in ./variable-interpolation/fixtures/collection
    └── subproto.spec.ts
    

Files:

  • tests/preferences/autosave/autosave.spec.ts
🧬 Code graph analysis (5)
tests/preferences/autosave/autosave.spec.ts (1)
tests/utils/page/actions.ts (2)
  • closeAllCollections (130-130)
  • createRequest (130-130)
packages/bruno-app/src/components/RequestPane/QueryUrl/index.js (7)
packages/bruno-app/src/components/RequestPane/GrpcBody/index.js (1)
  • onSave (56-56)
packages/bruno-app/src/components/CollectionSettings/Vars/VarsTable/index.js (1)
  • onSave (31-31)
packages/bruno-app/src/components/FolderSettings/Vars/VarsTable/index.js (1)
  • onSave (28-28)
packages/bruno-app/src/components/RequestPane/RequestHeaders/index.js (1)
  • onSave (35-35)
packages/bruno-app/src/components/RequestPane/Vars/VarsTable/index.js (1)
  • onSave (30-30)
packages/bruno-app/src/components/RequestPane/GraphQLVariables/index.js (1)
  • onSave (48-48)
packages/bruno-app/src/components/RequestPane/GraphQLRequestPane/index.js (1)
  • onSave (52-52)
packages/bruno-app/src/providers/ReduxStore/middlewares/autosave/middleware.js (1)
packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js (6)
  • saveCollectionSettings (2133-2172)
  • saveCollectionSettings (2133-2172)
  • saveRequest (97-135)
  • saveRequest (97-135)
  • saveFolderRoot (199-242)
  • saveFolderRoot (199-242)
packages/bruno-app/src/components/Preferences/General/index.js (3)
packages/bruno-app/src/components/Sidebar/CreateCollection/index.js (1)
  • formik (32-65)
packages/bruno-app/src/components/GlobalEnvironments/EnvironmentSettings/CreateEnvironment/index.js (1)
  • formik (21-49)
packages/bruno-app/src/components/Preferences/Display/Theme/index.js (1)
  • formik (10-21)
packages/bruno-app/src/providers/ReduxStore/index.js (2)
packages/bruno-app/src/providers/App/useTelemetry.js (1)
  • isDevEnv (21-23)
packages/bruno-app/src/providers/ReduxStore/middlewares/autosave/middleware.js (2)
  • autosaveMiddleware (119-161)
  • autosaveMiddleware (119-161)
🔇 Additional comments (19)
packages/bruno-app/src/providers/ReduxStore/slices/app.js (1)

31-35: LGTM!

The autoSave defaults align with the Electron store's defaultPreferences. Initial state is correctly structured.

packages/bruno-app/src/components/RequestPane/QueryUrl/index.js (1)

36-38: LGTM!

The parameterless onSave signature is consistent with other components in the codebase (e.g., GrpcBody, QueryParams, RequestHeaders, etc.).

packages/bruno-app/src/components/Preferences/General/index.js (4)

75-78: LGTM!

Initial values correctly default to false and 1000, matching the Redux store's initial state.


109-118: LGTM!

The autoSave object is correctly structured for persistence and the semicolon addition aligns with coding guidelines.


280-313: LGTM!

UI controls are well-structured with proper accessibility attributes, disabled state handling, and error display logic.


321-321: LGTM!

Adding the id attribute improves accessibility by properly linking the label to the input.

packages/bruno-electron/src/store/preferences.js (2)

52-56: LGTM!

Default values are consistent with the Redux store's initial state.


100-104: Note: Validation minimum differs from frontend.

As noted in the frontend review, this schema allows min(100) while the UI enforces >= 500. Align these values for consistency.

packages/bruno-app/src/providers/ReduxStore/index.js (2)

12-12: LGTM!

Import correctly references the named export from the autosave middleware module.


18-18: LGTM!

Middleware ordering is correct. The autosaveMiddleware is positioned after draftDetectMiddleware, ensuring it observes draft state changes properly.

packages/bruno-app/src/themes/light.js (1)

490-494: LGTM!

The addition of the preferences sidebar border color follows the existing theme structure and naming conventions. The color value is appropriate for the light theme.

packages/bruno-app/src/themes/dark.js (1)

483-487: LGTM!

The dark theme preferences sidebar border addition mirrors the light theme structure with an appropriate darker color value.

tests/preferences/autosave/autosave.spec.ts (1)

4-198: Well-structured test suite with good use of test.step.

The test structure follows best practices:

  • Excellent use of test.step for readable test reports
  • Consistent locator variable usage
  • Multiple assertions per test
  • Proper cleanup in afterEach
  • No test.only or page.pause() detected

The tests comprehensively cover the autosave feature including enabling/disabling, persistence, and existing drafts scenarios.

As per coding guidelines, the test structure promotes readability and maintainability.

packages/bruno-app/src/providers/ReduxStore/middlewares/autosave/middleware.js (3)

4-75: LGTM! Comprehensive action interception list.

The actionsToIntercept array is well-organized with clear categorization (request-level, folder-level, collection-level). The list covers all relevant mutation actions that should trigger autosave.


92-117: LGTM! Comprehensive existing drafts detection.

The saveExistingDrafts function correctly:

  • Iterates through all collections, requests, and folders
  • Detects drafts at all levels
  • Schedules appropriate save actions with the silent flag
  • Uses utility functions (flattenItems, isItemARequest, isItemAFolder) properly

119-161: LGTM! Well-structured middleware implementation.

The autosaveMiddleware correctly:

  • Updates state before processing (calling next(action) first)
  • Checks autosave enabled status
  • Handles existing drafts when autosave is enabled
  • Filters for relevant actions
  • Determines the correct save operation based on payload structure
  • Uses debouncing via scheduleAutoSave

The if-else logic at lines 142-154 correctly prioritizes the most specific entity type (request > folder > collection).

packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js (3)

97-135: LGTM! Clean implementation of silent parameter.

The saveRequest function correctly:

  • Adds silent parameter with default value false (backward compatible)
  • Conditionally displays success toast only when not silent
  • Maintains error toast visibility regardless of silent flag

This enables autosave to save requests without showing success notifications while preserving error visibility for debugging.


199-242: LGTM! Consistent implementation of silent parameter.

The saveFolderRoot function follows the same pattern as saveRequest:

  • Silent parameter added with default false
  • Success toast conditional on silent flag
  • Error toast always visible

The implementation is consistent and correct.


2133-2172: LGTM! Consistent silent parameter implementation.

The saveCollectionSettings function completes the pattern:

  • Silent parameter with default false
  • Conditional success toast
  • Unconditional error toast

All three save actions (saveRequest, saveFolderRoot, saveCollectionSettings) now consistently support silent mode for autosave functionality.

Comment on lines +40 to +58
autoSave: Yup.object({
enabled: Yup.boolean(),
interval: Yup.mixed()
.transform((value, originalValue) => {
return originalValue === '' ? undefined : value;
})
.test('isNumber', 'Save Delay must be a number', (value) => {
return value === undefined || !isNaN(value);
})
.test('isValidInterval', 'Save Delay must be at least 500ms', (value) => {
return value === undefined || Number(value) >= 500;
})
}).test('intervalRequired', 'Save Delay is required when Auto Save is enabled', (value) => {
// If autosave is enabled, interval must be provided
if (value.enabled && (value.interval === undefined || value.interval === '')) {
return false;
}
return true;
}),

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.

⚠️ Potential issue | 🟡 Minor

Validation mismatch: Frontend requires 500ms minimum, backend allows 100ms.

The frontend schema enforces >= 500 (line 50), but packages/bruno-electron/src/store/preferences.js allows min(100). This inconsistency could cause confusion or allow values saved via other means to fail frontend validation on reload.

Consider aligning both to the same minimum threshold.

🤖 Prompt for AI Agents
In packages/bruno-app/src/components/Preferences/General/index.js around lines
40 to 58 the Yup schema enforces a minimum autoSave.interval of 500ms which
conflicts with the backend preference
(packages/bruno-electron/src/store/preferences.js) that allows 100ms; update the
frontend validation to match the backend by changing the isValidInterval test to
require Number(value) >= 100 (or alternatively update the backend to 500 if you
intend to raise the global minimum) so both sides use the same minimum
threshold.

@coderabbitai coderabbitai Bot mentioned this pull request Dec 6, 2025
6 tasks
@coderabbitai coderabbitai Bot mentioned this pull request Dec 12, 2025
4 of 6 tasks
@coderabbitai coderabbitai Bot mentioned this pull request Jan 12, 2026
5 of 6 tasks
@coderabbitai coderabbitai Bot mentioned this pull request Apr 1, 2026
6 tasks
maxenceleblanc pushed a commit to maxenceleblanc/curly_cats2 that referenced this pull request Jul 20, 2026
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.

6 participants