Skip to content

[Windows] IME composition/candidate UI loses caret positioning when switching between windows of the same application #1908

Open

Description

@chenbihao

Describe the bug

On Windows, switching between two native windows containing Wry webviews can cause Chinese IME composition/preedit UI to lose its caret positioning. Instead of remaining inline in the active textarea or next to its caret, the composition UI can appear in a separate floating window at the top-left corner of the screen (0, 0).

Direct English input still works. The problem is not consistently tied to one window: one window may work normally while the other has broken IME positioning, and the affected window can change during repeated switching. It often occurs when returning to a previously focused window.

An important comparison in the Tauri application is that returning to an application window from an external application normally works, while switching between windows of the same application triggers the problem. This describes the observed reproduction pattern, rather than a claim that all external-application transitions are unaffected. The external-application control case has not yet been separately verified in the attached standalone reduction.

I observed this with both Microsoft Pinyin and WeChat Input Method (Chinese Pinyin).

Steps To Reproduce

  1. Extract the attached wry-ime-window-switch-repro.zip. It contains a standalone Rust project using Wry and Tao directly, with no Tauri dependency.
  2. Run:
    cargo run --locked
  3. Enable a Chinese Pinyin IME.
  4. Click the textarea in window A, type and commit some Chinese text.
  5. Switch to window B, click its textarea, and type Chinese text.
  6. Return to A and type Chinese again. Repeat A → B → A → B several times.

After a window regains focus, the IME composition UI may appear at the screen origin instead of at the caret. The other window may still work, and the affected window can change on subsequent switches.

The reproduction setup uses one Tao event loop, two native windows, a shared Wry WebContext, and a plain textarea in each webview. There are no custom native window hooks, programmatic focus/blur calls, editor frameworks, or IME recovery code in the attached reduction. The page script only observes focus/composition events and displays a counter.

Expected behavior

Each time either window receives focus, Chinese composition should remain inline in the focused textarea, and the candidate/composition UI should be positioned at the caret.

Screenshots

In one captured failure, a detached IME composition window appeared at screen coordinates (0, 0), while the test page still displayed “Waiting for input”.

Platform and Versions (please complete the following information):

OS: Windows 11 Pro, build 26200 (10.0.26200), x64
Rustc: rustc 1.96.0 (ac68faa20 2026-05-25)

Versions used in the standalone test where the symptom was observed:

  • Wry: 0.57.0
  • Tao: 0.37.1
  • WebView2 Runtime: 142.0.3595.69
  • IMEs: Microsoft Pinyin and WeChat Input Method (Chinese Pinyin)

Additional context

  • The symptom was initially observed in a Tauri application (Tauri 2.12.1), then also in a separate direct Tao/Wry test with two plain textareas.
  • The attached source is a reduction of that standalone setup and has been build-checked. This newly packaged reduction has not yet been manually retested.
  • The Tauri application has since been upgraded to Tauri 2.12.5 / tauri-runtime-wry 2.12.3 / Wry 0.57.1 / Tao 0.37.2, and manual testing after the upgrade still reproduces the problem. The upgraded versions were verified in the running application. This newer-version result is from the Tauri application; the standalone test result above remains scoped to Wry 0.57.0 / Tao 0.37.1.
  • WebView2 Runtime remains 142.0.3595.69; a newer Runtime has not yet been tested.
  • Automated interactions appeared to introduce extra focus transitions and could mask the failure. Manual switching is the relevant reproduction path.
  • Other background applications were not fully excluded. This report does not establish whether the root cause is in Wry's hosting/focus handling, Tao, WebView2, or the IME.

wry-ime-window-switch-repro.zip

Potentially related reports:

The triggers and platforms differ, so I am linking these for context rather than assuming they are duplicates.

Is there a known issue or recommended handling for restoring the IME text-input context/caret positioning when switching between multiple native windows hosting Wry webviews?

Activity

  1. TakahiroNago commented on Nov 8, 2026

    @TakahiroNago
    Contributor

    I was able to reproduce this issue using the standalone Wry/Tao reproduction project.

    My observations:

    • The issue occurs intermittently when switching between windows A and B in either direction (A → B → A and B → A → B).
    • I reproduced it with both a Japanese IME and a Chinese Pinyin IME.
    • The IME candidate/composition UI sometimes appears at the top-left corner of the screen (0, 0) after switching windows.
    • The issue does not occur on every attempt.

    I have not identified the root cause yet. I plan to investigate the Windows focus handling and IME-related behavior in Wry and Tao, and will share any findings or a potential fix.

    I hope these additional reproduction results are helpful.

  2. TakahiroNago commented on Nov 8, 2026

    @TakahiroNago
    Contributor

    I ran a set of controlled experiments with the standalone Wry/Tao reproduction.

    Environment

    • Windows 11 Pro 10.0.26200, WebView2 Runtime 157.0.4341.42
    • wry 0.57.0, tao 0.37.1 (plus a local, env-var-switchable patch of wry for the variants below)
    • Japanese Microsoft IME and Microsoft Pinyin

    Method

    An automated PowerShell harness alternately clicks the textarea in window A and B,
    turns the IME on (via WM_IME_CONTROL on the default IME window), types one key, and records
    (a) whether the page received compositionstart and (b) which IME UI windows were shown
    (SetWinEventHook). 20 trials per run. Manual verification is still pending.

    Failure signature: the browser process shows an MSCTFIME Composition / CiceroUIWndFrame
    window at the top-left of the screen and the page never gets compositionstart
    (same state as the screenshot in the original report).

    Results (failures / 20)

    Condition Click switching SetForegroundWindow switching
    wry 0.57.0 unmodified, shared WebContext 10, 10, 10, 10, 10 (ja), 10 (zh) 10
    same, 1.5 s pause before typing 10 –
    separate data directory per window (separate browser processes) 0 –
    no MoveFocus on WM_SETFOCUS 0, 0, 0 20 (keyboard never reaches the page)
    MoveFocus after DefSubclassProc, only if GetFocus() is still the parent (no deferral) 10 10
    MoveFocus deferred via PostMessage 1, 0, 0 (ja), 1 (zh) 0
    deferred + only if GetFocus() is still the parent HWND 0, 1, 0, 0, 0, 0 (ja), 0 (zh) 0
    above + skip when the activation came from a mouse click inside the webview 0 ×5 (ja), 0 ×2 (zh) 0
    WinForms app with Microsoft's WebView2 control (no wry), shared user data folder 10 –
    same WinForms app, separate user data folders 0 –
    wry window vs. a WinForms window in another process 0 –

    In the unmodified configuration one of the two webviews fails on every visit while the other
    keeps working; which one is affected varies between runs.

    Interpretation

    The failures need two things at once: both webviews in t
    MoveFocus(PROGRAMMATIC) being called synchronously inside the host window's WM_SETFOCUS
    (src/webview2/mod.rs, parent subclass). Logging inside wry shows that focus has already moved
    into the WebView2 HWND by the time MoveFocus returns, i.e. before Windows has finished the
    activation sequence. Deferring the call past the activation avoids the problem.

    Microsoft's WinForms control also calls MoveFocus on GotFocus and reproduces the same
    failure rate, so the underlying problem is most likely ily avoid
    triggering it. I intend to report it to WebView2Feedback as well.

    Proposed direction

    On WM_SETFOCUS, post a registered message instead of calling MoveFocus directly; in the
    handler call MoveFocus(PROGRAMMATIC) only if `GetFocus(so a
    click that already focused the webview is left alone). This keeps the Alt+Tab / programmatic
    re-activation behaviour from #676.

    Before opening a PR I'd appreciate feedback on whether ttended
    Windows focus handling, and whether deferring MoveFocus raises any concerns (e.g. with
    #1910 or multi-webview windows). I can share the harnessatch.

  3. TakahiroNago commented on Nov 8, 2026

    @TakahiroNago
    Contributor

    Opened #1924 with the deferred/conditional MoveFocus change described above.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions