I will file a bug report. Any complex UI that takes more than a few seconds to render the preview will cause this issue in Xcode 16. Below is an example view that takes a while to render in preivew. This allows you to run debug while the preview is still rendering. The result is the app loads twice with two icons in the dock. I'll post a bug number once I submit.
import SwiftUI
struct ComplexView: View {
let itemCount = 10_000
var gradientColors: [Color] = [.blue, .purple, .pink, .red, .orange, .yellow]
var body: some View {
ScrollView {
VStack {
Text("Rendering Complex View")
.font(.largeTitle)
.padding()
// Heavy Custom Graphics and Layered Canvas Drawing
Canvas { context, size in
let gradient = Gradient(colors: gradientColors)
// Correcting the gradient fill
context.fill(Path(ellipseIn: CGRect(x: 0, y: 0, width: size.width, height: size.height)),
with: .linearGradient(gradient, startPoint: .zero, endPoint: CGPoint(x: size.width, y: size.height)))
// Stroked ellipses to add complexity
for i in 1..<50 {
let rect = CGRect(x: CGFloat(i) * 10, y: CGFloat(i) * 10, width: size.width / 2, height: size.height / 2)
context.stroke(Path(ellipseIn: rect), with: .color(.black), lineWidth: 1)
}
}
.frame(height: 500)
.padding()
// Expensive ForEach with Thousands of Views
ForEach(0..<itemCount, id: \.self) { index in
HStack {
Circle()
.fill(gradientColors[index % gradientColors.count])
.frame(width: 30, height: 30)
.shadow(radius: 10)
Text("Item \(index)")
.font(.headline)
.foregroundColor(.primary)
}
.padding(.vertical, 2)
}
}
}
}
}
struct ComplexView_Previews: PreviewProvider {
static var previews: some View {
ComplexView()
}
}