cloudflare / next-on-pages

CLI to build and develop Next.js apps for Cloudflare Pages
https://www.npmjs.com/package/@cloudflare/next-on-pages
MIT License
1.24k stars 118 forks source link

[šŸ› Bug]: Workers KV for caching fetch requests is not working #844

Open Jdruwe opened 1 month ago

Jdruwe commented 1 month ago

next-on-pages environment related information

System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 23.5.0: Wed May 1 20:12:58 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6000 CPU: (10) arm64 Apple M1 Pro Memory: 32 GB Shell: /bin/zsh Package Manager Used: npm (10.2.3)

Relevant Packages: @cloudflare/next-on-pages: 1.13.1 vercel: 35.2.2 next: 14.1.0

Description

Hey All!

We are trying to cache fetch requests using the 'Worker KV' optioned descibed at: https://github.com/cloudflare/next-on-pages/blob/main/packages/next-on-pages/docs/caching.md#workers-kv.

  1. Configured a binding inside the wrangler.toml file:
[[kv_namespaces]]
binding = "__NEXT_ON_PAGES__KV_SUSPENSE_CACHE"
id = "7e342246dcbb48ec9cf86c439d9d42c1"
image
  1. Added a fetch call to the root page:
const todosResponse = await fetch("https://jsonplaceholder.typicode.com/todos");
const todos: {userId: number, title: string}[] = await todosResponse.json();
  1. Visit the app at: https://cloudflare-page-next-data-fetching-cache.pages.dev

  2. KV should be populated but still empty

image

Note: I also tried this on a different project running next.js version 14.2.3 but it's also an issue over there.

UPDATE 02-08-2024:

This seems to be related to the "Workers runtime version", I had it set to 2024-08-02 originally but changed it to an older version: 2023-12-01 just to be sure and lo and behold it starts working.

Reproduction

Reproduction repo can be found at: https://github.com/Jdruwe/cloudflare-page-next-data-fetching-cache

Pages Deployment Method

Direct Upload (wrangler pages publish or the @cloudflare/pages-action GitHub Action)

Pages Deployment ID

58ddbcd4-65c8-4e9b-aaa5-2f5b001706c4

Additional Information

No response

Would you like to help?

Jdruwe commented 1 month ago

This seems to be related to the "Workers runtime version", I had it set to 2024-08-02 originally but changed it to an older version: 2023-12-01 just to be sure and lo and behold it starts working. Hopefully this helps the maintainers to pinpoint the issue.