Skip to content

fix(v3): add nil check to Focus() to prevent SIGSEGV after Hide - #4922

Merged
leaanthony merged 3 commits into
wailsapp:v3-alphafrom
ddmoney420:fix/4890-focus-nil-check
Feb 2, 2026
Merged

leaanthony merged 3 commits into
wailsapp:v3-alphafrom
ddmoney420:fix/4890-focus-nil-check

Conversation

@ddmoney420

@ddmoney420 ddmoney420 commented Jan 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Adds nil/destroyed check to Focus() method in webview_window.go
  • Prevents SIGSEGV when Focus() is called on a hidden/destroyed window (e.g., clicking dock icon after window.Hide() on macOS)

Problem

When handling the macOS dock icon click using wailsEvents.Mac.ApplicationShouldHandleReopen, a SIGSEGV occurs if the main window was previously hidden via window.Hide().

The Focus() method was missing the nil/destroyed check that Show() and Hide() already have:

// Before (crash)
func (w *WebviewWindow) Focus() {
    InvokeSync(w.impl.focus)  // No nil check!
}

// After (safe)
func (w *WebviewWindow) Focus() {
    if w.impl == nil || w.isDestroyed() {
        return
    }
    InvokeSync(w.impl.focus)
}

Test plan

  • go build ./... passes
  • go test ./... passes
  • Manual test: Hide window → click dock icon → verify no crash

Reproduction repo: https://github.com/farhan687/wailsapp

Fixes #4890

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Fixed a crash that occurred when attempting to focus a hidden or destroyed window.

The Focus() method was missing a nil/destroyed check on w.impl,
causing a SIGSEGV when Focus() is called on a window that has been
hidden and potentially destroyed (e.g., when clicking the dock icon
after hiding the window on macOS).

This aligns Focus() with Show() and Hide() which already have proper
guards against nil/destroyed window implementations.

Fixes wailsapp#4890

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Jan 29, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

This PR adds a changelog entry documenting a fix for a SIGSEGV crash that occurs when calling Focus() on a hidden or destroyed window in Wails v3.

Changes

Cohort / File(s) Summary
Changelog Update
v3/UNRELEASED_CHANGELOG.md
Added fixed entry for SIGSEGV crash when calling Focus() on a hidden or destroyed window (#4890).

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Possibly related PRs

  • #4923: Implements the early-return guard in WebviewWindow.Focus to prevent calling into a nil/destroyed impl, resolving the SIGSEGV crash documented in this changelog entry.

Suggested labels

Bug, go, v3-alpha, v3

Poem

🐰 A crash was squashed, the window stood tall,
No more SIGSEGV when Focus heard the call!
Hidden or destroyed, the pointer plays fair,
The rabbit rejoices—now windows, beware! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is missing several required checklist items from the template, including documentation updates, changelog updates, test coverage, and platform testing confirmation. Complete the checklist by confirming changelog updates, platform testing results, self-review completion, and test execution results.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding a nil check to Focus() to prevent SIGSEGV after Hide, which is the primary objective of this PR.
Linked Issues check ✅ Passed The PR addresses issue #4890 by adding nil/destroyed checks to Focus() method to prevent SIGSEGV when called on hidden or destroyed windows, directly meeting the stated objectives.
Out of Scope Changes check ✅ Passed The changes are limited to the CHANGELOG entry and the Focus() method fix, both directly related to issue #4890 with no extraneous modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@leaanthony leaanthony left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM! This is a clean fix that follows the existing pattern used in Show() and Hide(). The nil/destroyed check prevents the SIGSEGV crash reported in #4890.

A minor suggestion for the future: consider adding an UNRELEASED_CHANGELOG.md entry for bug fixes like this so they appear in the release notes.

@leaanthony
leaanthony enabled auto-merge (squash) February 2, 2026 09:58
@sonarqubecloud

sonarqubecloud Bot commented Feb 2, 2026

Copy link
Copy Markdown

@leaanthony
leaanthony merged commit a572244 into wailsapp:v3-alpha Feb 2, 2026
45 checks passed
Grantmartin2002 pushed a commit to Grantmartin2002/wails that referenced this pull request Apr 29, 2026
…sapp#4922)

* fix(v3): add nil check to Focus() to prevent SIGSEGV after Hide

The Focus() method was missing a nil/destroyed check on w.impl,
causing a SIGSEGV when Focus() is called on a window that has been
hidden and potentially destroyed (e.g., when clicking the dock icon
after hiding the window on macOS).

This aligns Focus() with Show() and Hide() which already have proper
guards against nil/destroyed window implementations.

Fixes wailsapp#4890

Co-Authored-By: Claude Opus 4.5 <[email protected]>

* docs: add changelog entry for Focus() nil check fix

Co-Authored-By: Claude Opus 4.5 <[email protected]>

---------

Co-authored-by: ddmoney420 <[email protected]>
Co-authored-by: Claude Opus 4.5 <[email protected]>
Co-authored-by: Lea Anthony <[email protected]>
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