<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Takahiro Nago</title>
    <description>The latest articles on DEV Community by Takahiro Nago (@takahironago).</description>
    <link>https://dev.to/takahironago</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4239552%2Fc2a9566f-35bb-4349-a0ef-ee869264ecb6.jpg</url>
      <title>DEV Community: Takahiro Nago</title>
      <link>https://dev.to/takahironago</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/takahironago"/>
    <language>en</language>
    <item>
      <title>Fixing a drop target leak every time a WebView closes in Wry</title>
      <dc:creator>Takahiro Nago</dc:creator>
      <pubDate>Wed, 02 Dec 2026 15:07:09 +0000</pubDate>
      <link>https://dev.to/takahironago/fixing-a-drop-target-leak-every-time-a-webview-closes-in-wry-26hh</link>
      <guid>https://dev.to/takahironago/fixing-a-drop-target-leak-every-time-a-webview-closes-in-wry-26hh</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;On Windows, every closed WebView with a drag and drop handler (the Tauri default) leaked four COM drop targets plus the handler closure and everything it captured.&lt;/li&gt;
&lt;li&gt;Fixed in wry 0.57.4. Tauri 2.13+ already uses a fixed wry; on Tauri 2.12, run &lt;code&gt;cargo update -p wry&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The lesson for COM in Rust: if you hand an object to OLE, don't let it hold anything heavy by &lt;code&gt;Rc&lt;/code&gt;. You can't control when OLE lets go.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Wry, the WebView library underneath Tauri, had a Windows bug: closing a WebView that had a drag and drop handler did not free the handler or anything it captured. Each closed WebView left four COM objects and the handler closure alive until the process exited.&lt;/p&gt;

&lt;p&gt;My pull request fixing this was merged into the &lt;code&gt;dev&lt;/code&gt; branch on November 23, 2026 and shipped in wry 0.57.4 on November 25.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Issue: &lt;a href="https://github.com/tauri-apps/wry/issues/1931" rel="noopener noreferrer"&gt;tauri-apps/wry#1931&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Pull request: &lt;a href="https://github.com/tauri-apps/wry/pull/1935" rel="noopener noreferrer"&gt;tauri-apps/wry#1935&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This post covers the cause of the leak, the fix, how the design changed once it turned out some registrations cannot be revoked, and the review. The main topics are the lifetime of &lt;code&gt;RegisterDragDrop&lt;/code&gt; / &lt;code&gt;RevokeDragDrop&lt;/code&gt; registrations, and what to watch out for when a COM object holds a Rust &lt;code&gt;Rc&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem
&lt;/h2&gt;

&lt;p&gt;The issue was reported by someone else. They opened and closed child WebViews in a Tauri app 1,000 times and counted objects by reading the process memory from outside:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;With a drag and drop handler, live &lt;code&gt;DragDropTarget_Impl&lt;/code&gt; objects grew by exactly 400 per 100 WebViews (4,015 after 1,000).&lt;/li&gt;
&lt;li&gt;Private bytes of the host process grew by about 4.2 KB per WebView.&lt;/li&gt;
&lt;li&gt;WebViews created with &lt;code&gt;disable_drag_drop_handler()&lt;/code&gt; did not grow.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Tauri attaches a drag and drop handler to every WebView by default, so any app that creates and closes WebViews often hits this without doing anything unusual.&lt;/p&gt;

&lt;h2&gt;
  
  
  Root cause
&lt;/h2&gt;

&lt;p&gt;To receive file drops on top of WebView2 itself, Wry enumerates the child windows of the WebView's container window and registers its own &lt;code&gt;IDropTarget&lt;/code&gt; on each:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;inject_in_hwnd&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="kd"&gt;mut&lt;/span&gt; &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hwnd&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;HWND&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Rc&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;dyn&lt;/span&gt; &lt;span class="nc"&gt;Fn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;DragDropEvent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;drag_drop_target&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;IDropTarget&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;DragDropTarget&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hwnd&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;into&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="k"&gt;unsafe&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;RevokeDragDrop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hwnd&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;Err&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;DRAGDROP_E_INVALIDHWND&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;into&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="k"&gt;unsafe&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;RegisterDragDrop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hwnd&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;drag_drop_target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;is_ok&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;drop_targets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;drag_drop_target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It removes the drop target WebView2 registered with &lt;code&gt;RevokeDragDrop&lt;/code&gt; and registers its own with &lt;code&gt;RegisterDragDrop&lt;/code&gt;. There are four such windows per WebView: &lt;code&gt;Chrome_WidgetWin_0&lt;/code&gt;, &lt;code&gt;Chrome_WidgetWin_1&lt;/code&gt;, &lt;code&gt;Chrome_RenderWidgetHostHWND&lt;/code&gt; and &lt;code&gt;Intermediate D3D Window&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The problem: nothing ever revoked these registrations.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;RegisterDragDrop&lt;/code&gt; makes OLE hold a reference to the &lt;code&gt;IDropTarget&lt;/code&gt;. That reference is released by &lt;code&gt;RevokeDragDrop&lt;/code&gt;. If the window is destroyed while still registered, OLE's reference stays. Destroying the window does not clean it up for you.&lt;/p&gt;

