sindresorhus / ky

🌳 Tiny & elegant JavaScript HTTP client based on the Fetch API
MIT License
11.91k stars 342 forks source link

Ky does not pass custom options down to the native fetch #531

Closed thexpand closed 9 months ago

thexpand commented 10 months ago

When I try to pass down custom options to the native fetch, e.g. Next.js 13's { next: { revalidate: 0 } }, these options don't get passed to the fetch function. Here's the issue created in Next.js's repo, but the problem is that actually ky doesn't pass the custom options: https://github.com/vercel/next.js/issues/48519

References about how to use the options in the Next.js docs:

kylekz commented 9 months ago

I'm not sure if this is related, but I'm also using Next 13.5.2 and a simple post request:

const data = await ky
    .post(endpoint, {
      json: {
        some: 'json',
      },
    })
    .json<SomeResponseType>();

results in:

Request with GET/HEAD method cannot have body.

Manually specifying { method: "POST" } doesn't work either, so perhaps it's just not passing options at all?

sindresorhus commented 9 months ago

This may because Ky is not passing options directly to fetch(…, options), but instead constructs a Request and passes the options in there. My guess would be that Next.js does not correctly handle that.

sindresorhus commented 9 months ago

Actually, yeah, this is the reason: https://github.com/sindresorhus/ky/issues/516#issuecomment-1674303251

spaceemotion commented 9 months ago

I just came across the same issue when i tried to set the request priority. is this something ky should natively support (i can open issue for that, if needed) or left for after the option passthrough has been fixed?