Next.js Discord

Discord Forum

App Dir not passing props to client component on hydration with strict mode

Answered
Isaac Smith posted this in #help-forum
Open in Discord
Avatar
Isaac SmithOP
I have this sorta layout:

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.
View full answer

20 Replies

Avatar
Dunker
can you show real code and check the existence of images before passing to component like {images.length !== 0 <ClientComp ...
Avatar
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
Ray
does it become empty if you disable strict mode
Avatar
Isaac SmithOP
When I disable strict mode it is not empty.
Avatar
Ray
I just tried, pass props to client component and it is not empty
Avatar
Isaac SmithOP
I'm on latest next version
Avatar
Ray
me too
Avatar
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
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
Ray
I think you can import from github on codesanbox
Avatar
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
Ray
can you show me the codesandbox
Avatar
Isaac SmithOP
dmed you
Avatar
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