&lt;p&gt;Each &lt;code&gt;DragDropTarget&lt;/code&gt; held the handler by &lt;code&gt;Rc&lt;/code&gt;. The ownership looked like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;InnerWebView ─→ DragDropController ─→ Vec&amp;lt;IDropTarget&amp;gt; ─┐
                                                        ├─→ DragDropTarget ─→ Rc&amp;lt;handler&amp;gt;
OLE (reference from RegisterDragDrop) ──────────────────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Dropping the WebView removes the upper path, but OLE's reference keeps the &lt;code&gt;DragDropTarget&lt;/code&gt; alive, and its &lt;code&gt;Rc&lt;/code&gt; keeps the handler and everything the handler captured alive too.&lt;/p&gt;

&lt;p&gt;Before the fix, &lt;code&gt;InnerWebView&lt;/code&gt; had this comment:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Store FileDropController in here to make sure it gets dropped when&lt;/span&gt;
&lt;span class="c1"&gt;// the webview gets dropped, otherwise we'll have a memory leak&lt;/span&gt;
&lt;span class="cp"&gt;#[allow(dead_code)]&lt;/span&gt;
&lt;span class="n"&gt;drag_drop_controller&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Option&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;DragDropController&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The controller was indeed dropped with the WebView. But that only released the controller's own references. OLE's references were never touched.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fix, part 1: revoke before the windows go away
&lt;/h2&gt;

&lt;p&gt;The straightforward fix: remember the &lt;code&gt;HWND&lt;/code&gt; each target was registered on, and call &lt;code&gt;RevokeDragDrop&lt;/code&gt; in &lt;code&gt;Drop&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;impl&lt;/span&gt; &lt;span class="nc"&gt;Drop&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="nc"&gt;DragDropController&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;drop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="kd"&gt;mut&lt;/span&gt; &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hwnd&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;drop_targets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;drain&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="c1"&gt;// A window WebView2 has already destroyed cannot be revoked anymore, and its handle may&lt;/span&gt;
      &lt;span class="c1"&gt;// have been reused by an unrelated window.&lt;/span&gt;
      &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="k"&gt;unsafe&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;IsChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;hwnd&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;hwnd&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;as_bool&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;continue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;unsafe&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;RevokeDragDrop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hwnd&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;IsChild&lt;/code&gt; check skips windows that are already destroyed. &lt;code&gt;HWND&lt;/code&gt; values get reused, so a stored handle may now point to an unrelated window. If it is no longer a descendant of the container, leave it alone.&lt;/p&gt;

&lt;p&gt;Ordering matters here: the revoke has to happen &lt;strong&gt;while the window still exists&lt;/strong&gt;. So &lt;code&gt;InnerWebView::drop&lt;/code&gt; now drops the controller before &lt;code&gt;Close()&lt;/code&gt; and &lt;code&gt;DestroyWindow&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;impl&lt;/span&gt; &lt;span class="nc"&gt;Drop&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="nc"&gt;InnerWebView&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;drop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="kd"&gt;mut&lt;/span&gt; &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Revoke the drop targets while the windows they are registered on still exist.&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="kc"&gt;Some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;drag_drop_controller&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;drag_drop_controller&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;drag_drop_controller&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;drag_drop_controller&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;take&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nb"&gt;drop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;drag_drop_controller&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;unsafe&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;controller&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;is_child&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;unsafe&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;DestroyWindow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;hwnd&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Fix, part 2: when the parent window is destroyed first
&lt;/h2&gt;

&lt;p&gt;That is not enough when the parent window is destroyed with &lt;code&gt;DestroyWindow&lt;/code&gt; before the WebView is dropped. Destroying the parent destroys the container and all its descendants, so by the time &lt;code&gt;InnerWebView::drop&lt;/code&gt; runs there is nothing left to revoke. Every target is skipped by the &lt;code&gt;IsChild&lt;/code&gt; check and stays alive.&lt;/p&gt;

&lt;p&gt;For this path, revoke in the container's &lt;code&gt;WM_DESTROY&lt;/code&gt;. &lt;code&gt;WM_DESTROY&lt;/code&gt; is sent to the window being destroyed before its children are destroyed, so while the container handles &lt;code&gt;WM_DESTROY&lt;/code&gt; its descendants still exist.&lt;/p&gt;

&lt;p&gt;Wry already subclasses the container (&lt;code&gt;main_thread_dispatcher_proc&lt;/code&gt;), so the controller is handed to that subclass and dropped on &lt;code&gt;WM_DESTROY&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="no"&gt;WM_DESTROY&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;dwrefdata&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Drop the drag drop controller to revoke its drop targets: the descendants of the&lt;/span&gt;
  &lt;span class="c1"&gt;// container they are registered on still exist at this point.&lt;/span&gt;
  &lt;span class="kt"&gt;Self&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;attach_main_thread_dispatcher&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hwnd&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;drag_drop_controller&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="nc"&gt;Rc&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from_raw&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dwrefdata&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="nc"&gt;Cell&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;Option&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;DragDropController&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;drag_drop_controller&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;drag_drop_controller&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;take&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nb"&gt;drop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;drag_drop_controller&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The controller is shared between &lt;code&gt;InnerWebView&lt;/code&gt; and the subclass as &lt;code&gt;Rc&amp;lt;Cell&amp;lt;Option&amp;lt;DragDropController&amp;gt;&amp;gt;&amp;gt;&lt;/code&gt;, and whichever runs first &lt;code&gt;take()&lt;/code&gt;s and drops it. The subclass gets a raw pointer from &lt;code&gt;Rc::into_raw&lt;/code&gt; as its reference data and reclaims it with &lt;code&gt;Rc::from_raw&lt;/code&gt; on &lt;code&gt;WM_DESTROY&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Both paths are needed because, for a WebView that is not a child WebView, dropping the WebView does not destroy the container: the container is the app's window itself.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sometimes the revoke fails
