next-on-pages icon indicating copy to clipboard operation
next-on-pages copied to clipboard

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

Open Jdruwe opened this issue 1 year ago โ€ข 5 comments

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?

  • [ ] Would you like to help fixing this bug?

Jdruwe avatar Jul 31 '24 12:07 Jdruwe

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.

Jdruwe avatar Aug 02 '24 11:08 Jdruwe

I can confirm there is an issue with higher versions of the workers runtime. I also changed to version: 2023-12-01 and caching started to work. Please fix it. ๐Ÿ™

kuririn1 avatar Sep 23 '24 11:09 kuririn1

Confirmed. My new project using runtime 2024-08-02 and doesn't have any data in KV. I changed it to 2024-04-03 and it works!

savokiss avatar Nov 11 '24 09:11 savokiss

2023-12-01 works!

lainfox avatar Nov 26 '24 16:11 lainfox

i am still facing this in 2025-04-18 , please fix .

log-xp avatar Apr 21 '25 18:04 log-xp

Hello ๐Ÿ™‚ Thank you for the issue and apologies for the late reply.

Earlier this year we released our Cloudflare adapter for OpenNext, and we have been continuously investing effort in its improvement since then. Existing deployments can continue to use the next-on-pages tooling, but the Cloudflare adapter for OpenNext is currently stable and recommended for deployment of Next.js applications to Cloudflare.

As such, we will no longer be maintaining next-on-pages. We recently deprecated the package on npm and we plan to archive this repo on Monday Sep 29, 2025. In preparation for archival, we are closing all open issues and PRs.

If you have concerns, please feel free to reply here before the repo is archived (after that, it will no longer be possible to comment) or to reach out to our team on Discord.

Thanks so much for using and contributing to next-on-pages ๐Ÿงก

dario-piotrowicz avatar Sep 26 '25 23:09 dario-piotrowicz