-
-
Notifications
You must be signed in to change notification settings - Fork 366
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
Add retry.delay option to control the time between retries #533
Add retry.delay option to control the time between retries #533
Conversation
@sindresorhus @szmarczak @sholladay |
You need to document it in the readme too. |
Co-authored-by: Sindre Sorhus <[email protected]>
FYI: @sindresorhus
I'm using ky pretty much basic. But it seems like that KY internally is adding the cache to the fetcher with value of default. const contentApi = ky.create({
prefixUrl: `${process.env.CONTENT_API_URL}/api`,
retry: 0,
});
contentApi
.get(`getSomething/${someId}`, {
next: { revalidate: 60 },
})
.json(); |
@TommySorensen this is because Ky internally constructs a I just checked and it seems this was fixed in Next.js in vercel/next.js#58505, and released in https://github.com/vercel/next.js/releases/tag/v14.0.3 BTW if like me you're not using Next 14 yet, this is a workaround I've been using: function fetchWith(override: RequestInit): typeof fetch {
return (input, init) => {
if (input instanceof Request) {
return fetch(input.url, {
// Copy all properties *except* for `cache` to prevent Next from warning that
// we pass both `cache` and `revalidate`.
// This happens because Ky internally constructs a `Request` object, so `cache`
// will always be the set to `"default"` even when we don't explicitly set it.
body: input.body,
credentials: input.credentials,
headers: input.headers,
integrity: input.integrity,
keepalive: input.keepalive,
method: input.method,
mode: input.mode,
redirect: input.redirect,
referrer: input.referrer,
referrerPolicy: input.referrerPolicy,
signal: input.signal,
...init,
...override,
});
}
return fetch(input, { ...init, ...override });
};
}
// then use it like
contentApi
.get(`getSomething/${someId}`, {
fetch: fetchWith({ next: { revalidate: 60 } }),
})
.json(); |
Related to option (2) to #509
Changes
delay
function toRetryOptions
objectdelay