Skip to content
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

[Next.js] Hydration failed #123

Closed
dvlden opened this issue May 26, 2022 · 3 comments
Closed

[Next.js] Hydration failed #123

dvlden opened this issue May 26, 2022 · 3 comments

Comments

@dvlden
Copy link

dvlden commented May 26, 2022

I have a problem using this lib in the latest Next.js and latest React.js.

This is the error I'm getting:

Warning: Expected server HTML to contain a matching <div> in <div>.
div
div
MasonryScroller@webpack-internal:///./node_modules/.pnpm/[email protected][email protected]/node_modules/masonic/dist/module/masonry-scroller.js:24:10
Masonry@webpack-internal:///./node_modules/.pnpm/[email protected][email protected]/node_modules/masonic/dist/module/masonry.js:32:59

Followed by:

Uncaught Error: Hydration failed because the initial UI does not match what was rendered on the server.

Not sure what I can do to fix this. I searched through issues and nobody seemed to complain about using it on Next/SSR.

@jaredLunde
Copy link
Owner

It is not "fixable" in the sense that the server has no viewport. You will not be able to work around this so you basically can either ignore it or not use a masonry layout.

@dvlden dvlden closed this as completed Jun 9, 2022
@giavinh79
Copy link

You can do something like this to avoid the error on Next.js - vercel/next.js#35773 (comment)

@orlando-guy
Copy link

orlando-guy commented Jan 31, 2024

I had the same issue, here is how I fixed that:

  'use client'

  export default function App () {
     const [isServerSide, setIsServerSide] = React.useState(true)

    React.useEffect(() => {
        setIsServerSide(false)
    }, [])

    if (isServerSide) {
        return
    }

  // the rest of your code
 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants