Skip to content

fix(v3/windows): restore modal owner activation on close - #6055

Open
myparsleycat wants to merge 1 commit into
wailsapp:masterfrom
myparsleycat:fix/windows-modal-owner-activation
Open

fix(v3/windows): restore modal owner activation on close#6055
myparsleycat wants to merge 1 commit into
wailsapp:masterfrom
myparsleycat:fix/windows-modal-owner-activation

Conversation

@myparsleycat

@myparsleycat myparsleycat commented Aug 29, 2026

Copy link
Copy Markdown

Description

On Windows, closing a foreground attached modal can activate an unrelated application instead of returning activation to the modal owner.

The current WM_CLOSE path re-enables the owner only after DefWindowProc destroys the modal. This change records whether the modal is foreground, re-enables the owner before destruction, and activates the owner when appropriate. A background modal does not activate its owner, so closing it does not steal focus.

This also adds Windows regression tests for the required release and activation order.

Fixes #6054

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • WEP (proposal only; no implementation)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • Reproduced with a separate application using tagged github.com/wailsapp/wails/v3 v3.0.0-beta.15.

  • Applied only this patch through a local module replacement and verified that both immediate and delayed modal closure return activation to the owner.

  • Verified that an unrelated application no longer moves in front of the owner when the foreground modal closes.

  • Ran GOTOOLCHAIN=go1.25.0 go test ./pkg/application -count=1 successfully.

  • Ran GOTOOLCHAIN=go1.25.0 go test -timeout 10m ./...; all relevant packages passed. The current upstream internal/wake/exec tests still fail on Windows because they invoke the POSIX true command through cmd.exe.

  • Windows

  • macOS

  • Linux

Test Configuration

Wails CLI: v3.0.0-beta.15
OS: Windows 11 Pro 25H2 (Build 26200)
Architecture: amd64
Go: go1.25.0 for tests
WebView2: 151.0.4129.107
CGO_ENABLED: 1
Diagnosis: No issues found

Checklist:

  • (v2 only) I have updated website/src/pages/changelog.mdx with details of this PR (not applicable; this is a v3 fix)
  • My code follows the general coding style of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (not applicable; no documentation change is required)
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes (blocked by the unrelated upstream Windows internal/wake/exec failures described above)

Summary by CodeRabbit

  • Bug Fixes
    • Improved modal window closing behavior on Windows.
    • Restored the modal’s owner window before destruction, preventing unrelated windows from being activated.
    • Ensured owner activation only occurs when appropriate.
  • Tests
    • Added regression coverage for modal window release and activation behavior.

@coderabbitai

coderabbitai Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: ddd63986-8e60-42d2-9c4f-f1fd2790feaa

📥 Commits

Reviewing files that changed from the base of the PR and between 0f6083a and 26261cb.

📒 Files selected for processing (2)
  • v3/pkg/application/webview_window_modal_windows_test.go
  • v3/pkg/application/webview_window_windows.go

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


Walkthrough

The Windows modal cleanup logic now uses a shared owner-release helper. The WM_CLOSE path releases and conditionally activates the owner before destruction. Windows-only source-order tests verify the required control flow.

Changes

Windows modal owner activation

Layer / File(s) Summary
Modal owner release flow
v3/pkg/application/webview_window_windows.go
destroy() and the unconditional WM_CLOSE path call releaseModalParent before destruction. The helper re-enables the owner and calls SetActiveWindow only when activation is requested.
Modal release regression tests
v3/pkg/application/webview_window_modal_windows_test.go
Windows-only tests verify release ordering and conditional activation by inspecting the implementation source.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 26261

This change restores activation to the modal owner when a foreground Windows modal closes while preventing background modals from stealing focus. Regression tests cover the required behavior, and no actionable merge-blocking risk remains beyond normal checks and review.

Sequence Diagram(s)

sequenceDiagram
  participant ModalWindow
  participant OwnerWindow
  participant WindowsUser32
  ModalWindow->>ModalWindow: Capture focus state
  ModalWindow->>OwnerWindow: Re-enable owner
  ModalWindow->>WindowsUser32: Activate owner when modal was focused
  ModalWindow->>WindowsUser32: DefWindowProc WM_CLOSE
  WindowsUser32-->>ModalWindow: Return close result
Loading

Suggested reviewers: leaanthony, taliesin-ai

Poem

A rabbit checks the closing pane

The owner wakes, released from chain
If focused, activation starts
Tests guard the ordered parts
Windows hops in place again

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The implementation meets issue #6054: it records foreground state, releases the modal owner before destruction, activates the owner only when required, and avoids focus theft for background modals. Re…
Out of Scope Changes check ✅ Passed The code and tests are directly related to restoring Windows modal owner activation and preventing focus theft. No unrelated changes are identified.
Title check ✅ Passed The title clearly and concisely describes the main Windows bug fix: restoring modal owner activation when the modal closes.
Description check ✅ Passed The description is complete and relevant. It explains the bug, fix, issue reference, test coverage, Windows configuration, and checklist status. It also clearly documents the unrelated Windows test fa…
Full details: Linked Issues check

Explanation

The implementation meets issue #6054: it records foreground state, releases the modal owner before destruction, activates the owner only when required, and avoids focus theft for background modals. Regression tests cover the required ordering and conditional activation.

Full details: Description check

Explanation

The description is complete and relevant. It explains the bug, fix, issue reference, test coverage, Windows configuration, and checklist status. It also clearly documents the unrelated Windows test failure that prevents marking all tests as passing.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@myparsleycat myparsleycat changed the title fix(windows): restore modal owner activation on close fix(v3/windows): restore modal owner activation on close Aug 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[v3, windows]: restore owner activation when closing a foreground modal

1 participant