store icon indicating copy to clipboard operation
store copied to clipboard

`shallow` doesn't correctly compare different object instances if they only have property getters

Open tcgj opened this issue 5 months ago • 0 comments

Describe the bug

I'm using @tanstack/react-form, but traced the issue back to the store here. Specifically, I'm trying to store Temporal.Duration values, but store updates are not being received via useStore because shallow returns true when both objects have no keys, i.e. Object.keys(objA) return [], instead of comparing referential equality at that point.

Steps to Reproduce the Bug or Issue

This, and any object factory that use getters instead of static properties return true.

shallow(Temporal.Duration.from({ hours: 1 }), Temporal.Duration.from({ days: 2 }));

Expected behavior

Expect to see false, since they are different values, different objects.

Screenshots or Videos

No response

Platform

  • OS: macOS
  • Browser: Arc (Chromium)
  • Version: 138.0

Additional context

No response

tcgj avatar Jul 22 '25 01:07 tcgj