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

[Bug] Unexpected result when fetcher returns false #164

Closed
AngusFu opened this issue Nov 30, 2019 · 2 comments · Fixed by #165
Closed

[Bug] Unexpected result when fetcher returns false #164

AngusFu opened this issue Nov 30, 2019 · 2 comments · Fixed by #165
Labels
bug Something isn't working

Comments

@AngusFu
Copy link

AngusFu commented Nov 30, 2019

Description

Always suspending when the fetcher returns (strictly, "resolved with") false.

image

async function fetcher() {
  return false;
}

async function fetcher2() {
  return true;
}

function Demo() {
  const { data: ok } = useSWR("/api", fetcher, { suspense: true });
  return <h1>{ok ? "Ok" : "Not ok"}</h1>;
}

function Demo2() {
  const { data: ok } = useSWR("/api2", fetcher2, { suspense: true });
  return <h1>{ok ? "Ok" : "Not ok"}</h1>;
}

<>
    <Suspense fallback={<h1>loading...</h1>}>
    <Demo />
    </Suspense>
    <Suspense fallback={<h1>loading...</h1>}>
    <Demo2 />
    </Suspense>
</>

Way to reproduce

See the codesandbox demo:

https://codesandbox.io/s/loving-grass-pv9ey

@AngusFu AngusFu changed the title [Bug] Unexpected result when fetcher returns boolean value false [Bug] Unexpected result when fetcher returns false Nov 30, 2019
@AngusFu
Copy link
Author

AngusFu commented Nov 30, 2019

PS: Seems falsy values in JavaScript ("" false 0) would get the above result, which is unexpected.

@shuding shuding added the bug Something isn't working label Nov 30, 2019
@shuding
Copy link
Member

shuding commented Nov 30, 2019

Thanks for reporting! Will get this fixed soon.

@shuding shuding mentioned this issue Dec 1, 2019
pacocoursey pushed a commit that referenced this issue Dec 2, 2019
* fix explicitly passing null as fetcher

* fix #164 allow returning falsy value from the cache
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants