Why are asynchronous tasks not executed in Xcode Canvas, and why do they only work in the simulator?

Hi everyone, I'm new to Xcode and iOS development. I've encountered an issue where asynchronous tasks seem to not execute in Xcode Canvas, but they work fine in the simulator. Can anyone explain why this might be happening or what I could do to fix it? Thank you for your help!

struct PartnerProfileView: View {
   @State private var showSheet: Bool = true
   let partnerName: String
   
   var body: some View {
      ZStack(alignment: .bottom) {
         Color("EFEFF4_0F2534")
         
         ScrollView(showsIndicators: false) {
            headerSection()
            
            infoSection()
               .padding(.bottom, 5)
            
            sectionTitle("Other Skills")
            
            skillsGrid()
            
            sectionTitle("···")
            
            dynamicsSection()
         }
         .frame(maxWidth: .infinity, maxHeight: .infinity)
         
         CustomTabBar()
      }
      .navigationBarHidden(true)
      .ignoresSafeArea(edges: .all)
      .onAppear {
         print("PartnerProfileView received")
         Task {
            await BottomCustomPopup().present()
         }
      }
      .onChange(of: showSheet) { oldState, newValue in
         print("oldState \(oldState)")
         print("newValue \(newValue)")
      }
   }
}

//@MainActor
struct BottomCustomPopup: BottomPopup {
    var body: some View {
        HStack(spacing: 0) {
            Text("Hello World")
            Spacer()
            Button(action: { Task { await dismissLastPopup() }}) { Text("Dismiss") }
        }
        .padding(.vertical, 20)
        .padding(.leading, 24)
        .padding(.trailing, 16)
    }
}

Hi,

Sorry to hear you are having problems getting Task working in previews. There is a chance you are hitting some bug, but mostly Task works. The above code mostly seems like it should work, but we are missing some pieces of code like BottomPopup.

Would it make sense for you to file a feedback with a sample project that reproduce the issue so we can take a look?

In addition we will likely need the diagnostics Xcode Previews generates in order to make sure we understand more about your configuration, etc.

Install the logging profile using instructions available here: https://developer.apple.com/bug-reporting/profiles-and-logs/?name=swift On your mac running Xcode, and on your physical preview device (if you are using one).

Install the logging profile using the following instructions on your mac running Xcode; and if you are using one, your physical preview device (iOS or visionOS): https://developer.apple.com/bug-reporting/profiles-and-logs/?name=swift

Then when you reproduce the problem in Xcode:

  1. Either (a) an error banner will appear, click the "Diagnostics" button in that banner; or (b) if you're not seeing an error but you still want to provide diagnostics you can get the same diagnostics window by going under the Editor menu in the menu bar, then selecting the Canvas submenu, then selecting "Diagnostics".
  2. In the sheet that appears, click "Generate Report" in the bottom left of the sheet
  3. Attach (or make from the folder) the resulting zip file to the bug (will be named something like previews-diagnostics-0123456789.zip)
  4. Generate a sysdiagnose on your mac and any on-device preview devices, and attach those too
Why are asynchronous tasks not executed in Xcode Canvas, and why do they only work in the simulator?
 
 
Q