Skip to content

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

@tcgj

Description

@tcgj

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions