Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If value is a NaN, it causes an infinity render #2298

Open
bhbs opened this issue Dec 30, 2023 · 1 comment
Open

If value is a NaN, it causes an infinity render #2298

bhbs opened this issue Dec 30, 2023 · 1 comment

Comments

@bhbs
Copy link

bhbs commented Dec 30, 2023

same as #2280

React version: v18.2.0

Reproduction

https://github.com/bhbs/recoil-repro-2298

import { atom, useRecoilValue } from "recoil";

const Atom = atom({
  key: "someKey",
  default: NaN,
});

function App() {
  const recoilValue = useRecoilValue(Atom);
  return <div>{String(recoilValue)}</div>;
}

export default App;

Current behavior

image

Expected behavior

Rendered successfully

How to fix

State should be compared using Object.is

is(other: Loadable<mixed>): boolean {
// $FlowFixMe[prop-missing]
return other.state === this.state && other.contents === this.contents;
}

should be

return (
  // $FlowFixMe[prop-missing]
  other.state === this.state && Object.is(other.contents, this.contents)
);

Note

Problems in similar situations

@bhbs bhbs changed the title If value is a NaN, it causes an infinity render If value is a NaN, it causes an infinity render Dec 30, 2023
@SaiUddisa
Copy link

any possible fix you suggest , I will solve

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants