From 2f2b5ac7b5ef283cab66f7a1be85a0aef5f69ecd Mon Sep 17 00:00:00 2001 From: Greg Johnston Date: Fri, 26 Dec 2025 12:13:45 -0500 Subject: [PATCH] fix: track parents when tracking keyed subfield (second half of #4475) --- reactive_stores/src/keyed.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/reactive_stores/src/keyed.rs b/reactive_stores/src/keyed.rs index 5312bcc0d..302ef16b9 100644 --- a/reactive_stores/src/keyed.rs +++ b/reactive_stores/src/keyed.rs @@ -140,13 +140,20 @@ where } fn track_field(&self) { - let inner = self - .inner - .get_trigger(self.inner.path().into_iter().collect()); - inner.this.track(); + let mut full_path = self.path().into_iter().collect::(); let trigger = self.get_trigger(self.path().into_iter().collect()); trigger.this.track(); trigger.children.track(); + + // tracks `this` for all ancestors: i.e., it will track any change that is made + // directly to one of its ancestors, but not a change made to a *child* of an ancestor + // (which would end up with every subfield tracking its own siblings, because they are + // children of its parent) + while !full_path.is_empty() { + full_path.pop(); + let inner = self.get_trigger(full_path.clone()); + inner.this.track(); + } } }