&lt;/h2&gt;

&lt;p&gt;I thought that was the end of it, until measurements showed revokes failing.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;RevokeDragDrop&lt;/code&gt; sometimes returns &lt;code&gt;DRAGDROP_E_NOTREGISTERED&lt;/code&gt; (0x80040100). The window still exists and is still a descendant of the container, yet it reports "not registered".&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It is always &lt;code&gt;Chrome_WidgetWin_1&lt;/code&gt;, the window owned by the WebView2 browser process. It never happened on the other three.&lt;/li&gt;
&lt;li&gt;The frequency varies a lot between runs: 0 to 48 per 1,000 WebViews.&lt;/li&gt;
&lt;li&gt;A target whose revoke fails stays alive.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The issue suggested calling &lt;code&gt;CoDisconnectObject(&amp;amp;target, 0)&lt;/code&gt; in that case. I tried it: it returned &lt;code&gt;S_OK&lt;/code&gt; 48 times out of 48, and not a single target was released.&lt;/p&gt;

&lt;h3&gt;
  
  
  Hold the handler weakly
&lt;/h3&gt;

&lt;p&gt;If some targets cannot be released, change the design instead. As long as a surviving target does not drag the handler along with it, the damage is one small COM object.&lt;/p&gt;

&lt;p&gt;So the controller now holds the only strong reference to the handler, and the targets hold a &lt;code&gt;Weak&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;crate&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="nc"&gt;DragDropController&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;hwnd&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;HWND&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;drop_targets&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Vec&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;HWND&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;IDropTarget&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="c1"&gt;/// The only strong reference to the handler. The drop targets hold weak ones, because OLE&lt;/span&gt;
  &lt;span class="c1"&gt;/// can keep a target alive forever: revoking fails with `DRAGDROP_E_NOTREGISTERED` when the&lt;/span&gt;
  &lt;span class="c1"&gt;/// registration on a window owned by the WebView2 browser process is already gone.&lt;/span&gt;
  &lt;span class="n"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Rc&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;dyn&lt;/span&gt; &lt;span class="nc"&gt;Fn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;DragDropEvent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="c1"&gt;/// Calls the handler, unless its webview is already gone.&lt;/span&gt;
&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;emit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;DragDropEvent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="kc"&gt;Some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;listener&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;listener&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;upgrade&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;listener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the controller is dropped, the handler is freed, and &lt;code&gt;upgrade()&lt;/code&gt; on any surviving target just returns &lt;code&gt;None&lt;/code&gt;. The handler's lifetime is now tied to the WebView's, not to whether the revoke succeeds.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why is the registration gone?
&lt;/h3&gt;

&lt;p&gt;Legend-Master, one of the reviewers, suggested that Chromium might be removing Wry's target with its own &lt;code&gt;RevokeDragDrop&lt;/code&gt;, since Chromium does not know its handler has been replaced.&lt;/p&gt;

&lt;p&gt;I wanted to know, so I added logging around &lt;code&gt;RevokeDragDrop&lt;/code&gt; / &lt;code&gt;RegisterDragDrop&lt;/code&gt; that recorded the window's &lt;code&gt;OleDropTargetInterface&lt;/code&gt; property and the target's reference count, and ran 1,000 WebViews again.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;
&lt;code&gt;Chrome_WidgetWin_1&lt;/code&gt; at inject time&lt;/th&gt;
&lt;th&gt;Windows&lt;/th&gt;
&lt;th&gt;Revoke failed later&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;No drop target registered&lt;/td&gt;
&lt;td&gt;995&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;A drop target already registered&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The 2,999 windows of the other three classes had no drop target at inject time and never failed.&lt;/p&gt;

&lt;p&gt;Failures only happened when Chromium's own drop target was already registered at the moment Wry replaced it. Those five cases:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;RevokeDragDrop&lt;/code&gt; before registering returned &lt;code&gt;RPC_E_WRONG_THREAD&lt;/code&gt; (0x8001010E) in four cases and &lt;code&gt;DRAGDROP_E_NOTREGISTERED&lt;/code&gt; in one. Even so, the property was gone right after the call in all five.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;RegisterDragDrop&lt;/code&gt; returned &lt;code&gt;S_OK&lt;/code&gt; in all five. But in two cases the property was already gone right after the call, and in one it disappeared before the WebView was dropped. Those three are the ones whose final revoke failed.&lt;/li&gt;
&lt;li&gt;In those three, the target's reference count stayed at 2 (ours plus one more) from registration onward. Every target whose revoke succeeded went back to 1.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So the reviewer was right that replacing Chromium's handler is what triggers this. But in two of the three cases the registration disappeared right after &lt;code&gt;RegisterDragDrop&lt;/code&gt; returned, while the window was still alive, so it does not look like window teardown. It looks like a race with the browser process while it is still setting up that window. I could not confirm what removes the registration, or who holds the remaining reference.&lt;/p&gt;

