yaodingyd / react-flickity-component

A React.js component for using @desandro's Flickity
314 stars 51 forks source link

bug: prevent crashes on hydration #146

Closed Quicksaver closed 1 year ago

Quicksaver commented 1 year ago

On certain cases with SSR'd pages (i.e. Next.js), if we have some hydration issues, the Flickity component may first (or intermediately) render null, while still calling componentDidMount and componentDidUpdate.

Without a valid node, the app crashes trying to instantiate Flickity on null:

Screenshot 2023-06-01 at 12 24 39

This patch fixes that, by ensuring that this.carousel exists before trying to instantiate Flickity with it, ensuring that this.flkty exists before trying to access it.

yaodingyd commented 1 year ago

thanks!