App Dir not passing props to client component on hydration with strict mode
Answered
Isaac Smith posted this in #help-forum
![Avatar](https://cdn.discordapp.com/avatars/982281650446680095/0a63f0c59be9c53612dbb7206b04feef.webp?size=256)
Isaac SmithOP
I have this sorta layout:
In ServerComponent on render
On initial ClientComponent hydration render
On second ClientComponent render (React strict mode)
I have no idea what to do. Turning strict mode off solves this temporarily, but obiously that's not the ideal solution.
async function ServerComponent({images}){
return (
<Suspense>
<ClientComponent images={images} />
</Suspense>
);
}
// diff file now
'use client';
function ClientComponent({images}){
return (
<div>
{images.length}
</div>
);
}
In ServerComponent on render
images.length === 10
.On initial ClientComponent hydration render
images.length === 10
On second ClientComponent render (React strict mode)
images.length === 0
I have no idea what to do. Turning strict mode off solves this temporarily, but obiously that's not the ideal solution.
Answered by Isaac Smith
If anyone comes across this looking for an answer, my problem was I was using splice instead of slice on a prop which was changing the variable reference and affecting the subsequent renders.
20 Replies
![Avatar](https://cdn.discordapp.com/embed/avatars/2.png)
Dunker
can you show real code and check the existence of images before passing to component like
{images.length !== 0 <ClientComp ...
![Avatar](https://cdn.discordapp.com/avatars/982281650446680095/0a63f0c59be9c53612dbb7206b04feef.webp?size=256)
Isaac SmithOP
The server component only runs once and it logs the images.length on there and it is 10
The client component receives 10 on initial render, but the react strict mode renders components twice and on the second one it's empty
![Avatar](https://cdn.discordapp.com/avatars/743561772069421169/3c5d689eee4459a24fc420063411c016.webp?size=256)
Ray
does it become empty if you disable strict mode
![Avatar](https://cdn.discordapp.com/avatars/982281650446680095/0a63f0c59be9c53612dbb7206b04feef.webp?size=256)
Isaac SmithOP
When I disable strict mode it is not empty.
![Avatar](https://cdn.discordapp.com/avatars/743561772069421169/3c5d689eee4459a24fc420063411c016.webp?size=256)
Ray
I just tried, pass props to client component and it is not empty
![Avatar](https://cdn.discordapp.com/avatars/982281650446680095/0a63f0c59be9c53612dbb7206b04feef.webp?size=256)
Isaac SmithOP
I'm on latest next version
![Avatar](https://cdn.discordapp.com/avatars/743561772069421169/3c5d689eee4459a24fc420063411c016.webp?size=256)
Ray
me too
![Avatar](https://cdn.discordapp.com/avatars/982281650446680095/0a63f0c59be9c53612dbb7206b04feef.webp?size=256)
Isaac SmithOP
Hmm. Interesting.
What would be different between using strict mode and non-strict mode when it comes to this
look like strictmode found a bug for you
![Avatar](https://cdn.discordapp.com/avatars/982281650446680095/0a63f0c59be9c53612dbb7206b04feef.webp?size=256)
Isaac SmithOP
Is there an easy way to make an online replica of my example to see if i can show what i have in a not-working state?
Im gonna try to spin up a codesandbox for this
![Avatar](https://cdn.discordapp.com/avatars/743561772069421169/3c5d689eee4459a24fc420063411c016.webp?size=256)
Ray
I think you can import from github on codesanbox
![Avatar](https://cdn.discordapp.com/avatars/982281650446680095/0a63f0c59be9c53612dbb7206b04feef.webp?size=256)
Isaac SmithOP
A cloned my repo into a codesandbox and it appears to working fine
I'm not sure what could be different on my local machine 🤔
![Avatar](https://cdn.discordapp.com/avatars/743561772069421169/3c5d689eee4459a24fc420063411c016.webp?size=256)
Ray
can you show me the codesandbox
![Avatar](https://cdn.discordapp.com/avatars/982281650446680095/0a63f0c59be9c53612dbb7206b04feef.webp?size=256)
Isaac SmithOP
dmed you
![Avatar](https://cdn.discordapp.com/avatars/982281650446680095/0a63f0c59be9c53612dbb7206b04feef.webp?size=256)
Isaac SmithOP
If anyone comes across this looking for an answer, my problem was I was using splice instead of slice on a prop which was changing the variable reference and affecting the subsequent renders.
Answer