fix(preview): async WebView2 creation on Windows — root fix for #149 - #253
Merged
Conversation
…the UI thread Root cause of #149, reproduced deterministically on physical Windows 11: wry's synchronous build_as_child pumps a nested Win32 message loop on the GPUI thread while WebView2 creates asynchronously; a window close dispatched inside that pump destroys the last window and the process exits mid-creation (or AVs, timing-dependent). Windows now uses lb-wry's build_as_child_async behind a per-key slot map (Creating{id, phase, pending_url} / Ready). Creation runs on the GPUI foreground executor; completion installs the view only if the window, panel, and exact creation generation are all still alive, else the raw webview is dropped through a panic-guarded helper. Duplicate ensures while Creating are coalesced; navigations replay from the stored URL on completion; value-returning ops answer a retryable 'preview is starting' error. A shared WebContext pins the WebView2 user-data folder under the tcode data dir instead of the exe-adjacent default. macOS keeps its proven synchronous path. The smoke harness now proves the fix: drop-during-create waits for a genuinely in-flight creation, drops the victim generation, and a new recreate-after-inflight-drop phase shows the same key reaches Ready afterwards — with the primary window retained so premature process exit is observable. Closes #149 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Owner
Author
|
Physical Windows 11 validation complete — 3/3 PASS. Same machine and harness that deterministically reproduced the failure (3/3 runs died at Zero crash dumps produced. Environment: Windows 11 26200, WebView2 Evergreen 151.0.4129.101. |
This was referenced Aug 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root cause (reproduced deterministically on physical Windows 11)
--preview-smokedied atdrop-during-createon 3/3 runs: process exit code 0 mid-phase, no dump, no PASS. wry's synchronousbuild_as_childwaits for WebView2's async environment/controller creation by running a nested Win32 message pump on the GPUI UI thread (webview2_com::wait_with_pump). A window-teardown message dispatched inside that pump destroys the last window → GPUI exits the process mid-creation. Timing-dependent variants can AV (parent HWND destroyed under the pending controller). macOS passes the same harness — the pump semantics differ.Fix
build_as_child_async(no nested pump; ships in lb-wry 0.53.3) driven by the GPUI foreground executor, behind a per-key slot map (Creating{id, phase, pending_url}/Ready). Completion installs the view only if window + panel + exact creation generation all still live; otherwise the raw webview is dropped via a panic-guarded helper. Duplicate ensures coalesce; navigations replay from the stored URL; value-returning MCP ops answer a retryable "preview is starting" error; builder failures keep the existing unavailable-state path.WebContextpins the WebView2 user-data folder under the tcode data dir (%APPDATA%\tcode\WebView2or%TCODE_DATA_DIR%\WebView2) instead of the crash-prone exe-adjacent default.drop-during-createasserts an actually in-flight creation before dropping the victim generation, and a newrecreate-after-inflight-dropphase shows the same key reaches Ready afterwards — with the primary window retained so a premature exit is observable as a missing PASS.Verification
--preview-smokerun — all 10 phases + PASS (output in the commit/report).cargo clippy -p tcode --target x86_64-pc-windows-gnu -- -D warnings— pass.Closes #149
🤖 Generated with Claude Code