You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
update() silently corrupts custom class instances in fields the callback doesn't touch #1714
I've validated the bug against the latest version of DB packages
update()'s draft is built via a deepClone() that only preserves the prototype for a fixed allowlist of types (Date, RegExp, Array, typed arrays, Map, Set, Temporal.*). Any other class instance is cloned into a plain {} with the same properties but no prototype.
A field the callback assigns directly is fine (the value is stored as-is, bypassing deepClone). But any sibling field the callback doesn't touch is silently replaced by a prototype-less clone, so editing one field on a row corrupts every other field which contains a custom class instance, even though nothing about it changed.
This is easy to miss (the corrupted value still looks more or less right in a debugger, since the shape matches) and tends to surface later, e.g. as an instanceof check failing once the value is serialized and re-validated. That's how I found it: a zod z.custom(v => v instanceof MyClass) check started failing on partial updates, for a field the update never touched.
update()'s draft is documented as "Immer-style," and this is a divergence from Immer's actual behavior for such values: un-marked values (any class instance without immerable) are simply not drafted. Immer leaves them alone, by reference, untouched.
Expected: after.price is unchanged and still instanceof Money.
Actual: after.price is a plain object with matching properties but no prototype.
Impact
Any collection with a custom class instance as a field value — a value object, a domain type, anything outside the built-in allowlist — silently loses that value's type on anyupdate() that doesn't happen to also reassign it. In my case this broke partial edits to a row with multiple class-instance fields, and only surfaced as a downstream validation error, not at the point of corruption.
Thanks for the clear reproduction. #1800 landed the update behavior that preserves untouched custom class instances by reference. The reported Money instance case passes on current main. Closing as fixed.
Activity
KyleAMathews commentedon Sep 29, 2026
Thanks for the clear reproduction. #1800 landed the update behavior that preserves untouched custom class instances by reference. The reported Money instance case passes on current main. Closing as fixed.