Skip to content

fix(runtime): don't pump messages inside XAML's dispatcher; keep Application.Current an Application - #58

Merged
triniwiz merged 1 commit into
mainfrom
fix/xaml-host-pump
Nov 21, 2026
Merged

triniwiz merged 1 commit into
mainfrom
fix/xaml-host-pump

Conversation

@triniwiz

Copy link
Copy Markdown
Member

Problem

WinUI 3 apps freeze. A few seconds after an app starts rendering every frame, timers, requestAnimationFrame and native callbacks (such as a fetch completing) all stop for good. The window never recovers, and the UI thread sits idle in GetMessage.

The process outlives its window. Application.Current came back as Microsoft.UI.Xaml.IApplicationOverrides, which only has OnLaunched. So core's Application.Current.Exit() couldn't work.

Cause

Freeze:

  • WinUI's dispatcher is a Microsoft.UI.Dispatching.DispatcherQueue, so init_ui_dispatcher finds no Windows.System.DispatcherQueue and creates its own controller.
  • That made needs_win32_pump() true under XAML too. runtime_pump_timers (classic V8) and host_abi::pump_once (napi engines) then drained the thread's messages with PeekMessage/DispatchMessage while running inside the host's DispatcherQueue work item.
  • Dispatching the queues' wake messages re-entrantly can lose a wake. After that, XAML's queue, its DispatcherQueueTimer heartbeat and the runtime's own queue never run again.

Application.Current:

  • The template's C# App : Application has no WinMD entry, so CsWinRT reports one of its interfaces as the runtime class name.
  • resolve_runtime_class accepted that name and replaced the declared Application class with it.

Fix

  • ui_dispatcher::host_pumps_messages() is true when Microsoft.UI.Xaml.dll is loaded. It's settled on the first call, and every caller is a pump that a WinUI host only starts after Application.Start.
    • runtime_pump_timers and host_abi::pump_once leave Win32 messages to XAML's loop in that case.
    • event_loop::run_event_loop (console executables) and worker threads keep pumping as before.
  • resolve_runtime_class no longer replaces a declared class with an interface name. An interface name can still replace a declared interface or an unknown type.

Testing

Tested on a WinUI 3 app (a pixi.js WebGPU game) with the classic V8 release-with-devtools build:

  • Freeze:
    • Before: the stall reproduced on every run within about 3 s of the render loop starting, with both the stock beta.26 DLL and a local build.
    • Diagnosis: a cdb breakpoint showed PeekMessageW being called from PumpTimers inside the SchedulePump work item. Making those calls return FALSE under the debugger removed the stall.
    • After: the menu renders, play joins the server and the game runs.
  • Application.Current:
    • Before: closing the window left the process running.
    • After: it exits on its own after Alt+F4.

Not run: the new console_host_keeps_pumping_messages unit test, and builds of the Hermes, QuickJS and JSC engines. Those engines share the changed host_abi::pump_once.

Follow-up (separate PR)

defer_on_ui_thread and handle_worker_pushes_messages still key on needs_win32_pump(), so under WinUI they act as if there's no XAML host.

…ication.Current an Application

WinUI 3 apps froze a few seconds after they started rendering every
frame: timers, requestAnimationFrame and native callbacks all stopped
while the UI thread sat idle in GetMessage.

WinUI's dispatcher is a Microsoft.UI.Dispatching.DispatcherQueue, so
init_ui_dispatcher finds no Windows.System.DispatcherQueue and makes
its own controller. needs_win32_pump() was then true under XAML too,
and runtime_pump_timers (and the napi engines' host pump) drained the
thread's messages with PeekMessage/DispatchMessage from inside the
host's DispatcherQueue work item. Dispatching the queues' wake
messages re-entrantly can lose a wake, after which XAML's queue, its
timers and the runtime's own queue never run again. A frame loop
makes it happen within seconds.

host_pumps_messages() now detects a XAML host (Microsoft.UI.Xaml.dll
loaded), and the host pumps leave messages to XAML's loop there.
Console executables and workers keep pumping.

Also: Application.Current came back as Microsoft.UI.Xaml.
IApplicationOverrides, with no Exit, so core could never end the app
when its last window closed. The template's C# App has no WinMD, so
CsWinRT reports one of its interfaces as the runtime class name.
resolve_runtime_class no longer swaps a declared class for an
interface name.
@coderabbitai

coderabbitai Bot commented Nov 21, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5e215f17-257f-42e6-8208-5fd7d1f2291b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@triniwiz
triniwiz merged commit 2e49d5b into main Nov 21, 2026
3 checks passed
@triniwiz
triniwiz deleted the fix/xaml-host-pump branch November 22, 2026 01:34
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.

1 participant