Using Client component in layout.js
Unanswered
Toyger posted this in #help-forum
ToygerOP
I want to use the layout as a client component and have useEffect to fetch data.. its because server components are slow when switching routes
61 Replies
ToygerOP
because the layout loads data, and the redirecting takes like 3 mins
i want it to go to a different route instantly
@Toyger because the layout loads data, and the redirecting takes like 3 mins
It probably happens in development. Have you tried in production?
@Anay-208 It probably happens in development. Have you tried in production?
ToygerOP
its still slow
it doesnt feel smooth
It won't make much difference. just rendering will take time
ToygerOP
but like how are other websites extremely fast in switching routes
@Toyger I want to use the layout as a client component and have useEffect to fetch data.. its because server components are slow when switching routes
You can add "use client"; at the top and try it out then
ToygerOP
like the vercel website itself
it loads everything instantly
@Anay-208 You can add "use client"; at the top and try it out then
ToygerOP
but people hate me when i use a client component as parent
Ya, I'll also hate you
ToygerOP
so what do i do to increase speed
@Toyger it loads everything instantly
Not instantly, but roughly 0.5s, till it gets data from the server
@Anay-208 Not instantly, but roughly 0.5s, till it gets data from the server
ToygerOP
but the website itself feels smooth
as in it shows those loading components
it doesnt buffer the whole page
Can you give a minimum repro repo on where you face speed issues? Because I don't face any
ToygerOP
i clicked sell
and it took like 5 secs
to redirect
on production
i feel like its because of server components
Original message was deleted
Are you using the
Link element for urls?ToygerOP
no
<a> tagscause
Link is even slower@Toyger no `<a>` tags
Thats the reason!
@Toyger cause `Link` is even slower
With my personal experience, Link is faster!
ToygerOP
but like
<Link> is even slower than a tags@Toyger but like `<Link>` is even slower than a tags
Have you tried it?
ToygerOP
yea
i initially had that
Link doesnt even show any sort of loading
<a> atleast shows that the website buffersits also slower
idk
whats the cause
I'll need a min reproduction repo
because its a unexpected behaviour
and whats your nextjs version
ToygerOP
would making the route itself client
but have server component inside
work
@Anay-208 and whats your nextjs version
ToygerOP
latest
Just create a minimum reproduction repo & send it here
ToygerOP
idk how to do that lol
you can google it!
ToygerOP
can u give me some advice
is it fine if i fetch data in layout
and pass it
but idk how to pass it to children
no
ToygerOP
💀
sorry
you should delete above messages ASAP
ToygerOP
why what happened
i just asked for help
i didnt ask for planting bomb
ignore it then, if you don't want to.
Ping me when you get a minimum repro repo