Skip to content

Commit 89f8104

Browse files
committed
Only call setNeedsEnvironmentUpdate() on descendants that have a non-nil ancestor
1 parent 11998ee commit 89f8104

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

ViewEnvironmentUI/Sources/ViewEnvironmentPropagating.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,16 @@ extension ViewEnvironmentPropagating {
130130

131131
return environment
132132
}
133+
134+
@_spi(ViewEnvironmentWiring)
135+
public func setNeedsEnvironmentUpdateOnAppropriateDescendants() {
136+
for descendant in environmentDescendants {
137+
// If the descendant's ancestor is nil it has opted out of environment updates and is likely acting as
138+
// a root for propagation bridging purposes (e.g. from a Workflow ViewEnvironment update).
139+
// Avoid updating the descendant if this is the case.
140+
guard descendant.environmentAncestor != nil else { continue }
141+
142+
descendant.setNeedsEnvironmentUpdate()
143+
}
144+
}
133145
}

ViewEnvironmentUI/Sources/ViewEnvironmentPropagatingObject.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ extension ViewEnvironmentPropagatingObject {
226226
setNeedsApplyEnvironment()
227227
}
228228

229-
environmentDescendants.forEach { $0.setNeedsEnvironmentUpdate() }
229+
setNeedsEnvironmentUpdateOnAppropriateDescendants()
230230
}
231231

232232
private var needsUpdateObservers: [NSObject: ViewEnvironmentUpdateObservation] {

ViewEnvironmentUI/Sources/ViewEnvironmentPropagationNode.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,6 @@ public struct ViewEnvironmentPropagationNode: ViewEnvironmentCustomizing {
5858
}
5959

6060
public func setNeedsEnvironmentUpdate() {
61-
environmentDescendants.forEach { $0.setNeedsEnvironmentUpdate() }
61+
setNeedsEnvironmentUpdateOnAppropriateDescendants()
6262
}
6363
}

0 commit comments

Comments
 (0)