I have the same problem with .sheet(item:)
After dismissing the sheet, the URLSheet view gets evaluated again (even though it is not shown anymore), and catastrophically for me its .task
is run a second time, thus trying to open the URL a second time...
@State private var urlToOpen: URL? = nil
MainContent(urlToOpen: $urlToOpen) // 1
.sheet(item: $urlToOpen, onDismiss: sheetDismissed) { url in
let sheet = URLSheet(urlToOpen: url)
Sheet(sheetView: AnyView(sheet))
}
.onOpenURL { url in
urlToOpen = url // raise sheet
}
I tried to pass urlToOpen
as binding to MainContent, see // 1
.
But sadly your solution doesn't work for .sheet(item:)