Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Page was incorrectly cached when Route parameter contains : #38581

Closed
1 task done
Coxxs opened this issue Jul 13, 2022 · 6 comments · Fixed by #39568
Closed
1 task done

Page was incorrectly cached when Route parameter contains : #38581

Coxxs opened this issue Jul 13, 2022 · 6 comments · Fixed by #39568
Labels
bug Issue was opened via the bug report template.

Comments

@Coxxs
Copy link

Coxxs commented Jul 13, 2022

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)

if (routeInfo.__N_SSP && fetchNextDataParams.dataHref) {
const cacheKey = new URL(
fetchNextDataParams.dataHref,
window.location.href
).href
delete this.sdc[cacheKey]
}

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: Coxxs/next-cache-test@fe30c1a

@Coxxs Coxxs added the bug Issue was opened via the bug report template. label Jul 13, 2022
@Coxxs
Copy link
Author

Coxxs commented Jul 13, 2022

image

@visnup
Copy link
Contributor

visnup commented Aug 12, 2022

Going to attempt to fix this. I think I also narrowed down the regression to #37646, which has related code to what you pointed out.

@GioLogist
Copy link

@visnup If it helps, we're experiencing this issue as well. On SSR pages and when the @ is present. It makes the specific query parameter that has @ be removed on subsequent (client-side) navigations.

@visnup
Copy link
Contributor

visnup commented 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.

@Coxxs
Copy link
Author

Coxxs commented Aug 18, 2022

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

ijjk added a commit that referenced this issue Sep 2, 2022
Fixes #38581
<!--
Thanks for opening a PR! Your contribution is much appreciated.
In order to make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below.
Choose the right checklist for the change that you're making:
-->

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)

Co-authored-by: JJ Kasper <jj@jjsweb.site>
atilafassina pushed a commit to atilafassina/next.js that referenced this issue Sep 5, 2022
…39568)

Fixes vercel#38581
<!--
Thanks for opening a PR! Your contribution is much appreciated.
In order to make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below.
Choose the right checklist for the change that you're making:
-->

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)

Co-authored-by: JJ Kasper <jj@jjsweb.site>
@github-actions
Copy link
Contributor

github-actions bot commented Oct 2, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants