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

next/link sometimes does not update the page when used in dynamic page with replace and query parameters in v15 #69847

Closed
skirsten opened this issue Sep 8, 2024 · 6 comments · Fixed by #69850
Labels
bug Issue was opened via the bug report template. locked Navigation Related to Next.js linking (e.g., <Link>) and navigation.

Comments

@skirsten
Copy link
Contributor

skirsten commented Sep 8, 2024

Link to the code that reproduces this issue

https://github.com/skirsten/repro-next-link-broken

To Reproduce

  1. Start the repo with next build and next start! It is not reproducible with next dev.
  2. Read the text and click the links in the order that is explained on the page.
  3. After each click check the url and the first line of the output. You should see the problem.

Alternatively use this hosted url: https://repro-next-link-broken-git-bug1-skirsten.vercel.app/
Or checkout this video: https://github.com/user-attachments/assets/bfcee9ae-e95e-405e-89a1-83e8d4256538 (if you turn up the volume you can hear the mouse clicks)

Current vs. Expected behavior

I expect the links to work as they did in next v14 without problems.

Known working:
14.2.5

Not working in at least:
15.0.0-canary.144
15.0.0-canary.136
15.0.0-canary.128

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #40~22.04.3-Ubuntu SMP PREEMPT_DYNAMIC Tue Jul 30 17:30:19 UTC 2
  Available memory (MB): 32012
  Available CPU cores: 16
Binaries:
  Node: 20.12.1
  npm: 10.5.0
  Yarn: 1.22.22
  pnpm: 9.9.0
Relevant Packages:
  next: 15.0.0-canary.145 // Latest available version is detected (15.0.0-canary.145).
  eslint-config-next: 15.0.0-canary.145
  react: 19.0.0-rc-7771d3a7-20240827
  react-dom: 19.0.0-rc-7771d3a7-20240827
  typescript: 5.5.4
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Navigation

Which stage(s) are affected? (Select all that apply)

next start (local), Vercel (Deployed), Other (Deployed)

Additional context

Unfortunately the nature of this bug is not very exact and sometimes changing the layout or order of the links changes how they will behave.

@skirsten skirsten added the bug Issue was opened via the bug report template. label Sep 8, 2024
@github-actions github-actions bot added the Navigation Related to Next.js linking (e.g., <Link>) and navigation. label Sep 8, 2024
@skirsten skirsten changed the title next/link sometimes does not update the page when used with replace and query parameters in v15 next/link sometimes does not update the page when used in dynamic route with replace and query parameters in v15 Sep 8, 2024
@skirsten skirsten changed the title next/link sometimes does not update the page when used in dynamic route with replace and query parameters in v15 next/link sometimes does not update the page when used in dynamic page with replace and query parameters in v15 Sep 8, 2024
@ztanner
Copy link
Member

ztanner commented Sep 8, 2024

Thank you for the very clear reproduction, I'll have a fix up for this shortly.

ztanner added a commit that referenced this issue Sep 9, 2024
When returning an aliased prefetch, we need to make sure the final tree
that is produced contains the final searchParams, as otherwise the
router might not properly re-key the component to reflect the changed
search value. This moves the existing util that handled appending
`searchParams` to the `__PAGE__` segment into the shared segment
helpers. On the client, when we detect that we returned an aliased
prefetch, we update the segment key with the "final" data by calling
this helper with the final searchParams.

This also fixes a missing `aliased` detection in the case where we do
find an entry as it's possible the entry matches the path, but not the
search. It wasn’t sufficient to only do this for full prefetches because
while auto prefetches won’t return the CacheNode data, it will return a
tree, so we need to make sure the tree contains the right params.

Fixes #69847
@skirsten
Copy link
Contributor Author

Thank you for the quick response and fix. I checked out the latest canary and it seems most issues are fixed 🎉.

Unfortunately I encountered in some cases (depending on the order of the links) it still requires clicking the link twice.

I added a new reproduction here https://github.com/skirsten/repro-next-link-broken/tree/bug2 and hosted here: https://repro-next-link-broken-git-bug2-skirsten.vercel.app/.

I believe its related to the same logic.

@ztanner
Copy link
Member

ztanner commented Sep 11, 2024

Thank you for the quick response and fix. I checked out the latest canary and it seems most issues are fixed 🎉.

Unfortunately I encountered in some cases (depending on the order of the links) it still requires clicking the link twice.

I added a new reproduction here https://github.com/skirsten/repro-next-link-broken/tree/bug2 and hosted here: https://repro-next-link-broken-git-bug2-skirsten.vercel.app/.

I believe its related to the same logic.

Indeed! Thanks for flagging, I’ll be taking a look at this soon.

@ztanner
Copy link
Member

ztanner commented Sep 11, 2024

Hi @skirsten -- I believe this should be resolved by #69948 and added your reproduction as a regression test. I've just triggered a canary. Appreciate the reports, let me know if you run into any troubles!

@skirsten
Copy link
Contributor Author

Awesome, I tested the canary and all the links behave as expected now. Thanks 🎉

I did notice one small inconsistency where some client side cache is used unexpectedly.
Its hard to explain so I put a small reproduction together:
https://github.com/skirsten/repro-next-link-broken/tree/bug3
https://repro-next-link-broken-git-bug3-skirsten.vercel.app/

Basically when returning to page 1 for the first time, its reusing the old page 1 (the timer will not start at 0).

Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. 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 Sep 26, 2024
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. locked Navigation Related to Next.js linking (e.g., <Link>) and navigation.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants