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

Custom fetch options are stripped from the request. Next.js cache doesn't work properly. #1569

Open
petercsaki opened this issue Feb 27, 2024 · 4 comments
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed openapi-fetch Relevant to the openapi-fetch library

Comments

@petercsaki
Copy link

Description

Openapi-fetch uses a request object for its fetch.

let response = await fetch(request);

The request object created by openapi-fetch strips away non standard fetch options, i.e. how Next.js passes its cache related params:

{ next: { revalidate: 3600 } }

More info on Next.js fetching data + caching

Reproduction

Try to pass next cache params in https://github.com/drwpow/openapi-typescript/blob/main/packages/openapi-fetch/examples/nextjs/app/page.tsx
It won't change its behaviour, it always falls back to defaults, because the non standard ones are stripped away.

I've tried

I changed this line

let response = await fetch(request);

to

let response = await fetch(request, requestInit);

and it works, but I don't know if it would cause other problems.

@petercsaki petercsaki added bug Something isn't working openapi-fetch Relevant to the openapi-fetch library labels Feb 27, 2024
@drwpow drwpow added help wanted Extra attention is needed good first issue Good for newcomers labels Feb 27, 2024
@drwpow
Copy link
Owner

drwpow commented Feb 27, 2024

Ah, hm. I was somewhat afraid this would happen, and did see it come up in one other test failure, but had thought it was fixed.

Would gladly welcome any PRs for this! This should be a fairly-straightforward issue to write a failing test for, and find a fix.

@petercsaki
Copy link
Author

PR created.

@JE-lee
Copy link
Contributor

JE-lee commented Mar 7, 2024

For the workaround, this could be ok as well as the cache mechanism, regardless a little wired.

  const res = await client.GET("/api/v1/space", {
    fetch: (request: unknown) => {
      return fetch(request as Request, { next: { revalidate: 40 } } )
    }
  })

I have tested it in Next.js 14

@FreeAoi
Copy link
Contributor

FreeAoi commented May 9, 2024

Hi, a pull request fixing this was merged #1653 recently

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed openapi-fetch Relevant to the openapi-fetch library
Projects
None yet
Development

No branches or pull requests

4 participants