&lt;p&gt;That part is still open, but the &lt;code&gt;Weak&lt;/code&gt; design frees the handler whatever the cause, so the PR went ahead with it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Verification
&lt;/h2&gt;

&lt;p&gt;I wrote a temporary example (not included in the PR) that repeats:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a WebView with a drag and drop handler.&lt;/li&gt;
&lt;li&gt;Wait for the page to finish loading.&lt;/li&gt;
&lt;li&gt;Drop it.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Live &lt;code&gt;DragDropTarget&lt;/code&gt;s were counted with a temporary counter, and live handlers with the strong count of an &lt;code&gt;Rc&lt;/code&gt; captured by the handler. There were three modes, one per teardown path:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;child&lt;/code&gt;: a child WebView from &lt;code&gt;build_as_child&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;window&lt;/code&gt;: a new window plus &lt;code&gt;build&lt;/code&gt;, dropping the WebView first.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;parent-first&lt;/code&gt;: destroying the window with &lt;code&gt;DestroyWindow&lt;/code&gt; before dropping the WebView.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;On &lt;code&gt;dev&lt;/code&gt; before the fix, 100 WebViews each:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Mode&lt;/th&gt;
&lt;th&gt;Live handlers&lt;/th&gt;
&lt;th&gt;Live targets&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;child&lt;/td&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;td&gt;399&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;window&lt;/td&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;td&gt;399&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;After the fix, 1,000 WebViews each:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Mode&lt;/th&gt;
&lt;th&gt;Live handlers&lt;/th&gt;
&lt;th&gt;Live targets&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;child&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;window&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;parent-first&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Live handlers dropped to 0 in every mode. The remaining targets are the &lt;code&gt;Chrome_WidgetWin_1&lt;/code&gt; revoke failures described above. In a separate run that logged revoke results, &lt;code&gt;parent-first&lt;/code&gt; with 1,000 WebViews had 3,991 successful revokes and 8 failures (all &lt;code&gt;DRAGDROP_E_NOTREGISTERED&lt;/code&gt;), and exactly 8 surviving targets.&lt;/p&gt;

&lt;p&gt;I also checked by hand that drag and drop itself still works: dragging a file over the window still delivers &lt;code&gt;Enter&lt;/code&gt; / &lt;code&gt;Over&lt;/code&gt; / &lt;code&gt;Drop&lt;/code&gt; / &lt;code&gt;Leave&lt;/code&gt; as before.&lt;/p&gt;

&lt;p&gt;Environment: Windows 11 Pro 10.0.26200, WebView2 Runtime 157.0.4341.46, rustc 1.99.1.&lt;/p&gt;

&lt;h2&gt;
  
  
  What came up in review
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Is the revoke in &lt;code&gt;WM_DESTROY&lt;/code&gt; needed?
&lt;/h3&gt;

&lt;p&gt;Legend-Master commented that in their testing the drop in &lt;code&gt;InnerWebView&lt;/code&gt; already revoked everything, so the container-side code looked unnecessary.&lt;/p&gt;

&lt;p&gt;That is true if you only test the path where the WebView is dropped first. The difference only shows when the parent window is destroyed first, so I answered with numbers from that path, 100 WebViews each:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Revoked&lt;/th&gt;
&lt;th&gt;Skipped&lt;/th&gt;
&lt;th&gt;Live handlers&lt;/th&gt;
&lt;th&gt;Live targets&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;With the &lt;code&gt;WM_DESTROY&lt;/code&gt; revoke&lt;/td&gt;
&lt;td&gt;399&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Without&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;399&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;399&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Thanks to &lt;code&gt;Weak&lt;/code&gt;, the handler is freed either way, so the cost of removing it is "four small COM objects per WebView on this path". I explained why I would keep it, and also said to remove it if simpler code mattered more. It stayed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Explain the &lt;code&gt;Weak&lt;/code&gt; in a comment
&lt;/h3&gt;

&lt;p&gt;Asked whether &lt;code&gt;Weak&lt;/code&gt; was there for the cases that cannot be revoked, I said yes, and was asked to write that reason in the code. Fair point: a later reader cannot tell why it isn't an &lt;code&gt;Rc&lt;/code&gt;. I added the comment on the struct field shown above.&lt;/p&gt;

&lt;h3&gt;
  
  
  Don't add another subclass
&lt;/h3&gt;

&lt;p&gt;The first version added a dedicated window subclass to catch the container's &lt;code&gt;WM_DESTROY&lt;/code&gt;. amrbashir, a maintainer, asked whether the controller could be dropped inside a subclass that already exists in &lt;code&gt;src/webview2/mod.rs&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;main_thread_dispatcher_proc&lt;/code&gt; version shown above is the rewrite after that comment: it is the subclass attached to the container, and it exists for child WebViews too. After the rewrite I reran the three modes with 1,000 WebViews each and the manual drag and drop check.&lt;/p&gt;

