-
Notifications
You must be signed in to change notification settings - Fork 982
[Slider] React.StrictMode fixes #794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
a6103a0
to
ef7ec91
Compare
ef7ec91
to
28deb92
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work on this! 👍
* render them in the wrong position before they snap into the correct position during | ||
* hydration which would be visually jarring. | ||
*/ | ||
return isInitialRenderRef.current || index !== -1 ? ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're checking for the initial render case here, is the index !== -1
just a safety to not render the whole thing if for some reason that thumb wasn't tracked? I can't think of any reason why this check would be necessary right now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's necessary for this case:
<Slider.Root value={[20]}>
...
<Slider.Thumb />
<Slider.Thumb />
</Slider.Root>
Notice how there are two thumbs but only one value? The second thumb won't render. We handled this case before with the value !== undefined
check but perhaps it's okay to let them render a thumb that does nothing and expect them to remove the redundant JSX instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that’s probably fine too seeing as it’s just a user error that they would figure out pretty easily.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can create a PR for that then 👍
* We hide thumbs on the first render while we work out the index, otherwise SSR will | ||
* render them in the wrong position before they snap into the correct position during | ||
* hydration which would be visually jarring. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might have been ok to leave it as is rather than doing more work specifically to hide it?
Are you thinking that we'll deal with this anyway differently at some point?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You think it's okay for them to render in the wrong position and snap into a different position during hydration?
The plan is to fix the SSR issue eventually so that it renders in the correct position server-side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It’s not great but I wonder how visible it is in a real use case. But yeah regardless SSR is something we need to look at some point. We might end up with some controlled overrides (like providing the index yourself) when you want to make sure it’s ok on first server render.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might end up with some controlled overrides (like providing the index yourself)
I was thinking this too since we already have the index
prop on the Impl
part. We just don't expose it via the SliderThumb
part atm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these kind of solutions would definitely be the easiest. Simple trade offs.
NOTE: PR will be easier to review with hidden whitespace changes
Fixes #615
Fixes #773
Replaces our old
collection
logic with our newCollection
. This fixes theReact.StrictMode
issues that have been reported lately, but means the thumbs will no longer be in the correct position on initial render for SSR as our newCollection
component doesn't handle this case.More information here. Thanks to @andy-hook for narrowing down collection code as the issue.
It seems this is a less jarring experience for now so I'm thinking we can look into improving SSR experience across our components separately.
Tested in:
CleanShot.2021-07-22.at.13.18.18.mp4