You can prevent this affecting subview by re-setting it to the original:
import SwiftUI
struct TabsView: View {
@Environment(.horizontalSizeClass) var horizontalSizeClass
var body: some View {
TabView() {
Text("Tab A")
.environment(.horizontalSizeClass, horizontalSizeClass)
Text("Tab B")
.environment(\.horizontalSizeClass, horizontalSizeClass)
}
.environment(\.horizontalSizeClass, .compact)
}
}