&lt;p&gt;Finally, Legend-Master changed the shared &lt;code&gt;RefCell&lt;/code&gt; to a &lt;code&gt;Cell&lt;/code&gt; (only &lt;code&gt;take()&lt;/code&gt; is used, so &lt;code&gt;Cell&lt;/code&gt; is enough) and approved it: "This felt much more verbose than I expected", but with no better idea for now, merge it first.&lt;/p&gt;

&lt;h2&gt;
  
  
  What this fix does not solve
&lt;/h2&gt;

&lt;p&gt;These are also listed in the PR description.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Targets whose revoke fails stay alive.&lt;/strong&gt; As described above, a few small COM objects per 1,000 WebViews remain. They no longer hold the handler.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Windows replaced by navigation.&lt;/strong&gt; The issue also mentioned that navigating to another origin replaces &lt;code&gt;Chrome_RenderWidgetHostHWND&lt;/code&gt;. Navigating one WebView between two origins 20 times, the window was replaced with a new one every time, and the new window had no drop target registered.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The target registered on the original window is not revoked, because that window is gone. It is one per WebView, though, not one per navigation.&lt;/li&gt;
&lt;li&gt;Registering on the new window is not part of this PR.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Drops still reach the handler after navigation, both before and after the fix, because the targets on the other two windows remain. Re-registering on replaced windows is split out as a separate change.&lt;/p&gt;

&lt;h2&gt;
  
  
  Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Destroying a window does not undo &lt;code&gt;RegisterDragDrop&lt;/code&gt;.&lt;/strong&gt; Call &lt;code&gt;RevokeDragDrop&lt;/code&gt; while the window still exists. "It's in the struct, so it gets dropped" is about Rust's references, and does not reach the reference OLE holds.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Don't let a COM object you hand out hold anything heavy by a strong reference.&lt;/strong&gt; If you can't control when the other side lets go, keep the object small and hold its contents by &lt;code&gt;Weak&lt;/code&gt;. A design that does not depend on the release succeeding limits the damage when some case stays unexplained.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;There is more than one teardown path.&lt;/strong&gt; "Drop the WebView first" and "destroy the parent first" leave different windows alive when cleanup runs. Without a measurement mode for each path, I would have missed one.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Child windows still exist during &lt;code&gt;WM_DESTROY&lt;/code&gt;.&lt;/strong&gt; The parent's &lt;code&gt;WM_DESTROY&lt;/code&gt; is the last chance to clean up anything registered on its descendants.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Try a suggested fix before accepting or rejecting it.&lt;/strong&gt; &lt;code&gt;CoDisconnectObject&lt;/code&gt; sounded plausible, but it just returned &lt;code&gt;S_OK&lt;/code&gt; and released nothing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Say what you don't know.&lt;/strong&gt; I never found what removes the registration. The PR separates what I confirmed (when it happens, what the reference counts look like) from what I could not.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Closing
&lt;/h2&gt;

&lt;p&gt;The cause of the leak was simple, "registered but never unregistered", but fixing it raised one thing after another: window destruction order, handle reuse, a race with the browser process. The final fix has two layers: revoke at the right time, and make sure the handler is freed even when the revoke fails.&lt;/p&gt;

&lt;p&gt;The fix is in wry 0.57.4 and later. Tauri 2.13 and later already depend on a fixed wry; on Tauri 2.12, &lt;code&gt;cargo update -p wry&lt;/code&gt; picks up 0.57.4. If you added &lt;code&gt;disable_drag_drop_handler()&lt;/code&gt; to work around this in an app that opens and closes WebViews often, update and see whether you can remove it.&lt;/p&gt;

</description>
      <category>rust</category>
      <category>tauri</category>
      <category>windows</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Fixing Tauri's MSI installer re-creating a deleted desktop shortcut on every update</title>
      <dc:creator>Takahiro Nago</dc:creator>
      <pubDate>Wed, 02 Dec 2026 13:35:55 +0000</pubDate>
      <link>https://dev.to/takahironago/fixing-tauris-msi-installer-re-creating-a-deleted-desktop-shortcut-on-every-update-1il1</link>
      <guid>https://dev.to/takahironago/fixing-tauris-msi-installer-re-creating-a-deleted-desktop-shortcut-on-every-update-1il1</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If you ship a Tauri app as an MSI, a desktop shortcut the user deleted came back on every update.&lt;/li&gt;
&lt;li&gt;Rebuild with tauri-cli 2.12.5 or later (tauri-bundler 2.10.5+) and the deleted shortcut stays deleted.&lt;/li&gt;
&lt;li&gt;Building your own WiX installer? A property found by &lt;code&gt;AppSearch&lt;/code&gt; needs &lt;code&gt;Secure="yes"&lt;/code&gt;, or interactive installs never see it.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Tauri's MSI installer had a long-standing annoyance: if a user deleted the desktop shortcut, every app update brought it back. The NSIS installer did not do this, only the MSI one.&lt;/p&gt;

