79433056

Date: 2025-02-12 12:37:03
Score: 3
Natty:
Report link

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:)

Reasons:
  • Blacklisted phrase (1): I have the same problem
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Me too answer (2.5): I have the same problem
  • Low reputation (0.5):
Posted by: Marc