Skip to content

Commit 442c7de

Browse files
committed
Identify stores based off state identity
Potential fix for #3451.
1 parent 59fdf28 commit 442c7de

File tree

4 files changed

+30
-7
lines changed

4 files changed

+30
-7
lines changed

ComposableArchitecture.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ let package = Package(
2121
.package(url: "https://github.com/apple/swift-collections", from: "1.1.0"),
2222
.package(url: "https://github.com/pointfreeco/combine-schedulers", from: "1.0.2"),
2323
.package(url: "https://github.com/pointfreeco/swift-case-paths", from: "1.5.4"),
24-
.package(url: "https://github.com/pointfreeco/swift-concurrency-extras", from: "1.2.0"),
24+
.package(
25+
url: "https://github.com/pointfreeco/swift-concurrency-extras",
26+
branch: "any-hashable-sendable-flexibility"
27+
),
2528
.package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "1.3.2"),
2629
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.4.0"),
2730
.package(url: "https://github.com/pointfreeco/swift-identified-collections", from: "1.1.0"),

[email protected]

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ let package = Package(
2121
.package(url: "https://github.com/apple/swift-collections", from: "1.1.0"),
2222
.package(url: "https://github.com/pointfreeco/combine-schedulers", from: "1.0.2"),
2323
.package(url: "https://github.com/pointfreeco/swift-case-paths", from: "1.5.4"),
24-
.package(url: "https://github.com/pointfreeco/swift-concurrency-extras", from: "1.2.0"),
24+
.package(
25+
url: "https://github.com/pointfreeco/swift-concurrency-extras",
26+
branch: "any-hashable-sendable-flexibility"
27+
),
2528
.package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "1.3.2"),
2629
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.4.0"),
2730
.package(url: "https://github.com/pointfreeco/swift-identified-collections", from: "1.1.0"),

Sources/ComposableArchitecture/Observation/Store+Observation.swift

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,24 @@ extension Store: Hashable {
3636
}
3737
}
3838

39-
extension Store: Identifiable {}
39+
extension Store: Identifiable {
40+
public struct ID: Hashable {
41+
fileprivate let objectIdentifier: ObjectIdentifier
42+
fileprivate let stateIdentifier: AnyHashableSendable?
43+
}
44+
45+
public nonisolated var id: ID {
46+
ID(
47+
objectIdentifier: ObjectIdentifier(self),
48+
stateIdentifier: Thread.isMainThread
49+
? MainActor.assumeIsolated {
50+
((currentState as? any Identifiable)?.id as? any Hashable)
51+
.map(AnyHashableSendable.init)
52+
}
53+
: nil
54+
)
55+
}
56+
}
4057

4158
extension Store where State: ObservableState {
4259
/// Scopes the store to optional child state and actions.
@@ -395,7 +412,7 @@ extension Store where State: ObservableState {
395412
set {
396413
if newValue == nil,
397414
let childState = self.state[keyPath: state],
398-
id == _identifiableID(childState),
415+
id == nil || id == _identifiableID(childState),
399416
!self._isInvalidated()
400417
{
401418
self.send(action(.dismiss))

0 commit comments

Comments
 (0)