Skip to content

fix: stabilize tray panel resizing - #36

Merged
Finesssee merged 2 commits into
mainfrom
codex/fix-issue-35-window-jump
Apr 24, 2026
Merged

Finesssee merged 2 commits into
mainfrom
codex/fix-issue-35-window-jump

Conversation

@Finesssee

@Finesssee Finesssee commented Apr 24, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Prevent the visible tray panel from expanding to max height during delayed provider refresh resize passes
  • Cancel stale tray resize runs and restore temporary measurement styles safely
  • Hide the tray menu after opening Settings/About and remove stale smooth-scroll on provider selection

Fixes #35

Tests

  • npm run build
  • npm test
  • cargo test --manifest-path apps/desktop-tauri/src-tauri/Cargo.toml shell::tests

Note

Medium Risk
Touches Tauri window sizing/measurement and DOM style mutation logic, which can easily introduce regressions like incorrect tray sizing or flicker across platforms, but does not affect security or data handling.

Overview
Prevents the tray popover from visibly "bouncing" to MAX_HEIGHT during subsequent provider refreshes by only doing the expand-to-measure step on the initial hidden layout pass, and by cancelling stale resize runs with a run counter.

Hardens the resize measurement path by snapshotting/restoring temporary overflow/flex styles in a finally block, and simplifies the delayed resize scheduling to a single timeout.

Updates tray actions so opening Settings/About closes the tray window afterward, and removes the smooth-scroll-to-card behavior when selecting a provider from the grid.

Reviewed by Cursor Bugbot for commit acd6682. Configure here.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Stale run's finally block corrupts concurrent resize measurement
    • Moved original style snapshot to a shared ref (only captured when no measurement is in progress) and gated the finally block's style restoration on the run still being the latest, so stale runs no longer corrupt the DOM for active concurrent runs.

Create PR

Or push these changes by commenting:

@cursor push 6d8296b267
Preview (6d8296b267)
diff --git a/apps/desktop-tauri/src/surfaces/TrayPanel.tsx b/apps/desktop-tauri/src/surfaces/TrayPanel.tsx
--- a/apps/desktop-tauri/src/surfaces/TrayPanel.tsx
+++ b/apps/desktop-tauri/src/surfaces/TrayPanel.tsx
@@ -76,6 +76,16 @@
   const [layoutReady, setLayoutReady] = useState(false);
   const layoutReadyRef = useRef(false);
   const resizeRunRef = useRef(0);
+  const originalStylesRef = useRef<{
+    htmlOverflow: string;
+    bodyOverflow: string;
+    bodyMinHeight: string;
+    surfaceMaxHeight: string;
+    surfaceOverflow: string;
+    bodyInnerOverflow: string | undefined;
+    bodyFlex: string | undefined;
+    stackOverflow: string | undefined;
+  } | null>(null);
 
   // Cards to display based on mode
   // Overview: all providers in the grid — non-error first, then errors
@@ -115,16 +125,21 @@
       const body = surface.querySelector<HTMLElement>(".menu-surface__body");
       const stack = surface.querySelector<HTMLElement>(".menu-stack");
 
-      const previous = {
-        htmlOverflow: document.documentElement.style.overflow,
-        bodyOverflow: document.body.style.overflow,
-        bodyMinHeight: document.body.style.minHeight,
-        surfaceMaxHeight: surface.style.maxHeight,
-        surfaceOverflow: surface.style.overflow,
-        bodyInnerOverflow: body?.style.overflow,
-        bodyFlex: body?.style.flex,
-        stackOverflow: stack?.style.overflow,
-      };
+      // Only capture original styles if no other run already has them saved.
+      // This prevents a later run from snapshotting the measurement styles
+      // applied by an earlier concurrent run.
+      if (!originalStylesRef.current) {
+        originalStylesRef.current = {
+          htmlOverflow: document.documentElement.style.overflow,
+          bodyOverflow: document.body.style.overflow,
+          bodyMinHeight: document.body.style.minHeight,
+          surfaceMaxHeight: surface.style.maxHeight,
+          surfaceOverflow: surface.style.overflow,
+          bodyInnerOverflow: body?.style.overflow,
+          bodyFlex: body?.style.flex,
+          stackOverflow: stack?.style.overflow,
+        };
+      }
       let committedHeight = false;
 
       document.documentElement.style.overflow = "visible";
@@ -181,20 +196,27 @@
           setLayoutReady(true);
         }
       } finally {
-        if (!committedHeight) {
-          surface.style.maxHeight = previous.surfaceMaxHeight;
+        // Only restore styles if this is still the latest run.
+        // A stale run must not touch the DOM — a newer run is still
+        // using the measurement styles and will handle cleanup itself.
+        if (run === resizeRunRef.current) {
+          const previous = originalStylesRef.current!;
+          originalStylesRef.current = null;
+          if (!committedHeight) {
+            surface.style.maxHeight = previous.surfaceMaxHeight;
+          }
+          surface.style.overflow = previous.surfaceOverflow;
+          document.documentElement.style.overflow = previous.htmlOverflow;
+          document.body.style.overflow = previous.bodyOverflow;
+          document.body.style.minHeight = previous.bodyMinHeight;
+          if (body) {
+            body.style.overflow = previous.bodyInnerOverflow ?? "";
+            body.style.flex = previous.bodyFlex ?? "";
+          }
+          if (stack) {
+            stack.style.overflow = previous.stackOverflow ?? "";
+          }
         }
-        surface.style.overflow = previous.surfaceOverflow;
-        document.documentElement.style.overflow = previous.htmlOverflow;
-        document.body.style.overflow = previous.bodyOverflow;
-        document.body.style.minHeight = previous.bodyMinHeight;
-        if (body) {
-          body.style.overflow = previous.bodyInnerOverflow ?? "";
-          body.style.flex = previous.bodyFlex ?? "";
-        }
-        if (stack) {
-          stack.style.overflow = previous.stackOverflow ?? "";
-        }
       }
     };