&lt;p&gt;I fixed this in tauri-bundler. The pull request was merged into the &lt;code&gt;dev&lt;/code&gt; branch on November 12, 2026 and shipped in tauri-bundler 2.10.5 (tauri-cli / &lt;code&gt;@tauri-apps/cli&lt;/code&gt; 2.12.5). This post covers the root cause, how WiX major upgrades work, the fix itself, and the one thing the fix explicitly does not solve, as pointed out in review.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Issue: &lt;a href="https://github.com/tauri-apps/tauri/issues/16483" rel="noopener noreferrer"&gt;tauri-apps/tauri#16483&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Pull request: &lt;a href="https://github.com/tauri-apps/tauri/pull/16506" rel="noopener noreferrer"&gt;tauri-apps/tauri#16506&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Along the way it touches &lt;code&gt;AppSearch&lt;/code&gt;, the &lt;code&gt;Secure&lt;/code&gt; property attribute and the scheduling of &lt;code&gt;RemoveExistingProducts&lt;/code&gt;. If you build your own Windows installer with WiX, the &lt;code&gt;Secure="yes"&lt;/code&gt; section is probably the part worth reading.&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem
&lt;/h2&gt;

&lt;p&gt;With a Tauri v2 app built for the &lt;code&gt;msi&lt;/code&gt; target:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Install the app. A desktop shortcut is created.&lt;/li&gt;
&lt;li&gt;Delete the shortcut.&lt;/li&gt;
&lt;li&gt;Install a newer version's MSI (updates through tauri-plugin-updater behave the same).&lt;/li&gt;
&lt;li&gt;The shortcut is back.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;GitButler users hit this on every single update (&lt;a href="https://github.com/gitbutlerapp/gitbutler/issues/14722" rel="noopener noreferrer"&gt;gitbutlerapp/gitbutler#14722&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Tauri's NSIS installer does not have this problem. &lt;code&gt;CreateOrUpdateDesktopShortcut&lt;/code&gt; in &lt;code&gt;installer.nsi&lt;/code&gt; returns early in update mode:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  ; Skip creating shortcut if in update mode or no shortcut mode
  ; but always create if migrating from wix
  ${If} $WixMode = 0
    ${If} $UpdateMode = 1
    ${OrIf} $NoShortcutMode = 1
      Return
    ${EndIf}
  ${EndIf}

  CreateShortcut "$DESKTOP\${PRODUCTNAME}.lnk" "$INSTDIR\${MAINBINARYNAME}.exe"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So the two installers disagreed, and the goal was to make MSI match NSIS.&lt;/p&gt;

&lt;h2&gt;
  
  
  Root cause
&lt;/h2&gt;

&lt;p&gt;Tauri generates its MSI from a WiX 3 template, &lt;code&gt;main.wxs&lt;/code&gt;. The desktop shortcut lived in this component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;Directory&lt;/span&gt; &lt;span class="na"&gt;Id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"DesktopFolder"&lt;/span&gt; &lt;span class="na"&gt;Name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Desktop"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;Component&lt;/span&gt; &lt;span class="na"&gt;Id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"ApplicationShortcutDesktop"&lt;/span&gt; &lt;span class="na"&gt;Guid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"*"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;Shortcut&lt;/span&gt; &lt;span class="na"&gt;Id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"ApplicationDesktopShortcut"&lt;/span&gt; &lt;span class="na"&gt;Name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"{{product_name}}"&lt;/span&gt; &lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Runs {{product_name}}"&lt;/span&gt; &lt;span class="na"&gt;Target&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"[!Path]"&lt;/span&gt; &lt;span class="na"&gt;WorkingDirectory&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"INSTALLDIR"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;RemoveFolder&lt;/span&gt; &lt;span class="na"&gt;Id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"DesktopFolder"&lt;/span&gt; &lt;span class="na"&gt;On&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"uninstall"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;RegistryValue&lt;/span&gt; &lt;span class="na"&gt;Root&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"HKCU"&lt;/span&gt; &lt;span class="na"&gt;Key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Software\\{{manufacturer}}\\{{product_name}}"&lt;/span&gt; &lt;span class="na"&gt;Name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Desktop Shortcut"&lt;/span&gt; &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"integer"&lt;/span&gt; &lt;span class="na"&gt;Value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"1"&lt;/span&gt; &lt;span class="na"&gt;KeyPath&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"yes"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/Component&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/Directory&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is no &lt;code&gt;Condition&lt;/code&gt;. In Windows Installer, a component without a condition is installed whenever its feature is installed.&lt;/p&gt;

&lt;p&gt;On top of that, Tauri uses a major upgrade:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;MajorUpgrade&lt;/span&gt; &lt;span class="na"&gt;Schedule&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"afterInstallInitialize"&lt;/span&gt; &lt;span class="na"&gt;...&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A major upgrade means &lt;code&gt;RemoveExistingProducts&lt;/code&gt; uninstalls the old version completely, and then every component of the new version is installed. The shortcut component is no exception, so it gets re-created no matter what the user did.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fix
&lt;/h2&gt;

&lt;p&gt;The idea: during an upgrade, only install the shortcut component if the shortcut still exists.&lt;/p&gt;

&lt;p&gt;First, a property that searches the desktop for &lt;code&gt;{{product_name}}.lnk&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;Property&lt;/span&gt; &lt;span class="na"&gt;Id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"DESKTOPSHORTCUTEXISTS"&lt;/span&gt; &lt;span class="na"&gt;Secure&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"yes"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;DirectorySearch&lt;/span&gt; &lt;span class="na"&gt;Id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"DesktopShortcutSearch"&lt;/span&gt; &lt;span class="na"&gt;Path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"[DesktopFolder]"&lt;/span&gt; &lt;span class="na"&gt;Depth&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"0"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;FileSearch&lt;/span&gt; &lt;span class="na"&gt;Id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"DesktopShortcutFile"&lt;/span&gt; &lt;span class="na"&gt;Name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"{{product_name}}.lnk"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/DirectorySearch&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/Property&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is evaluated by the standard &lt;code&gt;AppSearch&lt;/code&gt; action. If the file is found, the property is set to its path. Otherwise it stays unset.&lt;/p&gt;

&lt;p&gt;Then the component gets a condition:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;Component&lt;/span&gt; &lt;span class="na"&gt;Id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"ApplicationShortcutDesktop"&lt;/span&gt; &lt;span class="na"&gt;Guid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"*"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;Condition&amp;gt;&lt;/span&gt;NOT WIX_UPGRADE_DETECTED OR DESKTOPSHORTCUTEXISTS&lt;span class="nt"&gt;&amp;lt;/Condition&amp;gt;&lt;/span&gt;
    ...
&lt;span class="nt"&gt;&amp;lt;/Component&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;WIX_UPGRADE_DETECTED&lt;/code&gt; is set by WiX's &lt;code&gt;MajorUpgrade&lt;/code&gt; element when a previous version is found.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Scenario&lt;/th&gt;
&lt;th&gt;&lt;code&gt;WIX_UPGRADE_DETECTED&lt;/code&gt;&lt;/th&gt;
&lt;th&gt;&lt;code&gt;DESKTOPSHORTCUTEXISTS&lt;/code&gt;&lt;/th&gt;
&lt;th&gt;Result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Fresh install&lt;/td&gt;
&lt;td&gt;unset&lt;/td&gt;
&lt;td&gt;either&lt;/td&gt;
&lt;td&gt;shortcut created&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Upgrade, shortcut present&lt;/td&gt;
&lt;td&gt;set&lt;/td&gt;
&lt;td&gt;set&lt;/td&gt;
&lt;td&gt;shortcut re-created&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Upgrade, shortcut deleted&lt;/td&gt;
&lt;td&gt;set&lt;/td&gt;
&lt;td&gt;unset&lt;/td&gt;
&lt;td&gt;not created&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The diff is eight lines. Getting those eight lines right required checking two things.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why the existing HKCU registry value can't be used
&lt;/h3&gt;

&lt;p&gt;The component already has an HKCU &lt;code&gt;Desktop Shortcut&lt;/code&gt; registry value as its &lt;code&gt;KeyPath&lt;/code&gt;. It is tempting to use that as the signal, but it does not work: the value stays in the registry after the user deletes the &lt;code&gt;.lnk&lt;/code&gt;. The only way to know whether the shortcut exists is to look for the file with &lt;code&gt;FileSearch&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why &lt;code&gt;Secure="yes"&lt;/code&gt; is required
&lt;/h3&gt;

&lt;p&gt;This was the real trap.&lt;/p&gt;

&lt;p&gt;A Windows Installer install is split into a UI sequence (the dialogs) and an execute sequence (the elevated part that writes files). With full UI, &lt;code&gt;AppSearch&lt;/code&gt; runs in the UI sequence only; it does not run again in the execute sequence.&lt;/p&gt;

&lt;p&gt;Properties set in the UI sequence are not passed to the elevated execute sequence by default. Only properties listed in &lt;code&gt;SecureCustomProperties&lt;/code&gt; make it across. WiX's &lt;code&gt;Secure="yes"&lt;/code&gt; adds the property to that list.&lt;/p&gt;

&lt;p&gt;Without it, silent and &lt;code&gt;/passive&lt;/code&gt; installs work fine (they skip the UI sequence, so &lt;code&gt;AppSearch&lt;/code&gt; runs on the execute side), but double-clicking the installer leaves &lt;code&gt;DESKTOPSHORTCUTEXISTS&lt;/code&gt; always unset, and the shortcut silently disappears on every interactive upgrade. That is a nasty bug to ship, because the obvious way to test an installer is from the command line.&lt;/p&gt;

&lt;h3&gt;
  
  
  Action ordering
&lt;/h3&gt;

&lt;p&gt;Both properties must be set before the component condition is evaluated. The generated sequence is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FindRelatedProducts → AppSearch → CostFinalize → RemoveExistingProducts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;FindRelatedProducts&lt;/code&gt; sets &lt;code&gt;WIX_UPGRADE_DETECTED&lt;/code&gt;, &lt;code&gt;AppSearch&lt;/code&gt; sets &lt;code&gt;DESKTOPSHORTCUTEXISTS&lt;/code&gt;, and component conditions are evaluated in &lt;code&gt;CostFinalize&lt;/code&gt;. &lt;code&gt;RemoveExistingProducts&lt;/code&gt;, which deletes the old version's shortcut, comes after, so the file still exists when the search runs. I also checked that WiX 3.14 produced no new ICE warnings.&lt;/p&gt;

&lt;h2&gt;
  
  
  Verification
&lt;/h2&gt;

&lt;p&gt;Reading the template was not enough to be confident, so I built a minimal Tauri v2 app in three versions on Windows 11:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;v1 (1.0.0): built without the fix&lt;/li&gt;
&lt;li&gt;v2 (1.0.1) and v3 (1.0.2): built with the fix&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Every install ran with &lt;code&gt;msiexec /l*v&lt;/code&gt; logging, and I checked property values and component actions in the log.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Scenario&lt;/th&gt;
&lt;th&gt;Result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Fresh install v1 (&lt;code&gt;/passive&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;shortcut created&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Upgrade v1 → v2 with shortcut present (&lt;code&gt;/passive&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;DESKTOPSHORTCUTEXISTS&lt;/code&gt; set, shortcut refreshed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Delete shortcut, upgrade v2 → v3 (&lt;code&gt;/passive&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;WIX_UPGRADE_DETECTED&lt;/code&gt; set, &lt;code&gt;DESKTOPSHORTCUTEXISTS&lt;/code&gt; unset, component &lt;code&gt;Action: Null&lt;/code&gt;, shortcut stays deleted&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Uninstall&lt;/td&gt;
&lt;td&gt;shortcut removed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Full-UI upgrade v1 → v2 with shortcut present&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;Property(S): DESKTOPSHORTCUTEXISTS&lt;/code&gt; present on the execute side, shortcut refreshed&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The last row is the &lt;code&gt;Secure="yes"&lt;/code&gt; check. &lt;code&gt;Property(S)&lt;/code&gt; is the server-side (execute sequence) property, which confirms the UI-side search result reached the elevated process.&lt;/p&gt;

&lt;h2&gt;
  
  
  What came up in review
&lt;/h2&gt;

&lt;p&gt;FabianLars, one of the Tauri maintainers, left two comments.&lt;/p&gt;

&lt;h3&gt;
  
  
  "Isn't there a chance that this still re-orders the shortcut on the desktop?"
&lt;/h3&gt;

&lt;p&gt;Yes. If the shortcut still exists, &lt;code&gt;RemoveExistingProducts&lt;/code&gt; deletes the old &lt;code&gt;.lnk&lt;/code&gt; and the new component re-creates it. Windows stores desktop icon positions per file, so a delete-and-recreate moves the shortcut from wherever the user put it into the next free slot.&lt;/p&gt;

&lt;p&gt;This PR only fixes "a deleted shortcut comes back". It does not fix "an existing shortcut loses its position". NSIS keeps the position because in update mode it never touches the existing &lt;code&gt;.lnk&lt;/code&gt; beyond patching its target. Doing the same with a plain WiX component is hard, and it stays an open problem.&lt;/p&gt;

&lt;p&gt;One could argue the installer should just leave shortcuts alone on upgrade entirely. But the shortcut's target can change between versions (for example, when the main binary is renamed), so an existing shortcut has to be refreshed. FabianLars noted the same thing ("I forgot that the link target may change on updates") and we agreed on the current approach.&lt;/p&gt;

&lt;h3&gt;
  
  
  "I don't think this adds much value tbh"
&lt;/h3&gt;

&lt;p&gt;The PR originally included a unit test that rendered the Handlebars template and asserted the &lt;code&gt;&amp;lt;Condition&amp;gt;&lt;/code&gt; string was present. The comment was fair: that test only proves the template contains the XML written into it. It says nothing about installer behavior. I removed it.&lt;/p&gt;

&lt;p&gt;The verification that actually matters is the manual matrix above. Pretending a string-match test stands in for it was a mistake.&lt;/p&gt;

&lt;h2&gt;
  
  
  Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The UI and execute sequences are separate processes.&lt;/strong&gt; A value found in the UI sequence needs &lt;code&gt;Secure="yes"&lt;/code&gt; to reach the execute sequence. You will not find this bug if you only test with &lt;code&gt;/quiet&lt;/code&gt; or &lt;code&gt;/passive&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Component conditions are evaluated in &lt;code&gt;CostFinalize&lt;/code&gt;.&lt;/strong&gt; Any property used in a condition must be set by an earlier action such as &lt;code&gt;FindRelatedProducts&lt;/code&gt; or &lt;code&gt;AppSearch&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A major upgrade is remove-then-install.&lt;/strong&gt; You can control whether a file exists afterwards, but not its identity (icon position, for example).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;String-matching a template is not a behavior test.&lt;/strong&gt; For something like an installer, you have to build it and run it.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Closing
&lt;/h2&gt;

&lt;p&gt;Eight lines of diff, but they depend on understanding property propagation, action ordering and major upgrade semantics in Windows Installer. If you use &lt;code&gt;AppSearch&lt;/code&gt; results in a component condition in your own WiX project, check that the property is marked &lt;code&gt;Secure="yes"&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The fix was merged on November 12, 2026 and released on November 16 in tauri-bundler 2.10.5, tauri-cli 2.12.5 and &lt;code&gt;@tauri-apps/cli&lt;/code&gt; 2.12.5. If you ship an MSI with Tauri, rebuild with tauri-cli 2.12.5 or later. Note that the fix lives in the new version's installer, so it takes effect from the first update built with it.&lt;/p&gt;

</description>
      <category>tauri</category>
      <category>rust</category>
      <category>windows</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
