๐ hydration mismatch ๋์ ์ ๋ฆฌ - codesquad-masters2025-team01/issue-tracker GitHub Wiki
- Next.js App Router์์ layout.tsx์
"use client"
๋ฅผ ์ฌ์ฉํ์ง ์์์์๋ hydration mismatch ์๋ฌ๊ฐ ๋ฐ์ํจ.
// src/app/layout.tsx
export default function RootLayout({ children }) {
return (
<html lang="ko">
<body>
<ClientProviders>{children}</ClientProviders>
</body>
</html>
);
}
์๋ฌ๋ฉ์ธ์ง
Error: A tree hydrated but some attributes of the server rendered HTML didn't match the client properties...
<body
cz-shortcut-listen="true"
style={{}}
>
-
ColorZilla ํ์ฅ ํ๋ก๊ทธ๋จ์ด
<body>
ํ๊ทธ์cz-shortcut-listen="true"
์์ฑ์ ๋์ ์ผ๋ก ์ถ๊ฐ -
React DevOverlay ๋๋ Emotion์ด ํด๋ผ์ด์ธํธ์์ ๋น
style={{}}
์ ์ฝ์ - ์ด๋ก ์ธํด ์๋ฒ์์ ๋ ๋๋ง๋ HTML๊ณผ ํด๋ผ์ด์ธํธ๊ฐ ๊ณ์ฐํ DOM์ด ์ผ์นํ์ง ์์ hydration mismatch ๊ฒฝ๊ณ ๋ฐ์
- Hydration: SSR๋ก ์์ฑ๋ HTML์ React๊ฐ ํด๋ผ์ด์ธํธ์์ React ํธ๋ฆฌ๋ก ๋ณํํ๋ ๊ณผ์
- SSR vs CSR: ์๋ฒ ์ปดํฌ๋ํธ๋ Node.js์์ ์์ HTML์, ํด๋ผ์ด์ธํธ ์ปดํฌ๋ํธ๋ ๋ธ๋ผ์ฐ์ ์์ JS ๋ ๋๋ง
- Dynamic ์์ฑ: ๋ธ๋ผ์ฐ์ ํ์ฅ์ด๋ DevOverlay๊ฐ ํด๋ผ์ด์ธํธ์์๋ง ์ฝ์ ํ๋ ์์ฑ
- suppressHydrationWarning: React์์ ํน์ ์์์ ์๋ฒ/ํด๋ผ์ด์ธํธ DOM ์ฐจ์ด๋ฅผ ๋ฌด์ํ๋๋ก ํ๋ ์์ฑ
- ColorZilla ํ์ฅ ๊ธฐ๋ฅ ์ฌ์ฉ ์ค์ง
- ๋ธ๋ผ์ฐ์ ํ์ฅ ๊ด๋ฆฌ์์์ ColorZilla๋ฅผ ๋นํ์ฑํ
- ํ์ด์ง ์๋ก๊ณ ์นจ ํ
<body>
์ ๋ ์ด์cz-shortcut-listen="true"
์์ฑ์ด ๋ถ์ง ์๋์ง ํ์ธ - hydration mismatch ๊ฒฝ๊ณ ๊ฐ ์ฌ๋ผ์ก๋ค๋ฉด ํด๊ฒฐ ์๋ฃ
<body suppressHydrationWarning>
์์ฑ ์ถ๊ฐ
// src/app/layout.tsx
export default function RootLayout({ children }) {
return (
<html lang="ko">
<body suppressHydrationWarning>
<ClientProviders>{children}</ClientProviders>
</body>
</html>
);
}
- React๊ฐ
<body>
์ ์๋ฒ/ํด๋ผ์ด์ธํธ ์์ฑ ์ฐจ์ด๋ฅผ ๋ฌด์ํ์ฌ hydration mismatch ๊ฒฝ๊ณ ์ ๊ฑฐ