Skip to content

bug: Nextjs hydration mismatch errorΒ #657

@JohannesSchwegler

Description

@JohannesSchwegler

Prerequisites

Stencil Version

4.35.1

Current Behavior

  • Install and build react components with the latest stencil version
  • Try to use those react-components in Nextjs (copy the generated react components.server.ts to the nextjs app and import those components)

Error:
_Uncaught Error: Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:

  • A server/client branch if (typeof window !== 'undefined').
  • Variable input such as Date.now() or Math.random() which changes each time it's called.
  • Date formatting in a user's locale which doesn't match the server.
  • External changing data without sending a snapshot of it along with the HTML.
  • Invalid HTML tag nesting.

It can also happen if the client has a browser extension installed which messes with the HTML before React loaded.

https://react.dev/link/hydration-mismatch_

Image

Expected Behavior

The components should work in a nextjs application without hydration errors

System Info

Steps to Reproduce

  1. Install and build
  2. Link current directory by running 'npm link' in the root folder
  3. Open the frameworks/react folder and run 'npm run build' and 'npm run link'
  4. Open the nextjs-app-example and run 'npm link stencilssr && npm link stencilssr-react'
  5. Run 'npm run dev' and see the error in the console

Code Reproduction URL

https://github.com/JohannesSchwegler/stencilssr-demo

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions