Fix update pill never appearing in toolbar

@Published fires on willSet, so the Combine sink measured fittingSize
while SwiftUI still saw the old state (idle/EmptyView), getting 0x0.
Defer measurement to next run loop cycle so SwiftUI processes the
new state before we read fittingSize.
This commit is contained in:
Lawrence Chen 2026-02-08 19:03:25 -08:00
parent fc5d7eeb05
commit 498cc6e4bc

View file

@ -133,8 +133,12 @@ final class WindowToolbarController: NSObject, NSToolbarDelegate {
updateSizeCancellables[key] = updateViewModel.$state
.receive(on: DispatchQueue.main)
.sink { [weak self, weak view] _ in
guard let self, let view else { return }
self.sizeToolbarItem(for: key, hostingView: view)
// @Published fires on willSet, so SwiftUI hasn't processed the
// new state yet. Defer measurement to the next run loop cycle.
DispatchQueue.main.async { [weak self, weak view] in
guard let self, let view else { return }
self.sizeToolbarItem(for: key, hostingView: view)
}
}
return item
}