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

Intercepting routes not work depending on the first page displayed #52748

Closed
1 task done
AkifumiSato opened this issue Jul 16, 2023 · 4 comments · Fixed by #59861
Closed
1 task done

Intercepting routes not work depending on the first page displayed #52748

AkifumiSato opened this issue Jul 16, 2023 · 4 comments · Fixed by #59861
Labels
bug Issue was opened via the bug report template. locked

Comments

@AkifumiSato
Copy link
Contributor

AkifumiSato commented Jul 16, 2023

Verify canary release

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

Provide environment information

$ next info

    Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 21.3.0: Wed Jan  5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_ARM64_T6000
    Binaries:
      Node: 18.13.0
      npm: 8.19.3
      Yarn: 1.22.19
      pnpm: 8.3.1
    Relevant Packages:
      next: 13.4.10-canary.8
      eslint-config-next: N/A
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 4.9.5
    Next.js Config:
      output: N/A

Which area(s) of Next.js are affected? (leave empty if unsure)

App Router

Link to the code that reproduces this issue or a replay of the bug

https://github.com/AkifumiSato/http-vary-has-not-next-url
I discovered this while investigating another bug.

To Reproduce

Operate normally

  1. http://localhost:3000/feed(full load)
  2. http://localhost:3000/photo

Not operate normally

  1. http://localhost:3000/(full load)
  2. http://localhost:3000/feed
  3. http://localhost:3000/photo

Describe the Bug

Depending on the first page displayed, the intercepting routes not work properly, and the transition will be as if the intercept directory did not exist.

Expected Behavior

Wherever the first page is, intercepting routes should work.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

@AkifumiSato AkifumiSato added the bug Issue was opened via the bug report template. label Jul 16, 2023
@AkifumiSato AkifumiSato changed the title Intercepting routes may not work depending on the first page displayed Intercepting route not work depending on the first page displayed Jul 16, 2023
@AkifumiSato AkifumiSato changed the title Intercepting route not work depending on the first page displayed Intercepting routes not work depending on the first page displayed Jul 16, 2023
@AkifumiSato
Copy link
Contributor Author

I think this is due to the unintended use of the prefetch cache.

@kachkaev
Copy link
Contributor

I have bumped into a similar situation here: #53170. My reproduction example also uses parallel routes (for a modal) and route groups (to pick pages that should intercept the route).

@AkifumiSato
Copy link
Contributor Author

@ztanner @feedthejim
I would like to hear from those who replied with this comment.
#54173 (comment)

ztanner added a commit that referenced this issue Dec 22, 2023
### What?
When handling route interception in two different segments but handled
by the same interception route, the first interception will show the
correct component but attempting the same interception on another
segment will return elements from the first request, not the second.

### Why?
Prefetch cache entries are created from the browser URL. However, route
interception makes use of `nextUrl` to mask the underlying components
that are being fetched from the server to handle the request

Consider the following scenario:

```
app
   foo
     @modal
       (...)post
         [id]
   bar
     @modal
       (...post)
         [id]
   post
     [id]
     
```
If you trigger an interception on `/foo`, your URL is going to be masked
to `/post/1` and keyed as such in the prefetch cache. However, the cache
entry is actually associated with `app/foo/@modal/(...post)/[id]`. That
means when you trigger the same interception on `/bar`, it will return
the tree from `/foo`.

### How?
This PR will prefix the prefetch cache key with `state.nextUrl` when
necessary.

Fixes #49878
Fixes #52748
Closes NEXT-1818
Copy link
Contributor

github-actions bot commented Jan 6, 2024

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 added the locked label Jan 6, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 6, 2024
agustints pushed a commit to agustints/next.js that referenced this issue Jan 6, 2024
…#59861)

### What?
When handling route interception in two different segments but handled
by the same interception route, the first interception will show the
correct component but attempting the same interception on another
segment will return elements from the first request, not the second.

### Why?
Prefetch cache entries are created from the browser URL. However, route
interception makes use of `nextUrl` to mask the underlying components
that are being fetched from the server to handle the request

Consider the following scenario:

```
app
   foo
     @modal
       (...)post
         [id]
   bar
     @modal
       (...post)
         [id]
   post
     [id]
     
```
If you trigger an interception on `/foo`, your URL is going to be masked
to `/post/1` and keyed as such in the prefetch cache. However, the cache
entry is actually associated with `app/foo/@modal/(...post)/[id]`. That
means when you trigger the same interception on `/bar`, it will return
the tree from `/foo`.

### How?
This PR will prefix the prefetch cache key with `state.nextUrl` when
necessary.

Fixes vercel#49878
Fixes vercel#52748
Closes NEXT-1818
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants