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

Cannot pass a custom fetch method in apiOptions #961

Open
1 task done
addemod opened this issue Feb 22, 2024 · 1 comment
Open
1 task done

Cannot pass a custom fetch method in apiOptions #961

addemod opened this issue Feb 22, 2024 · 1 comment
Labels
pending-author [Issue] Awaiting further information or action from the issue author pending-triage [Issue] Ticket is pending to be prioritised

Comments

@addemod
Copy link

addemod commented Feb 22, 2024

Describe the issue you're facing

Hello,

I want to pass a custom fetch to the storyblok-js-client when initializing the storyblok api using storyblokInit from @storyblok/react/rsc. However, it seems that the custom fetch is not being passed to the client correctly.

If a for example add console.log() to the fetch-method, the text is never printed. If I debug and attach, the breakpoint is never hit.

storyblokInit({
  accessToken: process.env.NEXT_PUBLIC_STORYBLOK_TOKEN,
  use: [apiPlugin],
  components: {
    page: Page,
  },
  apiOptions: {
    fetch: (url, options) => {
      console.log('A custom fetch');
      return fetch(url, { ...options, next: { tags: ['a custom tag'] } });
    },
  },
});

Reproduction

https://stackblitz.com/edit/stackblitz-starters-kzvhqv?file=app%2Flayout.tsx

Steps to reproduce

  1. Add a .env-file or edit layout.tsx with a storyblok token
  2. Start the app "npm run dev"
  3. Notice how there's no "A custom fetch" log in the console

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
    Memory: 9.24 GB / 31.73 GB
  Binaries:
    Node: 18.19.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.21 - C:\Program Files\nodejs\yarn.CMD
    npm: 10.2.3 - C:\Program Files\nodejs\npm.CMD
    pnpm: 8.15.2 - C:\Program Files\nodejs\pnpm.CMD
  Browsers:
    Edge: Chromium (121.0.2277.128)
    Internet Explorer: 11.0.19041.3636

Used Package Manager

pnpm

Error logs (Optional)

No response

Validations

@addemod addemod added pending-author [Issue] Awaiting further information or action from the issue author pending-triage [Issue] Ticket is pending to be prioritised labels Feb 22, 2024
@addemod addemod changed the title Cannot pass a custom fetch Cannot pass a custom fetch method in apiOptions Feb 22, 2024
@arorachakit
Copy link
Contributor

Hey @addemod !
Thanks for sharing this, we will take a look at it and let you know. cc - @fgiuliani @alexjoverm
However, it looks like that you want to pass the custom fetch options for Next js. You can pass those with every request you make as a third parameter, here is an example - https://github.com/storyblok/next.js-13-boilerplate/blob/main/app/page.js#L20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending-author [Issue] Awaiting further information or action from the issue author pending-triage [Issue] Ticket is pending to be prioritised
Projects
None yet
Development

No branches or pull requests

2 participants