From 1b1355cf1fccf4f117bd354ca06c7b497233c003 Mon Sep 17 00:00:00 2001 From: Stephen Celis Date: Fri, 5 Jan 2024 18:21:28 -0800 Subject: [PATCH] Fix retain cycle in `PresentationModifier` (#2697) --- .../SwiftUI/PresentationModifier.swift | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Sources/ComposableArchitecture/SwiftUI/PresentationModifier.swift b/Sources/ComposableArchitecture/SwiftUI/PresentationModifier.swift index bb1c8b41cf44..7636fb495cf9 100644 --- a/Sources/ComposableArchitecture/SwiftUI/PresentationModifier.swift +++ b/Sources/ComposableArchitecture/SwiftUI/PresentationModifier.swift @@ -285,11 +285,12 @@ public struct PresentationStore< ? toID($0).map { AnyIdentifiable(Identified($0) { $0 }) } : nil }, - compactSend: { + compactSend: { [weak viewStore = self.viewStore] in guard + let viewStore = viewStore, $0 == nil, - self.viewStore.wrappedValue != nil, - id == nil || self.toID(self.viewStore.state) == id + viewStore.wrappedValue != nil, + id == nil || self.toID(viewStore.state) == id else { return nil } return .dismiss }