Open UnnikrishnanBhargavakurup opened 6 months ago
@UnnikrishnanBhargavakurup There is nothing wrong with your component. By default, Next.js will pre-render client components on the server. This means that it will generate the initial HTML on the server (hence, why you see the path printed) and the component is later hydrated on the client. useEffect
only runs in the browser
You can learn more about the rendering behavior here: https://nextjs.org/docs/app/building-your-application/rendering/client-components#how-are-client-components-rendered
Got it, please close this issue.
Thanks!
Link to the code that reproduces this issue
https://github.com/UnnikrishnanBhargavakurup/my-minimal-nextjs-issue-reproduction
To Reproduce
You should observe "/contact" in the browser console, as it is a client-side component.
Current vs. Expected behavior
MobileNav.tsx
is defined as a client component but appearing as server component.Verify canary release
Provide environment information
Which area(s) are affected? (Select all that apply)
Not sure
Which stage(s) are affected? (Select all that apply)
next dev (local)
Additional context
I am facing an issue with a React component in my Next.js application. The component is meant for a mobile navigation menu and uses certain hooks and modules. However, it seems to be executing on the server side instead of the client side. Here is the relevant code:
Issue: The problem is that when I run my application, the
useEffect
andusePathname
hooks don't seem to behave as expected, and the component appears to be running on the server side.Why might this code be executing on the server side despite the intention for client-side execution?
I would appreciate any insights or suggestions on how to troubleshoot and resolve this issue. Thank you!