@@ -149,8 +149,17 @@ public class LiveSessionCoordinator<R: RootRegistry>: ObservableObject {
149
149
// extract the root layout, removing anything within the `<div data-phx-main>`.
150
150
let mainDiv = try doc. select ( " div[data-phx-main] " ) [ 0 ]
151
151
try mainDiv. replaceWith ( doc. createElement ( " phx-main " ) )
152
- self . stylesheet = try ? doc. select ( " Style " ) . reduce ( Stylesheet < R > ( content: [ ] , classes: [ : ] ) ) {
153
- ( try ? Stylesheet < R > ( from: $1. text ( ) , in: . init( ) ) . merge ( with: $0) ) ?? $0
152
+ async let stylesheet = withThrowingTaskGroup ( of: ( Data, URLResponse) . self) { group in
153
+ for style in try doc. select ( " Style " ) {
154
+ guard let url = URL ( string: try style. attr ( " url " ) , relativeTo: url)
155
+ else { continue }
156
+ group. addTask { try await self . configuration. urlSession. data ( from: url) }
157
+ }
158
+ return try await group. reduce ( Stylesheet < R > ( content: [ ] , classes: [ : ] ) ) { result, next in
159
+ guard let contents = String ( data: next. 0 , encoding: . utf8)
160
+ else { return result }
161
+ return result. merge ( with: try Stylesheet < R > ( from: contents, in: . init( ) ) )
162
+ }
154
163
}
155
164
self . rootLayout = try LiveViewNativeCore . Document. parse ( doc. outerHtml ( ) )
156
165
@@ -160,6 +169,8 @@ public class LiveSessionCoordinator<R: RootRegistry>: ObservableObject {
160
169
try await self . connectSocket ( domValues)
161
170
}
162
171
172
+ self . stylesheet = try await stylesheet
173
+
163
174
try await navigationPath. last!. coordinator. connect ( domValues: domValues, redirect: false )
164
175
} catch {
165
176
self . state = . connectionFailed( error)
0 commit comments