You can send follow-ups to the cloud agent here.

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit acd6682. Configure here.

}
if (stack) {
stack.style.overflow = previous.stackOverflow ?? "";
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale run's finally block corrupts concurrent resize measurement

Medium Severity

When two resize() calls run concurrently (likely during initial load while providers update), the stale run's finally block restores DOM styles to their original values, undoing the measurement styles that the active run still needs. The active run then measures content with wrong styles (constrained overflow/maxHeight), producing an incorrect panel height. Worse, the active run's previous captured the measurement styles (set by the earlier run), so its own finally permanently leaves the page with overflow: "visible" instead of the original values.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit acd6682. Configure here.

@Finesssee

Copy link
Copy Markdown
Collaborator Author

Windows VPS validation on EC2AMAZ-H83BO7S (100.101.191.102) completed for commit acd6682f in isolated worktree C:\Users\Administrator\Win-CodexBar-pr36.

Checks passed:

  • npm run build
  • npm test (27 tests)
  • cargo test --manifest-path apps/desktop-tauri/src-tauri/Cargo.toml shell::tests (25 tests)
  • npm run tauri:build:debug built target\debug\codexbar-desktop-tauri.exe

Smoke proof run:

  • launched PR build with CODEXBAR_PROOF_MODE=trayPanel and captured qa-pr36/tray-panel.png
  • launched PR build with CODEXBAR_PROOF_MODE=settings:general and captured qa-pr36/settings-general.png
  • restored the existing installed codexbar-0.22.0.exe process afterward

Notes: the settings screenshot was partially overlapped by the active terminal window on the VPS desktop, but the proof process launched, rendered, exited cleanly, and the installed app restarted. The tray screenshot showed the panel at a stable measured height rather than bouncing to max height.

@Finesssee

Copy link
Copy Markdown
Collaborator Author

Expanded Windows validation completed on EC2AMAZ-H83BO7S for current PR head 1a706096.

Additional checks passed:

  • cargo fmt --all -- --check
  • cargo test --manifest-path apps/desktop-tauri/src-tauri/Cargo.toml (171 tests)
  • cargo test --manifest-path rust/Cargo.toml (226 tests + doc tests)
  • cargo clippy --manifest-path apps/desktop-tauri/src-tauri/Cargo.toml --all-targets -- -D warnings
  • cargo clippy --manifest-path rust/Cargo.toml --all-targets -- -D warnings (passed before the DWM cleanup; no shared Rust changes after that)
  • npm run tauri:build produced target\release\codexbar-desktop-tauri.exe

Follow-up commit added during validation:

  • 1a706096 chore: satisfy windows dwm clippy fixes two Windows-only clippy warnings in the DWM helper (MARGINS acronym name and a no-op isize cast). No behavior change.

Release executable smoke at current head:

  • launched target\release\codexbar-desktop-tauri.exe with CODEXBAR_PROOF_MODE=trayPanel and captured qa-pr36-final/release-tray-panel.png
  • launched the same release exe with CODEXBAR_PROOF_MODE=settings:general and captured qa-pr36-final/release-settings-general.png
  • restarted installed C:\Users\Administrator\codexbar-0.22.0.exe afterward

One attempted deeper scheduled click smoke hung before writing evidence, so I killed/deleted that scheduled task and verified the installed app was restored. The reliable proof-mode release smoke above passed.

@Finesssee

Copy link
Copy Markdown
Collaborator Author

One more validation pass completed on Windows VPS at current head 1a706096.

Repeat checks passed:

  • confirmed remote worktree is at 1a706096 chore: satisfy windows dwm clippy
  • npm run build
  • npm test (27 tests)
  • cargo fmt --all -- --check
  • cargo test --manifest-path apps/desktop-tauri/src-tauri/Cargo.toml (171 tests)
  • cargo clippy --manifest-path apps/desktop-tauri/src-tauri/Cargo.toml --all-targets -- -D warnings
  • npm run tauri:build produced target\release\codexbar-desktop-tauri.exe again

Repeat release smoke passed:

  • CODEXBAR_PROOF_MODE=trayPanel captured qa-pr36-repeat/repeat-release-tray-panel.png
  • CODEXBAR_PROOF_MODE=settings:general captured qa-pr36-repeat/repeat-release-settings-general.png
  • installed C:\Users\Administrator\codexbar-0.22.0.exe restarted afterward and is running in session 8

Cleaned scheduled task after the run. Remote worktree only has evidence folders left untracked (qa-pr36/, qa-pr36-final/, qa-pr36-repeat/).

@Finesssee
Finesssee merged commit 35f4bd3 into main Apr 24, 2026
10 checks passed
@Finesssee
Finesssee deleted the codex/fix-issue-35-window-jump branch April 24, 2026 05:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0.22.0 running unstable

1 participant