Skip to content

fix: lag when moving Electron window (issue #5203)#6771

Merged
bijin-bruno merged 1 commit intousebruno:mainfrom
qweme32:bugfix/window-lags-5203
Jan 20, 2026
Merged

fix: lag when moving Electron window (issue #5203)#6771
bijin-bruno merged 1 commit intousebruno:mainfrom
qweme32:bugfix/window-lags-5203

Conversation

@qweme32
Copy link
Contributor

@qweme32 qweme32 commented Jan 10, 2026

Description

This PR fixes the lag when moving the Electron window reported in issue #5203.
The problem was caused by continuously saving the window position on every move event, which led to performance issues.

To solve this, I added a debounced timeout so the window position is saved only after movement stops, instead of on every frame.
This significantly improves window movement smoothness and removes the lag.

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
    • Improved window state management performance by reducing save operation frequency during window resizing and moving, resulting in a more responsive user experience.

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 10, 2026

Walkthrough

The change introduces debouncing to window bounds persistence by wrapping the saveBounds() call in a 100ms debounce mechanism. Instead of saving window boundaries synchronously on every resize/move event, the call is now deferred and consolidated when the window is not maximized, reducing unnecessary I/O operations.

Changes

Cohort / File(s) Summary
Window State Optimization
packages/bruno-electron/src/index.js
Adds debounce pattern to window bounds saving with 100ms timeout; prevents excessive synchronous saves during resize/move events

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested reviewers

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

Poem

Bounds bounce no more with every flick,
A debounce does the clever trick,
One hundred mills to let it rest,
Window state saved with finesse ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title accurately describes the main change: adding debounce to fix window movement lag, and references the related issue #5203.

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

✨ 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.

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

🧹 Nitpick comments (2)
packages/bruno-electron/src/index.js (2)

224-233: Excellent debounce implementation that addresses the lag issue.

The trailing debounce pattern is correctly implemented and will eliminate the performance problem of saving on every move event. The 100ms delay is well-chosen for this use case.

♻️ Optional: Add maximized check inside timeout for edge case

For additional robustness, consider checking the maximized state inside the timeout callback as well, in case the window is maximized during the 100ms delay:

 const handleBoundsChange = () => {
-  if (!mainWindow.isMaximized()) {
-    if (boundsTimeout) {
-      clearTimeout(boundsTimeout);
-    }
-    boundsTimeout = setTimeout(() => {
+  if (boundsTimeout) {
+    clearTimeout(boundsTimeout);
+  }
+  boundsTimeout = setTimeout(() => {
+    if (!mainWindow.isMaximized()) {
       saveBounds(mainWindow);
-    }, 100);
-  }
+    }
+  }, 100);
 };

This ensures bounds are only saved if the window is still not maximized when the timeout fires.


224-233: Consider cleanup on window lifecycle events.

While not critical, clearing the timeout on window close and maximize events would be more defensive.

♻️ Optional: Add timeout cleanup

On window close (around line 258):

 mainWindow.on('close', (e) => {
   e.preventDefault();
+  if (boundsTimeout) {
+    clearTimeout(boundsTimeout);
+  }
   terminalManager.cleanup(mainWindow.webContents);
   ipcMain.emit('main:start-quit-flow');
 });

On maximize (around line 239):

 mainWindow.on('maximize', () => {
+  if (boundsTimeout) {
+    clearTimeout(boundsTimeout);
+  }
   saveMaximized(true);
   mainWindow.webContents.send('main:window-maximized');
 });
📜 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 33594bd and 63f8ad6.

📒 Files selected for processing (1)
  • packages/bruno-electron/src/index.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-electron/src/index.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-electron/src/index.js
🧬 Code graph analysis (1)
packages/bruno-electron/src/index.js (1)
packages/bruno-js/src/sandbox/quickjs/shims/bruno-request.js (1)
  • setTimeout (115-117)
⏰ 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). (6)
  • GitHub Check: SSL Tests - macOS
  • GitHub Check: SSL Tests - Linux
  • GitHub Check: Unit Tests
  • GitHub Check: SSL Tests - Windows
  • GitHub Check: CLI Tests
  • GitHub Check: Playwright E2E Tests
🔇 Additional comments (1)
packages/bruno-electron/src/index.js (1)

223-223: LGTM! Good scope for the timeout variable.

The variable is appropriately scoped to the window lifecycle within the 'ready' callback.

@qweme32 qweme32 mentioned this pull request Jan 10, 2026
5 tasks
@qweme32 qweme32 changed the title Fix lag when moving Electron window (issue #5203) fix: lag when moving Electron window (issue #5203) Jan 11, 2026
@bijin-bruno bijin-bruno merged commit 81faa57 into usebruno:main Jan 20, 2026
8 checks passed
FraCata00 pushed a commit to FraCata00/bruno that referenced this pull request Feb 9, 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.

3 participants