Repository navigation
Description
Current behavior 🐛
On Skia macOS, a native element's peer is destroyed when the element leaves the visual tree, not when its owner is disposed. MacOSNativeElement calls DisposeNativePeer() from its Unloaded handler, and Unloaded fires on any tree leave — including a reparent, which is immediately followed by Loaded.
The result is that a native-hosted control cannot be reparented on macOS. Every operation after the move targets a peer that no longer exists.
macOS is the only backend that does this:
| Backend | DetachNativeElement behaviour |
|---|---|
| X11 | Reparents the X window to root and unmaps it — the window survives |
| Win32 | Hides the HWND and calls SetParent(HWND.Null); a code comment states "WS_CHILD stays set across detach/re-attach cycles" — re-attach is explicitly supported |
| macOS | Destroys the peer |
This is compounded by ContentPresenter already pairing EnterImpl → AttachNativeElement with LeaveImpl → DetachNativeElement, and uno_native_detach already parking the view in transients precisely so that it survives. The Unloaded hook is a second, destructive teardown on the same transition.
Expected behavior 🎯
Detaching a native element parks its peer so a subsequent attach can reuse it, matching X11 and Win32. Reparenting a WebView2 or MediaPlayerElement on macOS should preserve the peer, not destroy it.
How to reproduce it (as minimally and precisely as possible) 🔬
Reparent a native-hosted element on Skia macOS:
border.Child = null; // Unloaded -> DisposeNativePeer()
border.Child = webView; // Loaded, but the peer is gone
await webView.CoreWebView2.NavigateToString(html); // operates on a destroyed peerCovered by the existing runtime tests When_WebMessageReceived_After_RemoveAdd and When_MediaPlayerElement_SetIsFullWindow_Check_Fullscreen.
Before #24112 this was a hard SIGSEGV in libUnoNativeMac that took down the whole test host. #24112 makes it a logged no-op, so the operation now fails instead of crashing the process — but the underlying lifetime defect is untouched.
Workaround 🛠️
None. Avoid reparenting native-hosted elements on macOS.
Why the Unloaded hook cannot simply be deleted
Two pieces are missing, which is why #24112 did not attempt it:
uno_native_attachnever removes the element fromtransients, so that static set only ever grows. TheUnloadeddispose is currently the only thing draining it. Removing the hook without a replacement trades a crash for an unboundedNSViewleak across every macOS-hosted control.- There is no owner-driven disposal signal.
CoreWebView2has noDispose, only the tree-scopedOnLoaded/OnUnloaded, so the peer's lifetime is effectively the GC lifetime of theWebView2element.
A correct fix therefore needs uno_native_attach to drain transients when an element re-enters elements, plus a real disposal signal from the owner — a new lifetime contract rather than a patch.
Renderer 🎨
Skia
Affected platforms 📱💻🖥️
macOS (Skia)
Anything else we need to know? 💬
Analysis by @Xiaoy312 while triaging the macOS Segmentation fault: 11 CI failures that led to #24112. Related latent instance of the same class of bug: the MacOSMediaPlayerPresenterExtension shadow-handle issue filed separately.
Activity