-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Description
Current behavior
When using Cypress in e2e mode, the React Router application fails with the error "Hydration failed." This happens in both SPA and SSR modes.
The following example was created with create-react-router, and Cypress was installed.
To reproduce the error:
- Clone the following repository and install the dependencies using pnpm or another package manager.
- Run pnpm dev in one terminal.
- Run pnpm cy:open in another terminal.
- Execute the test and observe the error.
If you access the application using Chrome or any other browser outside of Cypress, everything works as expected.
Desired behavior
The application must render without error.
Test code to reproduce
Link to repository:
https://github.com/javialon26/react-router-cypress
Cypress Version
14.2.1
Node version
v20.12.2
Operating System
macOS
Debug Logs
Other
Error:
(uncaught exception)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 ... <Router basename="/" location={{pathname:"/", ...}} navigationType="POP" navigator={{...}}> <RenderErrorBoundary location={{pathname:"/", ...}} revalidation="idle" component={} error={undefined} ...> <RenderedRoute match={{params:{}, ...}} routeContext={{outlet:null, ...}}> + <style dangerouslySetInnerHTML={{__html:"\n/* /app/..."}}> - {" "} ... ...
Issue in react-router repo:
remix-run/react-router#13359