-
Notifications
You must be signed in to change notification settings - Fork 27k
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
ky-universal fetch leads to body timeout errors #13549
Comments
This issue stems from We're happy to entertain how this could be fixed in Next.js though, feel free to send a PR! |
@paambaati Maybe you need to upgrade Checkout release v0.7.0 note: https://github.com/sindresorhus/ky-universal/releases/tag/v0.7.0 |
@sagar-gavhane This issue happens with 0.7.0 as well. |
Hi all, Ky maintainer here! Happy to help with this. Just to make sure we're on the same page, Next has not yet released a version that uses Also, could someone enlighten me as to why Next uses I'm assuming that Next attaches its |
@sholladay Just to add some more context, Next.js itself doesn’t use |
I see |
@sholladay AFAIK, it is used only for tests — it was actually introduced in #12804 I think the problem is, Next.js also has its own polyfilled version of Do you think letting users bring their |
We've talked about it a few times and I think it's still on the table. The thing is, it needs a better use case than just a workaround for an upstream bug that's already been solved. In a sense, bring your own fetch is already supported since we check for its existence before using our own, albeit via globals. But it's done that way because All that said, given that |
@paambaati @sholladay Hi, I'm sorry to mention suddenly. This problem also happened to me. |
@TasukuUno Honestly, this might not be what you wanted to hear, but I gave up on Ky and just moved to Axios. |
@paambaati oh... It's sad to hear that... but now I understand the current situation! |
As of Ky v0.23.0 you can now provide a import ky from 'ky';
import fetch from 'isomorphic-unfetch';
const json = await ky('https://example.com', { fetch }).json(); And this is also supported with custom instances, so you don't need to specify it for every call. Is there anything else we can do to help? |
This workaround doesn't work for me, my requests still hang with large responses |
`ky-universal` requests hang because of this issue in Next.js: vercel/next.js#13549
Using Next.js 12 and the following API route: import ky from "ky-universal"
const api = () => {
const defaultOptions = {
prefixUrl: "https://jsonplaceholder.typicode.com",
credentials: "include",
keepAlive: true,
retry: 0,
hooks: {
afterResponse: [
(req, opt, res) => {
console.log("KY -> AFTER RESPONSE HOOK!")
// The below line does not affect the outcome when it is uncommented either.
// return res;
},
],
},
}
return ky.create(defaultOptions)
}
export default async function handler(_, res) {
res.json(await api().get("todos/1").json())
} I'm no longer able to reproduce any issue here. I suggest upgrading Next.js, and if you still experience the problem, please open a new bug report. |
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Bug report
I use
ky-universal
with Next.js to handle all my API calls, and I useky
's hooks (middleware for APIs) to do things like logging, handling cookies, etc.The library had a long-standing bug with timeout errors on large response bodies, and it was recently fixed when they switched their
node-fetch
dependency to3.0.0-beta.6
. Note that these are not actually timeouts from the API itself, but timeouts while trying to consume the response stream and parsing it as JSON. The linked PR was supposed to fix these issues (similar to mine) —After this change, I'd expected my hooks to work again, but I'm still getting the same errors —
This leads me to believe Next.js's own version of
node-fetch
is shadowing the one thatky-universal
should use.To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
api()
method in a Next.js API route withky-universal
dependency set to version0.7.0
- this version includes the fix for timeouts.Expected behavior
ky-universal
.ky-universal
's node-fetch over Next.js's own.System information
Additional context
Somewhat related — #12761
The text was updated successfully, but these errors were encountered: