Skip to content

fix(v3): guard nil AllowDarkModeForWindow to avoid startup panic#5793

Open
roachadam wants to merge 1 commit into
wailsapp:masterfrom
roachadam:fix/windows-1809-dark-mode-panic
Open

fix(v3): guard nil AllowDarkModeForWindow to avoid startup panic#5793
roachadam wants to merge 1 commit into
wailsapp:masterfrom
roachadam:fix/windows-1809-dark-mode-panic

Conversation

@roachadam

@roachadam roachadam commented Jul 17, 2026

Copy link
Copy Markdown

Description

Fixes a nil-pointer panic on startup when a window uses a Dark (or system-dark) native title bar on Windows builds that do not load the dark-mode uxtheme APIs — e.g. Windows 10 1809 / Windows Server 2019 (build 17763).

pkg/w32/theme.go loads AllowDarkModeForWindow (and siblings) only on build >= 18334, so on 1809 the package-level w32.AllowDarkModeForWindow is nil. (*windowsWebviewWindow).run called it unguarded in the Dark and dark SystemDefault branches (webview_window_windows.go), while w32.SetMenuTheme` already guards the identical call.

The fix extracts the call into a small applyDarkMode helper that nil-guards it (mirroring the guard w32.SetMenuTheme already uses) and calls it from both branches, so the window degrades gracefully (default title bar) instead of panicking. No behavior change on builds that load the procs; no new dependencies.

Fixes #5792

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • 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?

Built a minimal v3 app with Windows: application.WindowsWindow{Theme: application.Dark} and ran it on Windows Server 2019 (build 17763): before, it panicked on startup; after, the window opens normally.
Reproduction repo: https://github.com/roachadam/wails-1809-dark-title-bar-poc.

  • Windows
  • macOS
  • Linux

Test Configuration

Wails: v3.0.0-alpha2.117
OS:    Windows Server 2019 Standard Evaluation, 1809 (Build 17763)
Arch:  amd64
WebView2 runtime: 150.0.4078.65

Wails is not installed on this VM, so there is no wails3 doctor output. Reproduced with a minimal app instead: my existing app (built on v3.0.0-alpha.68) failed to start on Windows Server 2019 Standard Evaluation (build 17763). I reproduced the panic in isolation using the POC above built against the tagged v3.0.0-alpha2.117 release, then rebuilt the POC against this fix and confirmed the window opens normally.

Checklist:

  • (v2 only) I have updated website/src/pages/changelog.mdx with details of this PR (v3 changelog entries are added automatically)
  • 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
  • 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

Summary by CodeRabbit

  • Bug Fixes
    • Fixed a Windows startup crash that could occur when using a dark or system-dark window theme.
    • Improved compatibility with Windows versions where dark-mode system APIs are unavailable.

…indows 1809

pkg/w32/theme.go loads the undocumented dark-mode uxtheme exports (including
AllowDarkModeForWindow) only on Windows build >= 18334, so on older builds such
as Windows 10 1809 / Windows Server 2019 (build 17763) the package-level
AllowDarkModeForWindow is nil.

The Dark and system-dark branches of (*windowsWebviewWindow).run called it
unguarded, so a window with Windows.Theme == Dark (or SystemDefault while the OS
is in dark mode) panicked on startup with a nil pointer dereference before the
window was shown. w32.SetMenuTheme already guards the identical call.

Extract the call into an applyDarkMode method, which nil-guards it, and use it
from both branches so the window degrades gracefully instead of crashing.

Fixes wailsapp#5792
@github-actions github-actions Bot added Documentation Improvements or additions to documentation Windows v3-alpha labels Jul 17, 2026
@coderabbitai

coderabbitai Bot commented Jul 17, 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

Run ID: 18049280-9c7c-4913-a831-0f4da4948c31

📥 Commits

Reviewing files that changed from the base of the PR and between 107e42c and eda4f52.

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

Walkthrough

Windows dark-theme initialization now uses a nil-safe helper before invoking the optional dark-mode API. Both dark system-default and explicit dark themes avoid startup panics on builds without that API, and the fix is documented in the unreleased changelog.

Changes

Windows dark-mode startup fix

Layer / File(s) Summary
Nil-safe dark-mode theme setup
v3/pkg/application/webview_window_windows.go, v3/UNRELEASED_CHANGELOG.md
Dark system-default and explicit dark themes call applyDarkMode, which checks whether AllowDarkModeForWindow is available before invoking it. The changelog records the fix.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Possibly related PRs

  • wailsapp/wails#5790: Addresses the same Windows startup panic involving the unavailable dark-mode API.

Suggested labels: Bug, v3, size:XS

Suggested reviewers: wayneforrest, taliesin-ai, mbaklor

Poem

A rabbit found a dark-mode snare,
And guarded the Windows call with care.
No nil hop, no startup fright,
Just graceful themes from day to night.
Thump thump! Fixed and bright.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main fix: guarding nil AllowDarkModeForWindow to prevent a startup panic.
Description check ✅ Passed The description covers the fix, issue number, testing, configuration, and change type well enough for this repository.
Linked Issues check ✅ Passed The code matches #5792 by nil-guarding dark-mode window setup and preserving behavior on supported Windows builds.
Out of Scope Changes check ✅ Passed The changes stay focused on the reported Windows dark-mode panic and the related changelog entry.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain modules listed in go.work or their selected dependencies"


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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation Improvements or additions to documentation v3-alpha Windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[v3] Nil-pointer panic on startup with a Dark window theme on Windows 10 1809 / Server 2019

1 participant