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

Router cache does not revalidate #66118

Closed
Saman-Safaei-Dev opened this issue May 23, 2024 · 4 comments
Closed

Router cache does not revalidate #66118

Saman-Safaei-Dev opened this issue May 23, 2024 · 4 comments
Labels
bug Issue was opened via the bug report template. locked Middleware Related to Next.js Middleware Navigation Related to Next.js linking (e.g., <Link>) and navigation.

Comments

@Saman-Safaei-Dev
Copy link

Saman-Safaei-Dev commented May 23, 2024

Link to the code that reproduces this issue

https://github.com/Saman-Safaei-Dev/router-cache-bug

To Reproduce

1- Start the development server and open the web app.
2- Navigate to the dashboard or any random page to be redirected to the sign-in page (use the link provided on the home page).
3- Sign in to the website to set a cookie.
4- Close the browser and reopen the web page.
5- Click on the link you previously clicked to observe the bug.

Current vs. Expected behavior

I expect to dashboard get opened but nothing happens. router cache not revalidated on cookies().set and I redirected to signin page and then redirected to home. ( redirect chain )

Provide environment information

Operating System:
  Platform: Windows 11
  Arch: x64
  Version: 23H2
Binaries:
  Node: 18.20.2
  npm: 10.5.0
Relevant Packages:
  next: 14.2.3
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 5.4.3

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

Middleware, Navigation

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

next dev (local), next build (local), next start (local)

Additional context

No response

@Saman-Safaei-Dev Saman-Safaei-Dev added the bug Issue was opened via the bug report template. label May 23, 2024
@github-actions github-actions bot added Middleware Related to Next.js Middleware Navigation Related to Next.js linking (e.g., <Link>) and navigation. labels May 23, 2024
@icyJoseph
Copy link
Contributor

Is the issue here that you redirect with a 301? I haven't had time to run your app, but here:

    if (isProtectedRoute && !isException) {
      const newUrl = new URL(`/auth/signin?path=${pathname}`, request.url);
      return NextResponse.redirect(newUrl, { status: 301 });
    }

If you have an unauthenticated user, and the route is protected, and not an excepted route, then you do a 301 to signin, and the browser saves those. Could you try using 302 instead? First clear your browser cache though, since those 301's are saved by it. https://fabricdigital.co.nz/blog/how-to-hard-refresh-your-browser-and-clear-cache

@Saman-Safaei-Dev

This comment has been minimized.

@icyJoseph
Copy link
Contributor

Nice, could you close the issue then? :)

Copy link
Contributor

github-actions bot commented Jun 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 Jun 6, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 6, 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 Middleware Related to Next.js Middleware Navigation Related to Next.js linking (e.g., <Link>) and navigation.
Projects
None yet
Development

No branches or pull requests

2 participants