SwiftUI refresh while alert is visible

Does causing a swiftui view refresh via modifying observed properties while an alert is visible allowed? I am seeing a warning 'Presenting view controller <SwiftUI.PlatformAlertController> from detached view controller <B> is not supported, and may result in incorrect safe area insets and a corrupt root presentation. Make sure <SwiftUI.PlatformAlertController> is in the view hierarchy before presenting from it. Will become a hard exception in a future release.'

and the warning

'Attempt to present <SwiftUI.PlatformAlertController> on <A> (from <B>) while a presentation is in progress'.

The second warning occurs more often.

@tridiak It’s probably a case where you’re putting PlatformAlertController in the view hierarchy without adding it as a childViewController, and then presenting PlatformAlertController from this “detached” view controller.

It'll be great to get a test project that reproduces the issue. please share a link to your test project. That'll help us better understand what's going on. If you're not familiar with preparing a test project, take a look at Creating a test project.

I am not using UIKit in any way. It is pure SwiftUI. My guess is when the view the alert is displaying changes due to observed properties, the alert FW tries to redisplay the alert , sees it is already visible and emits the warning. I'll try to create a simple example over the next few days.

Submitted a bug to feedback assistant. FB16778512

Contains cutdown project which shows the bug.

Limited work around for the bug is to create a @State var in StdView.

@State private var alertVis

init(...) {
	...
	self._alertVis = State(initialValue: HNCModel.instance.alertVis)
}

var body : some View {
	VStack {
	...
	}.alert("text", isPresented: @alertVis) {...}

}

Setting HNCModel.alertVis vis showAlert() shows the alert and there is no 'Attempt to present...' warning. But the alert is not auto dismissed when the hncModel alertVis value is set to false.

Ignore previous post. Fix is limited.

SwiftUI refresh while alert is visible
 
 
Q