이런 에러가 발생했다. 위 에러는 처음 페이지 SSR로 내려준 이후 CSR로 화면을 렌더링하게 되는데,
이때 서버에서 받은 해시 + 클래스명과 이후 클라이언트에서 작동하는 해시 + 클래스 명이 달라지면서 스타일을 불러올 수 없는 문제를 발생한다.
구글링 해보니까 보통 styled component에서 많이 발생하는 에러인 것 같다. 그러나 나는 tailwind를 사용하고 있었다.
에러를 자세히 보니 dark가 있었고 이것은 다크모드 설정에서 발생된 에러같았다.
나의 다크모드에는 세가지 종류가 있는데 Light, Dark, System 이 있는데. 서버에서는 localStorage에 저장된 나의 테마상태를 모르기때문에 발생되는 에러다.
리액트 공식문서에 있는 suppressHydrationWarning으로 해결하였다.
https://ko.legacy.reactjs.org/docs/dom-elements.html
DOM 엘리먼트 – React
A JavaScript library for building user interfaces
ko.legacy.reactjs.org
"Warning: Prop `className` did not match" while setting up a theme provider in Next.js
I'm trying to make a theme provider with the Context API to set the application theme, which is just a className on body. The context it's pretty simple. On the lazy initializer of the theme state,...
stackoverflow.com
'nextjs' 카테고리의 다른 글
Nextjs 미들웨어를 활용한 액세스 토큰 자동 갱신 구현하기 (0) | 2025.04.14 |
---|---|
[nextjs] Link 새창띄우기 (0) | 2023.04.09 |
build하고나서 Image 가 안나왔던 이유 nextjs Image error (0) | 2022.09.23 |
폴더명이 "ud"로 시작하면 생기는 에러 ? create-next-app (0) | 2022.09.05 |