nextjs - 💡(How to fix) Fix React compiler causes hydration error with multiline className [2 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#88280Fetched 2026-04-08 02:05:12
View on GitHub
Comments
2
Participants
3
Timeline
9
Reactions
2
Author
Timeline (top)
labeled ×3commented ×2closed ×1cross-referenced ×1

Error Message

  1. See the hydration error

Fix Action

Fix / Workaround

A tree hydrated but some attributes of the server rendered HTML didn't match the client properties. This won't be patched up. This can happen if a SSR-ed Client Component used:

Code Example

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.2.0: Tue Nov 18 21:09:34 PST 2025; root:xnu-12377.61.12~1/RELEASE_ARM64_T8112
  Available memory (MB): 16384
  Available CPU cores: 8
Binaries:
  Node: 24.11.1
  npm: 11.6.2
  Yarn: N/A
  pnpm: 10.8.0
Relevant Packages:
  next: 16.1.1 // Latest available version is detected (16.1.1).
  eslint-config-next: N/A
  react: 19.2.3
  react-dom: 19.2.3
  typescript: N/A
Next.js Config:
  output: N/A

---

<div
+  className={"\n        flex min-h-screen items-center justify-center bg-zinc-50 font-s..."}
-  className={" flex min-h-screen items-center justify-center bg-zinc-50 font-sans dark:..."}
>

---

<div
      className="
        flex min-h-screen items-center justify-center bg-zinc-50 font-sans
        dark:bg-black
      "
    >
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/V-iktor/hydration

To Reproduce

  1. Start the application
  2. Open the webpage
  3. See the hydration error

Current vs. Expected behavior

Multi line className should match on server vs. client. Server adds \n causing a mismatch

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.2.0: Tue Nov 18 21:09:34 PST 2025; root:xnu-12377.61.12~1/RELEASE_ARM64_T8112
  Available memory (MB): 16384
  Available CPU cores: 8
Binaries:
  Node: 24.11.1
  npm: 11.6.2
  Yarn: N/A
  pnpm: 10.8.0
Relevant Packages:
  next: 16.1.1 // Latest available version is detected (16.1.1).
  eslint-config-next: N/A
  react: 19.2.3
  react-dom: 19.2.3
  typescript: N/A
Next.js Config:
  output: N/A

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

React

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

next dev (local)

Additional context

Before turning on React compiler the site loaded normally.

After adding the babel plugin and enabling the React compiler I got hydration errors.

A tree hydrated but some attributes of the server rendered HTML didn't match the client properties. This won't be patched up. This can happen if a SSR-ed Client Component used:

<div
+  className={"\n        flex min-h-screen items-center justify-center bg-zinc-50 font-s..."}
-  className={" flex min-h-screen items-center justify-center bg-zinc-50 font-sans dark:..."}
>

This is the relevant code, multiline formatted to make Tailwind more readable:

    <div
      className="
        flex min-h-screen items-center justify-center bg-zinc-50 font-sans
        dark:bg-black
      "
    >

extent analysis

TL;DR

Remove newline characters from the className attribute to fix the hydration error.

Guidance

  • Verify that the issue is caused by the newline characters in the className attribute by checking the server-rendered HTML and the client-side properties.
  • Remove the newline characters from the className attribute to ensure it matches on both the server and client sides.
  • Consider using a CSS class naming convention that avoids long class names or multiline formatting to prevent similar issues in the future.
  • Check the React compiler and Babel plugin configurations to ensure they are not introducing any unnecessary whitespace or formatting issues.

Example

// Before
<div
  className="
    flex min-h-screen items-center justify-center bg-zinc-50 font-sans
    dark:bg-black
  "
>

// After
<div
  className="flex min-h-screen items-center justify-center bg-zinc-50 font-sans dark:bg-black"
>

Notes

This solution assumes that the issue is solely caused by the newline characters in the className attribute. If the issue persists after removing the newline characters, further investigation into the React compiler and Babel plugin configurations may be necessary.

Recommendation

Apply the workaround by removing the newline characters from the className attribute, as this is a simple and effective solution to fix the hydration error.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING