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

redirect in server action and revalidateTag cause a parallel route to lose its active state #64728

Closed
roksui opened this issue Apr 18, 2024 · 3 comments · Fixed by #64730
Closed
Labels
bug Issue was opened via the bug report template. locked

Comments

@roksui
Copy link

roksui commented Apr 18, 2024

Link to the code that reproduces this issue

https://github.com/roksui/my-nextagram

To Reproduce

  1. Clone the repository and checkout to the master branch.
  2. Start the applicatin in dev mode using npm run dev.
  3. Go to "/login" page and press the Login button.
  4. Click on photo 1 and inside the modal click on the add comment button.
  5. The parallel route behind the modal loses its active state and turns blank.

Current vs. Expected behavior

I expected the parallel route segment behind the modal to not lose its active state when the router cache is cleared when calling revalidateTag in a server action which should only update the data inside the modal. However, I observed that while the data is successfully revalidated in the modal, the parallel route behind the modal loses its active state.

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 10 Pro
  Available memory (MB): 32545
  Available CPU cores: 16
Binaries:
  Node: 18.17.1
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 14.3.0-canary.9 // Latest available version is detected (14.3.0-canary.9).
  eslint-config-next: 14.1.1-canary.52
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.3.3
Next.js Config:
  output: N/A

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

Parallel & Intercepting Routes

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

next dev (local), next start (local)

Additional context

  • This bug was introduced in 14.3.0-canary.5 (supposedly with the PR fix refresh behavior for discarded actions #64532).
  • When looking at the Chrome dev tool's network tab when clicking on the button for adding a comment, after revalidateTag("comments") is called, the browser receives a RSC payload for the "/login" route. Now, when I remove redirect("/") inside the server action for the login, this RSC payload is not received after clicking on the add comment button.
  • If I use a version before 14.3.0-canary.5, the background segment doesn't lose its active state, however occasionally, the comment list is not revalidated and updated in the modal straight away.
@roksui roksui added the bug Issue was opened via the bug report template. label Apr 18, 2024
@roksui roksui changed the title revalidateTag causes a parallel route to lose its active state redirect in server action and revalidateTag cause a parallel route to lose its active state Apr 18, 2024
@roksui
Copy link
Author

roksui commented Apr 18, 2024

Just found out that if I manually refresh the browser after being redirected to "/" when pressing the Login button, the RSC paylod for the "/login" page is not fetched upon clicking on the add comment button, and everything seems to be working fine from then on.

@ztanner
Copy link
Member

ztanner commented Apr 18, 2024

Nice catch @roksui, thanks for the clear repro. This should be fixed in #64730

ztanner added a commit that referenced this issue Apr 18, 2024
When a server action triggers a redirect, we're incorrectly applying a
refresh marker to the segment they were on, rather than the segment they
were being redirected to. As a result, when revalidation occurs (via
`revalidateX` or `router.refresh()`), the top-level segment would be
replaced with data for an incorrect segment.

For example, if triggering a redirect action from `/redirect` to `/`,
the router state tree would save a reference to `/redirect`. The next
time a refresh or revalidate happens, it'd refresh the segment data for
`/redirect` instead of `/`.

Fixes #64728


Closes NEXT-3156
huozhi pushed a commit that referenced this issue Apr 23, 2024
When a server action triggers a redirect, we're incorrectly applying a
refresh marker to the segment they were on, rather than the segment they
were being redirected to. As a result, when revalidation occurs (via
`revalidateX` or `router.refresh()`), the top-level segment would be
replaced with data for an incorrect segment.

For example, if triggering a redirect action from `/redirect` to `/`,
the router state tree would save a reference to `/redirect`. The next
time a refresh or revalidate happens, it'd refresh the segment data for
`/redirect` instead of `/`.

Fixes #64728


Closes NEXT-3156
Copy link
Contributor

github-actions bot commented May 3, 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 May 3, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 3, 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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants