Share popover: ignore an earlier popover's late close (#178, finding 3)
popoverDidClose tore down whatever popover was showing, so an earlier one's close arriving after a new one had opened would close the new one's panel bookkeeping (and drop its once-only URL). It now acts only on its own popover's notification. Test: SharePopoverTests.testAnOldPopoversLateCloseLeavesTheNewOneAlone, which fails without the guard.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,
+23
−1
native/apple/Sources/DocsKit/DocsSharePopover.swift+6 −1native/apple/Tests/DocsWindowTests/SharePopoverTests.swift+17 −0
diff --git a/native/apple/Sources/DocsKit/DocsSharePopover.swift b/native/apple/Sources/DocsKit/DocsSharePopover.swift| index 33bb3ac..9ce421f 100644 |
| --- a/native/apple/Sources/DocsKit/DocsSharePopover.swift |
| +++ b/native/apple/Sources/DocsKit/DocsSharePopover.swift |
| @@ -77,7 +77,12 @@ import SwiftUI |
| return true |
| } |
| - func popoverDidClose(_ notification: Notification) { finish() } |
| + /// Only this popover's own close: an earlier one's, arriving late, must |
| + /// not tear down the one showing now (Fable on #178, finding 3). |
| + func popoverDidClose(_ notification: Notification) { |
| + guard let closed = notification.object as? NSPopover, closed === popover else { return } |
| + finish() |
| + } |
| private func finish() { |
| guard popover != nil else { return } |
diff --git a/native/apple/Tests/DocsWindowTests/SharePopoverTests.swift b/native/apple/Tests/DocsWindowTests/SharePopoverTests.swift| index d744a6b..21ac4e8 100644 |
| --- a/native/apple/Tests/DocsWindowTests/SharePopoverTests.swift |
| +++ b/native/apple/Tests/DocsWindowTests/SharePopoverTests.swift |
| @@ -164,6 +164,23 @@ import XCTest |
| XCTAssertEqual(share.popover?.behavior, .transient) |
| } |
| + /// Fable on #178, finding 3: an earlier popover's close, arriving after |
| + /// a new one has opened, leaves the new one alone. |
| + func testAnOldPopoversLateCloseLeavesTheNewOneAlone() async throws { |
| + let hosted = try await host() |
| + defer { Task { await close(hosted) } } |
| + let share = try await openShare(hosted) |
| + let old = try XCTUnwrap(share.popover) |
| + share.dismiss() |
| + try await until("closed") { share.popover == nil } |
| + _ = try await openShare(hosted) |
| + let current = try XCTUnwrap(share.popover) |
| + XCTAssertFalse(current === old) |
| + share.popoverDidClose(Notification(name: NSPopover.didCloseNotification, object: old)) |
| + XCTAssertTrue(share.popover === current && current.isShown, "the new popover is still the one showing") |
| + XCTAssertNotNil(share.panel, "and its panel is still there") |
| + } |
| + |
| func testEscClosesItAndReturnsTheKeyboardToShare() async throws { |
| let hosted = try await host() |
| defer { Task { await close(hosted) } } |