Repository navigation
fix(v3/windows): remove ResizeDebounceMS and fix resize background painting - #5596
Conversation
…inting ResizeDebounceMS delayed WebView2 resizing to improve performance, but inherently left newly-exposed window areas undrawn for the debounce period. No mitigation can fully hide the content gap, so the option is removed — modern WebView2 handles live resize well enough without it. Also fix WM_ERASEBKGND to fill the client area with the configured background colour before returning, so any area momentarily not covered by WebView2 during a resize shows the correct colour instead of white. Fixes #5594
WalkthroughRemoves the ChangesResize Debouncer Removal and Background Painting Fix
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Pull request overview
This PR fixes Windows resize “white gap” artifacts in the v3 WebView2 window by removing resize debouncing (which intentionally delayed WebView2 resizing) and ensuring the native window erases its background using the configured solid background colour during resize.
Changes:
- Removed
ResizeDebounceMSfromWindowsWindowoptions and eliminated the associated resize debouncer logic on Windows. - Updated
WM_ERASEBKGNDhandling to actually paint the client area withBackgroundColour(for solid backgrounds) to prevent white/unpainted regions during live resize. - Simplified the
WM_SIZEresize path to always resize WebView2 immediately (while preserving the frameless minimize suppression workaround).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| v3/pkg/application/webview_window_windows.go | Removes resize debouncing and paints solid background on WM_ERASEBKGND to avoid white gaps during resize. |
| v3/pkg/application/webview_window_options.go | Removes the ResizeDebounceMS option from WindowsWindow. |
Comments suppressed due to low confidence (1)
v3/pkg/application/webview_window_windows.go:1599
- WM_ERASEBKGND now always returns 1 even if CreateSolidBrush fails (returns 0). In that failure case, the handler would claim to have erased the background without actually painting anything, reintroducing the white/unpainted area problem (at least under low-memory conditions). Guard the brush handle and return 0 on failure so the default erasing path can run.
w.moveDebouncer(func() {
w.parent.emit(events.Windows.WindowDidMove)
})
case w32.WM_SHOWWINDOW:
if wparam == 1 {
w.parent.emit(events.Windows.WindowShow)
w.updateContentProtection()
} else {
w.parent.emit(events.Windows.WindowHide)
}
case w32.WM_WINDOWPOSCHANGED:
windowPos := (*w32.WINDOWPOS)(unsafe.Pointer(lparam))
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
v3/pkg/application/webview_window_windows.go (1)
1607-1618: 💤 Low valueConsider adding a nil check for
GetClientRectreturn value.Other code in this file (lines 621-626) checks for
nilfromGetClientRect. While failure is extremely unlikely duringWM_ERASEBKGND, adding a guard would be consistent with the existing pattern and prevent a potential nil dereference in edge cases.♻️ Optional defensive check
if w.parent.options.BackgroundType == BackgroundTypeSolid { col := w.parent.options.BackgroundColour hdc := w32.HDC(wparam) rc := w32.GetClientRect(w.hwnd) + if rc == nil { + return 1 + } colorRef := w32.COLORREF(uint32(col.Red) | uint32(col.Green)<<8 | uint32(col.Blue)<<16) hbrush := w32.CreateSolidBrush(colorRef) w32.FillRect(hdc, rc, hbrush) w32.DeleteObject(w32.HGDIOBJ(hbrush)) }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@v3/pkg/application/webview_window_windows.go` around lines 1607 - 1618, The code does not validate that GetClientRect returns a valid rectangle before using it in FillRect, which could cause a nil dereference in edge cases. Add a nil check on the return value from w32.GetClientRect(w.hwnd) immediately after retrieving it, and skip the painting operations (FillRect and DeleteObject calls) if the rectangle is nil. Follow the same defensive pattern used elsewhere in the file at lines 621-626 to maintain consistency throughout the codebase.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@v3/pkg/application/webview_window_windows.go`:
- Around line 1607-1618: The code does not validate that GetClientRect returns a
valid rectangle before using it in FillRect, which could cause a nil dereference
in edge cases. Add a nil check on the return value from
w32.GetClientRect(w.hwnd) immediately after retrieving it, and skip the painting
operations (FillRect and DeleteObject calls) if the rectangle is nil. Follow the
same defensive pattern used elsewhere in the file at lines 621-626 to maintain
consistency throughout the codebase.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: bd12415f-1c45-4661-99cb-a17730c0fef9
📒 Files selected for processing (2)
v3/pkg/application/webview_window_options.gov3/pkg/application/webview_window_windows.go
💤 Files with no reviewable changes (1)
- v3/pkg/application/webview_window_options.go
…GND (#5687) GetClientRect can return nil during minimise/restore transitions; passing that to FillRect crashes. Guard before painting the solid background. Salvaged from #5636 (reported by @sinspired); the rest of that PR was superseded by #5596/#5616. Co-authored-by: Lea Anthony <[email protected]>
Summary
Fixes #5594 — white areas appear after window resize on Windows.
Remove
ResizeDebounceMSfromWindowsWindowoptions. The debounce delayed WebView2 resizing for performance, but inherently left newly-exposed areas undrawn for the debounce period — a content gap no amount of mitigation can fully hide. Modern WebView2 handles live resize well without it. The default was already0(no debounce), so this only breaks callers who explicitly opted in.Fix
WM_ERASEBKGNDto actually fill the client area with the configuredBackgroundColourbefore returning1. Previously the handler claimed to handle the erase without drawing anything, leaving white pixels wherever WebView2 hadn't yet painted. WebView2 paints on top, so this has no effect on normal rendering — it only matters for the brief moment during resize when the client area is larger than the WebView2 surface.Test plan
BackgroundColour: application.NewRGB(15, 17, 23)and resize the window — no white flash should appearResizeDebounceMScompile after removing the field (breaking change, alpha only)Summary by CodeRabbit
Breaking Changes
Improvements