Xcode 13.3 breaks WidgetPreviewContext / WidgetFamily

The widget family obtained via @Environment(\.widgetFamily) is wrong when preview widgets in Xcode 13.3.

The problem can be reproduced by creating a default app project and a widget extension in Xcode 13.3.

Hi,

Sorry to hear you are having problems with widget previews. You are encountering a known issue that we hope to fix in a future release. Unfortunately I don't have any workarounds to offer you either, beyond passing in the family separate from the previewContext. Example:

struct MyWidgetEntryView : View {
    var entry: Provider.Entry
    let overridenWidgetFamily: WidgetFamily?
    @Environment(\.widgetFamily) var widgetFamily
    <…>
}

struct MyWidget_Previews: PreviewProvider {
    static var previews: some View {
        MyWidgetEntryView(entry: SimpleEntry(date: Date()), overridenWidgetFamily: .systemSmall)
            .previewContext(WidgetPreviewContext(family: .systemSmall))
    }
}
Xcode 13.3 breaks WidgetPreviewContext / WidgetFamily
 
 
Q