-
Notifications
You must be signed in to change notification settings - Fork 7
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
[bug]: Next.js Server Components - Missing Headers in Outbound Requests #54
Comments
Hi, thanks for opening this issue, and thank you for the detailed reproduction steps and time spent doing some research; it's gonna help us a lot! I'm gonna try and reproduce the issue, see if we can understand why it happens and then come back to you! |
Some update there. I've managed to reproduce your issue. It seems like the patched fetch instance that next is creating to intercept HTTP requests is wiping out the headers defined by the Strapi client. I've spent the last few hours trying different approaches to debug that behavior, but so far no luck 😕 To confirm the issues come from the patched fetch, I've forced the SDK HTTP client to use another fetch implementation ( I'll continue looking into this next week. If anyone has any ideas on how we can approach this, I'm all ears, I'm by no mean a Next expert. |
Alright, so we finally understood the issue, and I've opened a PR with a fix at #57. I'll let you know whenever it gets merged and we'll release a new version with the fix as soon as possible! |
Great to hear! Thanks so much for the quick fix and hard work on this. Looking forward to the new release! |
Hey 👋 I've just released Have a great day! |
Bug Description
Hi community!
I'm encountering a very strange issue with Next.js Server Components and the official Strapi JS library (@strapi/sdk-js). When I make requests to my Strapi backend from within a Server Component using the Strapi JS library, the Content-Type and Authentication headers are mysteriously missing in the outbound request. This results in a 403 error from Strapi.
Here's the breakdown of what I've observed:
Server Components + Strapi JS Library: Headers (Content-Type, Authentication) are missing in the request. Strapi returns 403.
Client Components + Strapi JS Library: Headers are present, request is successful, Strapi works as expected.
Direct Node.js script (using this demo outside Next.js) + Strapi JS Library: Headers are present, request is successful, Strapi works as expected.
Server Components + fetch or axios: Headers are present, request is successful, Strapi works as expected.
This isolates the issue specifically to the combination of Next.js Server Components and the Strapi JS library. It's not a general networking problem in Server Components because fetch and axios work fine. It's also not a fundamental issue with the Strapi JS library itself, as it works in other contexts.
Steps to Reproduce
Steps to Reproduce
It's worthy noting that there are Authorization header in the error log but when capturing requests with Wireshark, the headers are actually missing
I also created a repo shows it works well with client component https://github.com/DebugNinjaSlayer/client-component-demo
Expected Behavior
Given these observations, I'm wondering if there's something I might be misunderstanding about how to use the Strapi JS library within Next.js Server Components.
Is it expected to work correctly in this environment?
Or could this behavior point to a potential incompatibility or bug within the library itself when used in Server Components?
Any guidance on proper usage or confirmation regarding expected compatibility would be incredibly helpful. Thank you!
Version
1.0.0
Operating System
MacOS
Runtime Environment
Node.js
Logs
Media
this is what the missing header requests like
and this is the requests sent from client components or typescript script
Confirmation Checklist
The text was updated successfully, but these errors were encountered: