Fix UI thread freeze caused by PreCommit blocking when hiding windows

Commit: 7b031658 | 2025-03-10 18:38:05+00:00

← Back to List

Fix UI thread freeze caused by PreCommit blocking when hiding windows

Moderate
Commit Hash: 7b031658d66f2de00cb1e49c6945f838d897d251
Commit Time: 2025-03-10 18:38:05+00:00
Impact Level: Moderate
Generated By: webview2-upstream-sentry
Upstream Review: View Upstream Review 🔗

📋 Summary

This submission modifies the components/remote_cocoa/app_shim/native_widget_ns_window_bridge.mm file, adjusting the logic of NativeWidgetNSWindowBridge::ShouldWaitInPreCommit(). Previously, waiting would only occur when window_visible_ was true; now, an additional check for wants_to_be_visible_ has been added: as long as the window is currently not visible or "wants to be invisible," it will no longer block and wait. This aims to resolve the issue where, during the window hiding process, the UI thread was incorrectly blocked in the PreCommit phase, resulting in up to 5 seconds of freezing. This change primarily affects the synchronization mechanism of the window hiding flow, avoiding deadlocks or prolonged waiting in certain scenarios.

🎯 Impact Analysis

This change optimizes the synchronous waiting logic when hiding windows, preventing the issue of UI thread being blocked when hiding windows in the app shim process. For WebView2Mac, if its downstream code relies on the window visibility and synchronization mechanisms of NativeWidgetNSWindowBridge (such as window hiding, closing, animation, etc.), this change will enhance the robustness and responsiveness of window hiding-related operations, reducing the risk of UI stutter or deadlock caused by hiding windows. Since WebView2Mac directly inherits and reuses this class, this change is a low-level behavior correction and theoretically should not introduce compatibility issues. However, it is recommended to pay close attention to downstream logic that depends on window visibility state to ensure expected behavior.

Impacted Classes:

NativeWidgetNSWindowBridge