Skip to content

Re-assigning NaN is seen as a value change #614

@Legioth

Description

@Legioth
  • Check if updating to the latest version resolves the issue

Environment

  • I am using @preact/signals-core
  • I am using @preact/signals
  • I am using @preact/signals-react

Describe the bug
In JavaScript, NaN === NaN evaluates to false. A consequence of this is that a signal with the value NaN will trigger an update if the value is again assigned as NaN. In the worst case, this might lead to an infinite loop with a two-way UI binding if the receiving end is also treating NaN in the same way.

To Reproduce

const x = signal(0);
effect(() => console.log(x.value));
x.value = NaN;
x.value = x.value;

This logs NaN twice even though it's expected that the last row shouldn't lead to running the effect again.

Expected behavior
Expected that the dirty checking logic has a special case for re-assigning NaN

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