-
-
Notifications
You must be signed in to change notification settings - Fork 365
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
Passing { next: { revalidate, tags } } options to ky does not work in NextJS edge (at least with dev server) #541
Comments
One other thing worth mentioning is that it's a bit unergonomic to pass those unknown options to ky, since if I pass them directly, the type checker complains. I either have to do one of two things
which work but are not ideal. |
// @kdelmonte |
I'll take a look. |
Relates to: |
@dkokotov I've been following this thread and it seems like this this is a next.js issue that shouldn't require any modifications to ky. Please clarify when you can. Also, regarding the typescript error that you are getting, please provide a reproduction repository. |
@kdelmonte I am following the thread you linked as well - since I am one of the people affected by that issue. It looks like Next.js is working on a fix, but I am waiting to see how it plays out - the linked PR does not yet have a fully working fix. However, I don't think that issue is related to this one - other than the coincidence that both affect edge runtime on Next.js dev server. the problem described in that issue has to do with the fact that when you do something like
The problem described in this issue is with passing additional properties to This was previously reported in #531 and was attempted to be fixed in #536. And the fix mostly works - except in edge runtime in nextjs (it definitely does not work in edge with dev server. and I cannot test it with edge on Vercel prod, because they are currently having issues deploying edge functions). But the reason does not have anything to do with the nextjs issue above. As I mentioned in my original post, I think it has to do with the way #536 is implemented. Specifically in https://github.com/sindresorhus/ky/pull/536/files#diff-1d28e040cea335f5a22aa9c3f678f5d00b353e3ce966dc0978a91fe56f240b04R301 it only passes to You can prove this with something like this:
if I run this in edge runtime I get
whereas in node I get
So the problem is very specific to the One possible solution could be if we could only check the "declared" keys of the original Let me know if any of the above doesn't make sense. |
Thank you for the clarification. I will investigate. |
@kdelmonte (or @sindresorhus ) not sure if you've had a chance to look yet, but please let me know what you think of the approach in #542 |
To be honest I had some weird behaviors with the tests. When they ran on my fork they initially hung but then passed (https://github.com/dkokotov/ky/actions). so not sure why they are failing in the context of the PR. And I had trouble making them run locally. As I mentioned in my comment on the PR (#542 (comment)) I ended up switching to a different library just cause I needed to make progress on what I had been trying to use this for. so I probably won't have time to chase down the test issues. Feel free to either take the issue / PR over or to close it. |
The fix for passing unknown options to fetch (#536) does not work correctly for the
next
options used by Next.js to control cache revalidation, when using edge runtime on dev server.I think this is because the ky implementation relies on passing only keys that are not in
Request
in the second argument offetch
. however, it looks like Next.js patchesRequest
to also have anext
key (I think this may be the culprit, though not totally sure: https://github.com/vercel/next.js/blob/canary/packages/next/src/server/web/sandbox/context.ts#L370), so this results innext
key not being included.I verified it with a wrapper fetch function that logs the second input (similar to how the test in the PR above is written). I can see that keys other than
next
are correctly passed, and in the node runtime thenext
key is passed, but in the edge runtime it is not.I have not yet tested if this problem is present in the production edge environment, or only dev server.
The text was updated successfully, but these errors were encountered: