-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
using suspense mode with nullable ReturnType<fetcher> will cause a loop #517
Comments
@mha15 you can provide your useSWR hook with option useSWR(key, fetcher, {
initialData: /*<the default data you'd like to use>*/,
revalidateOnMount: false,
} and you might want to wrap your suspendable component with import * as React from "react";
import useSWR from "swr";
function getValue() {
console.log("requested again");
return Promise.resolve(null /* also for other falsy values like "" */);
}
function Main() {
useSWR("nullable value", getValue, {
suspense: true,
initialData: "",
revalidateOnMount: false
});
return (
<div className="App">
<h1>Hello CodeSandbox</h1>
<h2>Start editing to see some magic happen!</h2>
</div>
);
}
export default function App() {
return (
<React.Suspense fallback={<span>fallback</span>}>
<Main />
</React.Suspense>
);
} |
I did try turning off all revalidates and it doesn't help and also this problem is only when falsy value returned from fetcher function and it will work just fine in other cases |
I, too, experience such an issue. API call returns no content while data is not available, and JSON otherwise. Even if the React is at suspense: true,
revalidateOnReconnect: false,
revalidateOnFocus: false,
revalidateOnMount: false |
Fixed in #524. |
Bug report
I am using swr to get a value which can be object or null
but when null received from server my component will stuck in a loop and will show loading and request many times to server
Expected Behavior
call getValue once and use it's falsy value as resolved data
Repro Steps / Code Example
https://codesandbox.io/s/swr-problem-with-suspense-with-nullable-fetcher-zfhc2
The text was updated successfully, but these errors were encountered: