next.js: `suppressHydrationWarning` not working as expected for app router

Link to the code that reproduces this issue

https://github.com/aronwoost/nextjs-suppress-warning-issue

To Reproduce

  1. npm install
  2. npm run dev
  3. Open http://localhost:3000/ in browser

Current vs. Expected behavior

Actual result: “Hello Server” is displayed
Expected result: “Hello Client” is displayed

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 20.6.0: Thu Jul  6 22:12:47 PDT 2023; root:xnu-7195.141.49.702.12~1/RELEASE_ARM64_T8101
Binaries:
  Node: 18.17.0
  npm: 9.6.7
  Yarn: 1.22.5
  pnpm: N/A
Relevant Packages:
  next: 14.1.0
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.2.2
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Not sure

Additional context

This is the code in question:

"use client";

import styles from "./page.module.css";

export default function Home() {
  let helloLabel = "";

  if (typeof window !== "undefined") {
    helloLabel = "Client";
  } else {
    helloLabel = "Server";
  }

  return (
    <main className={styles.main}>
      <h1 suppressHydrationWarning>Hello {helloLabel}</h1>
    </main>
  );
}

suppressHydrationWarning does suppress the warning, but it does also prevents re-rendering. Without the suppressHydrationWarning prop, the text is correctly displayed but (of course) the warning is printed in the devtools console.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 33
  • Comments: 21 (1 by maintainers)

Most upvoted comments

It’s expected behavior in all React 18+.

@sebmarkbage how come? Are you saying that putting suppressHydrationWarning changes how the JSX element renders? I would expect it only hides the warning and keeps everything else running the exact same way.

Can you point to documentation/change log?

I only find this: https://react.dev/reference/react-dom/client/hydrateRoot#suppressing-unavoidable-hydration-mismatch-errors (and have been using suppressHydrationWarning for date related issues every since)

Issue persists with next@14.1

@d3vAdv3ntur3s Be aware that suppressHydrationWarning only works one level deep and only with text content (source), so not sure if it would work with your example.

I use Next.js v15.1.4 and Chakra UI v3.0.0 with Turbopack enabled and still show hydration error although I already give html tag suppressHyrationWarning. image However when I disable Turbopack the hydration error won’t appear image

Screenshot 2024-12-05 at 03 10 21

“next”: “15.0.3”, “react”: “19.0.0-rc-66855b96-20241106”, “react-dom”: “19.0.0-rc-66855b96-20241106”

Any update here 🤔 - same issue and wondering if it will be fixed soon or need to do something else 👀

I’m experiencing the same issue. Without suppressHydrationWarning, the output is as expected but I have the hydration error. With suppressHydrationWarning, the output isn’t as expected but I have no error.

'use client';

import { updatedDateStyle } from './HouseTableUpdatedDate.css';

interface Props {
  updatedAt: number;
}

const HouseTableUpdatedDate = (props: Props) => {
  const { updatedAt } = props;

  const updatedDate = new Intl.DateTimeFormat('ko', {
    dateStyle: 'full',
    timeStyle: 'medium',
  }).format(updatedAt);

  return <p className={updatedDateStyle}>{updatedDate}</p>;
};

export default HouseTableUpdatedDate;

I’m on next 14.2.2

Also - even with React 18 - the Page Router still have the old behavior.

same issue here, it would be nice to now if this is the expected behaviour on next or if it is a bug