Summary
NSHostingView creates an EnvironmentValues instance and passes it to the view graph without applying root environment configuration.
The default locale is Locale(identifier: ""), so Text(_:format:) passes an empty locale to Foundation instead of using the current system locale. This causes TextHeightUITests/dateFormatStyleExample() to fail on macOS.
Current behavior
For the fixed date used by TextFormatStyleExample, OpenSwiftUI renders:
2026-01-01
2026 M01 1, Thu 8:00:00 AM GMT+8
08:00
SwiftUI renders:
1/1/2026
Thursday, January 1, 2026 at 08:00:00 GMT+8
08:00
Formatting an equivalent Date.FormatStyle directly with Locale(identifier: "") reproduces the OpenSwiftUI output.
Expected behavior
The macOS root environment should use the current system locale unless a view explicitly overrides it. TextHeightUITests/dateFormatStyleExample() should match the SwiftUI reference.
Implementation notes
EnvironmentValues.configureForRoot() initializes locale, calendar, and timeZone.
- UIKit applies this configuration when constructing its root environment.
NSHostingView.updateEnvironment() currently forwards a plain EnvironmentValues() without applying it.
Summary
NSHostingViewcreates anEnvironmentValuesinstance and passes it to the view graph without applying root environment configuration.The default locale is
Locale(identifier: ""), soText(_:format:)passes an empty locale to Foundation instead of using the current system locale. This causesTextHeightUITests/dateFormatStyleExample()to fail on macOS.Current behavior
For the fixed date used by
TextFormatStyleExample, OpenSwiftUI renders:2026-01-012026 M01 1, Thu 8:00:00 AM GMT+808:00SwiftUI renders:
1/1/2026Thursday, January 1, 2026 at 08:00:00 GMT+808:00Formatting an equivalent
Date.FormatStyledirectly withLocale(identifier: "")reproduces the OpenSwiftUI output.Expected behavior
The macOS root environment should use the current system locale unless a view explicitly overrides it.
TextHeightUITests/dateFormatStyleExample()should match the SwiftUI reference.Implementation notes
EnvironmentValues.configureForRoot()initializeslocale,calendar, andtimeZone.NSHostingView.updateEnvironment()currently forwards a plainEnvironmentValues()without applying it.