Skip to content

Commit 4429f7b

Browse files
authored
Perception checking: Fall back on current perception state (#3762)
* Suppress more potential perception checks/warnings * wip
1 parent 5638930 commit 4429f7b

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

Sources/ComposableArchitecture/Core.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ final class ScopedCore<Base: Core, State, Action>: Core {
205205
let stateKeyPath: KeyPath<Base.State, State>
206206
let actionKeyPath: CaseKeyPath<Base.Action, Action>
207207
#if DEBUG
208-
let isInPerceptionTracking = _PerceptionLocals.isInPerceptionTracking
208+
let initializedInPerceptionTracking = _isInPerceptionTracking
209209
#endif
210210
init(
211211
base: Base,
@@ -220,7 +220,9 @@ final class ScopedCore<Base: Core, State, Action>: Core {
220220
@inline(__always)
221221
var state: State {
222222
#if DEBUG
223-
return _PerceptionLocals.$skipPerceptionChecking.withValue(isInPerceptionTracking) {
223+
return _PerceptionLocals.$skipPerceptionChecking.withValue(
224+
initializedInPerceptionTracking || _isInPerceptionTracking
225+
) {
224226
base.state[keyPath: stateKeyPath]
225227
}
226228
#else

Sources/ComposableArchitecture/Observation/IdentifiedArray+Observation.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ extension Store where State: ObservableState {
9292
public struct _StoreCollection<ID: Hashable & Sendable, State, Action>: RandomAccessCollection {
9393
private let store: Store<IdentifiedArray<ID, State>, IdentifiedAction<ID, Action>>
9494
private let data: IdentifiedArray<ID, State>
95-
private let isInPerceptionTracking = _isInPerceptionTracking
95+
private let initializedInPerceptionTracking = _isInPerceptionTracking
9696

9797
#if swift(<5.10)
9898
@MainActor(unsafe)
@@ -146,7 +146,9 @@ public struct _StoreCollection<ID: Hashable & Sendable, State, Action>: RandomAc
146146
return child
147147
}
148148
#if DEBUG
149-
return _PerceptionLocals.$isInPerceptionTracking.withValue(self.isInPerceptionTracking) {
149+
return _PerceptionLocals.$isInPerceptionTracking.withValue(
150+
self.initializedInPerceptionTracking || _isInPerceptionTracking
151+
) {
150152
child
151153
}
152154
#else

Sources/ComposableArchitecture/Store.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ public final class Store<State, Action>: _Store {
336336
func subscribeToDidSet<T: ObservableState>(_ type: T.Type) -> AnyCancellable {
337337
return core.didSet
338338
.prefix { [weak self] _ in self?.core.isInvalid == false }
339-
.compactMap { [weak self] in (self?.currentState as? T)?._$id }
339+
.compactMap { [weak self] in (self?.withState(\.self) as? T)?._$id }
340340
.removeDuplicates()
341341
.dropFirst()
342342
.sink { [weak self, weak parent] _ in

0 commit comments

Comments
 (0)