question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Page was incorrectly cached when Route parameter contains `:`

See original GitHub issue

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 10 Home
Binaries:
  Node: 18.4.0
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant packages:
  next: 12.2.3-canary.3
  eslint-config-next: 12.2.2
  react: 18.2.0
  react-dom: 18.2.0

What browser are you using? (if relevant)

Google Chrome Version 103.0.5060.114 (Official Build) (64-bit)

How are you deploying your application? (if relevant)

npm run build
npm run start

Describe the Bug

When the Route parameter contains the : character, page uses getServerSideProps will be incorrectly cached in the browser by next.js.

This is because an encoding error in cacheKey causing next.js unable to delete _this.sdc[cacheKey] (Server Data Cache)

https://github.com/vercel/next.js/blob/13557eac6fb599bb9b29c076c59c7117498ad0c5/packages/next/shared/lib/router/router.ts#L1841-L1847

Expected Behavior

Even if Router parameter contains the : character, page uses getServerSideProps should not be cached.

Link to reproduction

https://next-cache-test-fawn.vercel.app/

To Reproduce

Click the second & fourth link repeatedly, the server generated content will not change because it’s cached in browser.

This is only reproducible in production build.

I’ve disabled the minimize (config.optimization.minimize = false) to make it easy to debug.

Demo: https://next-cache-test-fawn.vercel.app/ Demo source: https://github.com/Coxxs/next-cache-test/commit/fe30c1abf8e713b601634fda3e1016d7ad02d77b

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Coxxscommented, Aug 18, 2022

patch-package is a good way to fix your project before next.js merging the PR.

1reaction
visnupcommented, Aug 18, 2022

Yeah, I have a PR for a fix in #39568 (one line?). I don’t know how to get more eyes on that. I guess the more upvotes and activity we can get on this issue, the better?

@GioLogist Have you found any good workarounds in the meantime? We’re experiencing the exact same issue since we use @ in our URLs a lot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - Cache busting via params
The param ?v=1.123 indicates a query string, and the browser will therefore think it is a new path from, say, ?v=1.0 . Thus...
Read more >
Correctly cache route by dynamic parameter - Drupal Answers
When accessing that route by a value for baz, the page contents are correct, but the breadcrumb is incorrect and caches the first...
Read more >
Advanced topics on caching in Apollo Client
In some cases, a query requests data that already exists in the cache under a different reference. For example, your UI might have...
Read more >
Page cache creates vast amounts of unneeded cache data
Problem 1: After some investigation we noticed a new page_cache entry was created for every unique URL, regardless wether or not that URL...
Read more >
Improving Performance with Output Caching (C#)
By default, the Location property has the value Any. However, there are situations in which you might want to cache only on the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found