-
Notifications
You must be signed in to change notification settings - Fork 84
Initialize the root locale for NSHostingView on macOS #968
Copy link
Copy link
Closed
Labels
area: hosting-bridgeSwiftUI bridge, UIHosting/NSHosting, representables, and platform host views.SwiftUI bridge, UIHosting/NSHosting, representables, and platform host views.area: textText, labels, line style, and text rendering APIs.Text, labels, line style, and text rendering APIs.platform: macOSmacOS-specific behavior or support.macOS-specific behavior or support.type: bugSomething is not working correctly.Something is not working correctly.
Description
Activity
Metadata
Metadata
Assignees
Labels
area: hosting-bridgeSwiftUI bridge, UIHosting/NSHosting, representables, and platform host views.SwiftUI bridge, UIHosting/NSHosting, representables, and platform host views.area: textText, labels, line style, and text rendering APIs.Text, labels, line style, and text rendering APIs.platform: macOSmacOS-specific behavior or support.macOS-specific behavior or support.type: bugSomething is not working correctly.Something is not working correctly.
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.