Skip to content

Commit 2c17a93

Browse files
authored
Fix ephemeral dismissal (#3286)
* Fix ephemeral dismissal This regression was introduced to fix a UIKit warning, but it causes state to not be `nil`'d out in SwiftUI. Luckily we caught it before a release. * wip
1 parent 27adbdc commit 2c17a93

File tree

3 files changed

+32
-35
lines changed

3 files changed

+32
-35
lines changed

Sources/ComposableArchitecture/Observation/Store+Observation.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,7 @@
375375
}
376376
set {
377377
if newValue == nil,
378-
let childState = self.state[keyPath: state],
379-
!isEphemeral(childState),
378+
self.state[keyPath: state] != nil,
380379
!self._isInvalidated()
381380
{
382381
self.send(action(.dismiss))

Tests/ComposableArchitectureTests/Reducers/PresentationReducerTests.swift

+31
Original file line numberDiff line numberDiff line change
@@ -2653,6 +2653,37 @@ final class PresentationReducerTests: BaseTCATestCase {
26532653
$0.child?.child = nil
26542654
}
26552655
}
2656+
2657+
@Reducer
2658+
struct TestEphemeralBindingDismissalFeature {
2659+
@ObservableState
2660+
struct State: Equatable {
2661+
@Presents var alert: AlertState<Never>?
2662+
}
2663+
enum Action: Equatable {
2664+
case alert(PresentationAction<Never>)
2665+
}
2666+
var body: some ReducerOf<Self> {
2667+
Reduce { state, action in
2668+
return .none
2669+
}
2670+
.ifLet(\.$alert, action: /Action.alert)
2671+
}
2672+
}
2673+
@MainActor
2674+
func testEphemeralBindingDismissal() async {
2675+
@Perception.Bindable var store = Store(
2676+
initialState: TestEphemeralBindingDismissalFeature.State(
2677+
alert: AlertState { TextState("Oops!") }
2678+
)
2679+
) {
2680+
TestEphemeralBindingDismissalFeature()
2681+
}
2682+
2683+
XCTAssertNotNil(store.alert)
2684+
$store.scope(state: \.alert, action: \.alert).wrappedValue = nil
2685+
XCTAssertNil(store.alert)
2686+
}
26562687
}
26572688

26582689
@Reducer

Tests/ComposableArchitectureTests/RuntimeWarningTests.swift

-33
Original file line numberDiff line numberDiff line change
@@ -324,38 +324,5 @@
324324
"""
325325
}
326326
}
327-
328-
@Reducer
329-
struct TestStoreDestination_NotIntegrated_EphemeralState {
330-
@Reducer
331-
struct Destination {}
332-
@ObservableState
333-
struct State: Equatable {
334-
@Presents var alert: AlertState<Never>?
335-
}
336-
enum Action {
337-
case alert(PresentationAction<Never>)
338-
}
339-
}
340-
@MainActor
341-
func testStoreDestination_NotIntegrated_EphemeralState() {
342-
let store = Store(
343-
initialState: TestStoreDestination_NotIntegrated_EphemeralState.State(
344-
alert: .init(title: { TextState("Hi") })
345-
)
346-
) {
347-
TestStoreDestination_NotIntegrated_EphemeralState()
348-
}
349-
350-
store[
351-
state: \.alert,
352-
action: \.alert,
353-
isInViewBody: false,
354-
fileID: "file.swift",
355-
filePath: "/file.swift",
356-
line: 1,
357-
column: 1
358-
] = nil // NB: Not issue reported
359-
}
360327
}
361328
#endif

0 commit comments

Comments
 (0)