unstable_cache does not deserialize dates
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 142k
- Forks
- 32.4k
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 351
Description
Verify canary release
- I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 22.5.0: Mon Apr 24 20:52:24 PDT 2023; root:xnu-8796.121.2~5/RELEASE_ARM64_T6000
Binaries:
Node: 18.12.1
npm: 9.6.4
Yarn: 1.22.19
pnpm: 7.13.1
Relevant packages:
next: 13.4.7-canary.2
eslint-config-next: N/A
react: 18.2.0
react-dom: 18.2.0
typescript: 4.9.5
Which area(s) of Next.js are affected? (leave empty if unsure)
App directory (appDir: true), Data fetching (gS(S)P, getInitialProps)
Link to the code that reproduces this issue or a replay of the bug
https://github.com/SSardorf/next_unstable_cache_date_deserialization
To Reproduce
npm inpx prisma generatenpx prisma db pushnpx prisma db seednpm run dev
When you first run the project, you'll see that it loads correctly (cause first prisma invocation will result in non-cached data)
When you refresh, the cached data will be shown, and it'll throw an error, as post.createdAt is no longer a Date, but a string:
<p>{post.createdAt.toISOString()}</p>
Describe the Bug
When you first run the project, you'll see that it loads correctly (cause first prisma invocation will result in non-cached data)
When you refresh, the cached data will be shown, and it'll throw an error, as post.createdAt is no longer a Date, but a string:
<p>{post.createdAt.toISOString()}</p>
Expected Behavior
unstable_cache should correctly de-serialize Dates.
Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked reproduction repository and run its setup steps: npm i, npx prisma generate, npx prisma db push, npx prisma db seed, and npm run dev. Inspect the unstable_cache behavior after the first request and refresh; done means cached post.createdAt values remain usable as Dates so toISOString() does not fail.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nextjs
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100