-
Notifications
You must be signed in to change notification settings - Fork 26.5k
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
App router: Components in root layout rerender on navigation #52558
Comments
I'm noticing the same behavior. |
Likewise, also encountering this. Seems to directly contradict the purpose of the new Worth noting: using browser history doesn’t produce this error. It’s only when clicking a |
For anyone with the same problem. I was able to fix my issue with this article. Basically the useSearchParams hook on static pages makes those pages to be deopted into client side rendering. |
Issue still happening with the latest canary
There is no |
I am also facing this issue on the latest stable Next version |
I have the same issue with the latest stable version, but instead of using Component I use parallel routes here's more if you want to try the problem https://nextjs-forum.com/post/1189895822251405382 @jk1x8 I tested the testing app you linked and I don't see any problems, the navbar render once on page reload but in navigation it dosn't re-render. |
We have a similar issue: An input field has the onChange => and there we set the value to the search param (router.replace). |
Same issue in my navbar using: 'use client' strict mode off |
This comment has been minimized.
This comment has been minimized.
same issue and i tried to reprouce it on sandbox and same thing. |
Same issue. When I try removing useEffects it works like dev |
Facing the same problem, removed all usePathname, useParams, useSearchParams, still layout rerenders on the same page segment change |
I encountered a similar issue involving a component utilizing 'use client' and React.memo. Upon removing the memo, it worked as expected. Unfortunately, identifying the issue required several hours of troubleshooting. Next team should take care of it, or at the very least, add some note to their docs. |
same here, I noticed this issue because I have a component inside which there is a However, this just happened when I first visited those routes, but after it worked as expected. So, this is the default behavior or what? Because I was thinking the root layout component would just stay there, while only the |
Same here. Using useEffect or useState in a "use client" component, imported into layout.js, causes full reload of page/layout when navigating to root (app/page.js). But does not re-render navigating to or between sub-routes (about/page.js or contact/page.js).
|
Verify canary release
Provide environment information
Which area(s) of Next.js are affected? (leave empty if unsure)
App Router, Routing (next/router, next/navigation, next/link)
Link to the code that reproduces this issue or a replay of the bug
https://github.com/jk1x8/App-router-issue
To Reproduce
npm run build
andnpm start
, then open the app and navigate between pages. You will see (in the console) that navbar component that is placed in root layout rerenders on every route change.npm run dev
, open app and you will see no rerenders of navbar during navigation, in dev mode components placed in root layout don't change.Describe the Bug
Client components in root layout are re-rendering on every navigation change in production mode. When React.memo is added it's even worse, the not only rerender but loose their state on route change. In dev mode everything is fine, they don't re-render when the page is changed. I have a client-component Navbar that is shared accros the whole app
and should not rerender on page change. In dev mode it work's fine but there are problems after building the app. React StrictMode is disabled.
Expected Behavior
Components, even client components placed in layout should not rerender on navigation.
Which browser are you using? (if relevant)
Chrome
How are you deploying your application? (if relevant)
No response
The text was updated successfully, but these errors were encountered: