Canvas crashes with Task code

Good day! It seems to be a bug in Xcode that preview can be showed correctly with async code wrapped in Task, for ex:

struct MyView: View {
    var onTapped: (() async -> Bool)?

    var body: some View {
Button {
            Task {
                guard await onTapped?() ?? true else { return }
            }
            .....

        } label: {
                 Text("Tap me")
        }
    }
}

    

Same error for me, did you find a solution? To me has started occuring after updating macOS to 12.3

@gemix, yeap, for now only via crutch, lol, to wrap task in2 this:

if ProcessInfo
                .processInfo
                .environment["XCODE_RUNNING_FOR_PREVIEWS"] != "1" {
                        Task {
                            .... }
               }

This one detects preview 🤷🏼‍♂️

Canvas crashes with Task code
 
 
Q