Skip to content

fix(tray): stop auto-fit ResizeObserver feedback loop - #352

Merged
Finesssee merged 1 commit into
nesszer:mainfrom
MiguelMachado-dev:fix/tray-autofit-observer-feedback
Aug 22, 2026
Merged

Finesssee merged 1 commit into
nesszer:mainfrom
MiguelMachado-dev:fix/tray-autofit-observer-feedback

Conversation

@MiguelMachado-dev

Copy link
Copy Markdown

Summary

  • Stop auto-fit measurement style changes from recursively scheduling another layout pass through the tray surface's ResizeObserver.
  • Keep observer-driven sizing enabled until the initial layout converges, so a newly created flyout still reaches its normal size.
  • Add a deterministic style-feedback regression test that fails on main before the hook fix and settles after it.

The auto-fit pass temporarily removes height and overflow constraints to measure the full surface. On the affected Windows/WebView2 setup, the observer saw those programmatic changes and re-entered auto-fit indefinitely, making the Pop Out Dashboard alternate between measured and committed layouts. This is a separate feedback path from the fractional-DPI native-size cycle handled in #272.

Related issue

Follow-up to #261 and #272.

Affected areas

  • Tray panel
  • Settings UI
  • Config file / settings persistence
  • CLI
  • Provider-specific behavior
  • Installer / release packaging
  • Startup / background behavior
  • Documentation
  • Other: detached Pop Out Dashboard flyout

Validation

  • powershell.exe -ExecutionPolicy Bypass -NoProfile -File scripts\local-check.ps1
    • Shared Rust: 1,293 tests passed
    • Tauri Rust: 353 tests passed
    • Frontend: 44 files / 269 tests passed
    • Frontend TypeScript/Vite build passed
    • Formatting and clippy gates passed
  • Full pre-release validation: not applicable; no packaging or release changes
  • Installer/release validation: not applicable
  • Thermo-nuclear code quality review completed before submitting
  • Focused red/green test: the new test fails before the hook change (3 reveal calls instead of settled 2) and all 3 sizing tests pass afterward
  • Fresh Windows debug build: pnpm --dir apps\desktop-tauri run tauri:build:debug

UI / tray proof

  • Not applicable
  • CUA Driver visual proof attached
  • CUA Driver could not be used; equivalent manual proof and explanation attached

CUA Driver is not installed on the test machine (%LOCALAPPDATA%\Programs\Cua\cua-driver\bin\cua-driver.exe is absent), so I used equivalent native Windows/WebView2 proof against a fresh debug build from this branch:

  • 12-second CDP sample, 2,160 animation frames: 0 body, surface, max-height, or native inner-height transitions; 1 ResizeObserver callback
  • 14-second desktop capture, 180 frames: 1 unique frame, 0 frame transitions, 0 single-frame flicker pulses, 1 native window geometry
  • Flyout remained 328 x 920
  • No bogus tiny remembered flyout size was persisted

For comparison, the affected build produced roughly 160 body/surface height transitions and about 240 observer callbacks in 12 seconds, plus 37 one-frame visual pulses in 12.6 seconds.

Notes for reviewers

The layoutReadyRef.current guard is intentional: observer callbacks remain active during first-open convergence, then callbacks caused by the hook's own measurement pass are ignored while programmaticInFlightRef is active. This preserves initial auto-fit and avoids misclassifying the hidden window's tiny bootstrap frame as a user-resized size.

The diff is limited to useTrayPanelLayout.ts and its sizing test; it contains no Rust/backend or local process-discovery changes.

@Finesssee

Copy link
Copy Markdown
Collaborator

Hey, thanks for the PR, I will review this ASAP.

@Finesssee

Copy link
Copy Markdown
Collaborator

Thermo-Nuclear Code Quality Review — APPROVE

Verdict

Minimal, correct fix at the right site using existing state. No structural debt added.

Findings

1. Structural regressions — None. The 6-line guard reuses two refs that were already tracking exactly the right state: layoutReadyRef (initial convergence done?) and programmaticInFlightRef (is our own measurement pass running?). No new abstractions, layers, or modules.

The guard's invariant is clean:

  • First-open: layoutReadyRef = false → observer fires → normal convergence
  • Our measurement: layoutReadyRef = true + inFlight > 0 → suppress (our own echo)
  • Content change: layoutReadyRef = true + inFlight = 0 → fires → normal re-layout
  • User drag: handled via onResized (separate path, line 129-139), not the observer — unaffected

2. Missed code-judo — None. The fix is the minimal correct change at the right site. The 186-line auto-fit function is pre-existing and untouched.

3. Spaghetti / branching — None. Clean early-return at the top of the callback answering "is this my own echo?" — not a special case bolted into an unrelated flow.

4. Type/boundary — Clean. No new types, casts, or optional churn. The 200ms trailing delay on programmaticInFlightRef is intentional for absorbing late observer callbacks.

5. File-size — No concern. Hook: 393→405 (+13). Test: 240→295 (+55). Both well under 1k.

6. Test quality — Good. StyleFeedbackResizeObserver uses MutationObserver on style attributes to simulate the actual feedback path. Asserts the observable contract (reveal count stops increasing) not implementation details. Correct vi.stubGlobal/unstubAllGlobals lifecycle.

7. Legibility — Clear. Comment explains the why. Guard reads naturally. Test name matches behavior.

Approval

No structural regression, no missed simplification, no file-size explosion, no spaghetti growth, no hacky abstraction. Approve.

@Finesssee
Finesssee merged commit 811ec50 into nesszer:main Aug 22, 2026
2 checks passed
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.

2 participants