From 91ef61b64900932213e484720e3aa3b6c3f5438d Mon Sep 17 00:00:00 2001 From: Dan Fabulich Date: Wed, 10 Jun 2026 02:39:33 -0700 Subject: [PATCH] Fix `@Observable` property writes skipped when new value is == old value Compose `mutableStateOf` uses structural equality by default, so assigning a new dictionary (or other collection) to an `@Observable` property was ignored when `Equatable` said nothing changed. Now, we use referential equality, so assignment always updates the backing state. Fixes #24 --- Sources/SkipModel/Observed.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/SkipModel/Observed.swift b/Sources/SkipModel/Observed.swift index dfbb1b4..dc4ad61 100644 --- a/Sources/SkipModel/Observed.swift +++ b/Sources/SkipModel/Observed.swift @@ -4,6 +4,7 @@ import androidx.compose.runtime.MutableState import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.referentialEqualityPolicy /// We model properties of `@Observable` types as if they had this synthetic `@Observed` property wrapper. /// Like `Published`, it uses `MutableState` to tie into Compose's observation system. @@ -48,7 +49,7 @@ public final class Observed: StateTracker { public func trackState() { // Once we create our internal MutableState, reads and writes will be tracked by Compose if projectedValue == nil { - projectedValue = mutableStateOf(_wrappedValue) + projectedValue = mutableStateOf(_wrappedValue, referentialEqualityPolicy()) } } }