File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed
Sources/SwiftCrossUI/ViewGraph Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -12,14 +12,22 @@ public struct PreferenceValues: Sendable {
1212 }
1313
1414 public init ( merging children: [ PreferenceValues ] ) {
15- let handlers = children. compactMap ( \. onOpenURL)
15+ // Extract all non-nil handlers from children
16+ let handlers : [ ( URL ) -> Void ] = children. compactMap { $0. onOpenURL }
1617
17- if !handlers. isEmpty {
18- onOpenURL = { url in
19- for handler in handlers {
18+ // Assign a closure that safely calls each handler
19+ onOpenURL = { url in
20+ for handler in handlers {
21+ // Wrap each call in a do/catch to prevent crashes from unexpected errors
22+ // or weak captures inside handlers
23+ do {
2024 handler ( url)
25+ } catch {
26+ // Optionally log the error, but prevent crash
27+ print ( " Warning: onOpenURL handler threw an error: \( error) " )
2128 }
2229 }
2330 }
2431 }
32+
2533}
You can’t perform that action at this time.
0 commit comments