From 5d82a29f45bc732696a63f3907a995f17723e0df Mon Sep 17 00:00:00 2001 From: Lawrence Chen <54008264+lawrencecchen@users.noreply.github.com> Date: Wed, 11 Mar 2026 18:21:41 -0700 Subject: [PATCH] Repair local-host devtools reparent geometry --- Sources/Panels/BrowserPanelView.swift | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Sources/Panels/BrowserPanelView.swift b/Sources/Panels/BrowserPanelView.swift index d11a67cf..e029499b 100644 --- a/Sources/Panels/BrowserPanelView.swift +++ b/Sources/Panels/BrowserPanelView.swift @@ -4992,6 +4992,8 @@ struct WebViewRepresentable: NSViewRepresentable { return true } guard !relatedSubviews.isEmpty else { return } + let preserveSlotLocalFrames = sourceSuperview is WindowBrowserSlotView + let sourceSlotBoundsSize = sourceSuperview.bounds.size #if DEBUG dlog( "browser.localHost.reparent.batch reason=\(reason) source=\(Self.objectID(sourceSuperview)) " + @@ -5000,11 +5002,17 @@ struct WebViewRepresentable: NSViewRepresentable { ) #endif for view in relatedSubviews { - let frameInWindow = sourceSuperview.convert(view.frame, to: nil) let className = String(describing: type(of: view)) + let targetFrame: NSRect + if preserveSlotLocalFrames { + targetFrame = view.frame + } else { + let frameInWindow = sourceSuperview.convert(view.frame, to: nil) + targetFrame = container.convert(frameInWindow, from: nil) + } view.removeFromSuperview() container.addSubview(view, positioned: .above, relativeTo: nil) - view.frame = container.convert(frameInWindow, from: nil) + view.frame = targetFrame #if DEBUG dlog( "browser.localHost.reparent.batch.item reason=\(reason) class=\(className) " + @@ -5012,6 +5020,11 @@ struct WebViewRepresentable: NSViewRepresentable { ) #endif } + if preserveSlotLocalFrames, sourceSlotBoundsSize != container.bounds.size { + container.resizeSubviews(withOldSize: sourceSlotBoundsSize) + container.needsLayout = true + container.layoutSubtreeIfNeeded() + } } private static func installPortalAnchorView(_ anchorView: NSView, in host: NSView) {