`shallow` doesn't correctly compare different object instances if they only have property getters
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 893
- Forks
- 114
- Avg merge
- 8d 14h
- Merged PRs (30d)
- 3
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the store's shallow implementation and its existing tests. Reproduce the reported comparison with two distinct objects that expose values through getters, then add coverage and adjust the behavior so distinct instances are not treated as equal; the relevant tests should pass afterward.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100