vercel / vercel/next.js

unstable_cache does not deserialize dates

Open
#51,613 25 comments 27 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Pages Router
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
  1. npm i
  2. npx prisma generate
  3. npx prisma db push
  4. npx prisma db seed
  5. npm 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.