Are nested layouts supposed to re-render?
Answered
Long-horned bees posted this in #help-forum
Long-horned beesOP
According to the docs I would expect them not to re-render, but they do re-render when I change search params on a child RSC.
https://nextjs.org/docs/app/building-your-application/routing/pages-and-layouts#layouts
https://nextjs.org/docs/app/building-your-application/routing/pages-and-layouts#layouts
12 Replies
No, layouts shouldn’t be re-rendered. I think that’s because of React Strict Mode, try running it in production mode and test if it’s still rerendered?
Long-horned beesOP
It still re-renders in production, and strict mode is off
It only re-renders when I update a searchParam in a child RSC with router.push.
It is not supposed to do so, even the docs mentions that it won’t be rerendered because it doesn’t receive search parameters
https://nextjs.org/docs/app/api-reference/file-conventions/layout
https://nextjs.org/docs/app/api-reference/file-conventions/layout
How do you test it out? Is it a console.log in the layout?
Long-horned beesOP
Yep
The docs I linked also mention that it shouldn't re-render, but it does.
It manifested when there was layout shift in a child framer-motion layout animation
I investigated which resulted in me finding out that the layout was re-rendering whenever I changed searchParams
Long-horned beesOP
Here's a video showing the reproduction
Is it because we're reading from cookies in the layout body?
Long-horned beesOP
Ahhh yes that's it
Answer