File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed
Sources/LiveViewNative/Coordinators Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -148,6 +148,10 @@ public class LiveSessionCoordinator<R: RootRegistry>: ObservableObject {
148
148
public convenience init ( _ url: URL , config: LiveSessionConfiguration = . init( ) ) where R == EmptyRegistry {
149
149
self . init ( url, config: config, customRegistryType: EmptyRegistry . self)
150
150
}
151
+
152
+ deinit {
153
+ self . liveReloadListenerLoop? . cancel ( )
154
+ }
151
155
152
156
/// Connects this coordinator to the LiveView channel.
153
157
///
@@ -202,10 +206,14 @@ public class LiveSessionCoordinator<R: RootRegistry>: ObservableObject {
202
206
guard let url = await URL ( string: style, relativeTo: self . url)
203
207
else { continue }
204
208
group. addTask {
205
- let ( data, _) = try await URLSession . shared. data ( from: url)
206
- guard let contents = String ( data: data, encoding: . utf8)
207
- else { return await Stylesheet < R > ( content: [ ] , classes: [ : ] ) }
208
- return try await Stylesheet < R > ( from: contents, in: . init( ) )
209
+ if let cached = await StylesheetCache . shared. read ( for: url, registry: R . self) {
210
+ return cached
211
+ } else {
212
+ let ( data, _) = try await URLSession . shared. data ( from: url)
213
+ guard let contents = String ( data: data, encoding: . utf8)
214
+ else { return await Stylesheet < R > ( content: [ ] , classes: [ : ] ) }
215
+ return try await Stylesheet < R > ( from: contents, in: . init( ) )
216
+ }
209
217
}
210
218
}
211
219
Original file line number Diff line number Diff line change @@ -65,6 +65,11 @@ public class LiveViewCoordinator<R: RootRegistry>: ObservableObject {
65
65
self . session = session
66
66
self . url = url
67
67
}
68
+
69
+ deinit {
70
+ self . eventListenerLoop? . cancel ( )
71
+ self . statusListenerLoop? . cancel ( )
72
+ }
68
73
69
74
/// Pushes a LiveView event with the given name and payload to the server.
70
75
///
You can’t perform that action at this time.
0 commit comments