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

How to Prevent Page Refresh on Language Switch in Next.js App Router #3420

Open
tuzkiiiii233 opened this issue Jan 17, 2025 · 2 comments
Open

Comments

@tuzkiiiii233
Copy link

When switching languages, the entire page refreshes. This happens in Next.js with the app router, whether using next-intl or directly storing the language in a cookie. This issue didn’t occur when using the page router before. How can I prevent the global refresh when switching languages in the app router?

@stepan662
Copy link
Collaborator

Hey, could you go into more detail with this issue?
Our testapp (https://github.com/tolgee/next-app-example) is using a server action, which invalidates cookie and that forces all server components to re-rendered. However there is no hard refresh (in traditional sense). I believe this is correct behavior.

@tuzkiiiii233
Copy link
Author

I just ran next-app-example and next-app-intl-example locally, and added a client component Test in src/app/[locale]/page.tsx.

"use client"

import { memo } from "react";

const Test = () => {
    console.log("test");

    return (<div>test</div>)
}

export default memo(Test)

When switching languages, I noticed that Test keeps refreshing as well. Is this the correct behavior? Is there any way to avoid the refresh of the Test component?
In my actual project, this refresh causes all requests on the page to be re-sent when switching languages, essentially re-rendering the page, even though the data is the same. This results in a poor user experience.
If there’s any solution, please let me know. Thank you! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants