avatar
dodyveloper
[nextjs error] useSearchParams() should be wrapped in a suspense boundary at page ...
nextjs useSearchParams 오류는 왜 은근히 자주 등장할까?
nextjsuseSearchParams
Jul 31
·
2 min read

nextjs 의 useSearchParams 를 사용하고, yarn build를 하게 되면

useSearchParams() should be wrapped in a suspense boundary at page "/account/find-password". Read more: https://nextjs.org/docs/messages/missing-suspense-with-csr-bailout

이런 오류를 만날수 있다.

해결

next.config.js에서 experimental > missingSuspenseWithCSRBailout 의 값을 false 로 두면 된다.

const nextConfig = {
 ...
  experimental: {
    missingSuspenseWithCSRBailout: false,
  },
};
export default nextConfig;

experimental 은 nextjs의 실험적인 기능이 정의되어있고 missingSuspenseWithCSRBailout 옵션은 Suspense 을 강요 여부를 설정한다. Suspense가 누락되면 자동으로 에러를 발생시키는 기능이다.

그럼, 이게 왜 useSearchParams 와 충돌을 일으키느냐 nextjs의 server, client component 와의 관계에서 시작된다.

useSearchParams는 url 의 쿼리 파라미터에 접근하는데 사용되는데 이건 클라이언트 컴포넌트에서만 사용할 수 있다. next13 이상에서는 서버컴포넌트가 디폴트이기 때문에 생기는 충돌이다.

nextjs는 useSearchParams가 서버컴포넌트 트리에 존재할 경우, 클라이언트 사이드 렌더링으로 전환을 하는데, 그 전환과정에서 missingSuspenseWithCSRBailout 경고가 발생하는 것이다.

이걸 해결하기 위해 use client를 알맞게 선언해줌으로써 해결할수 있다.


- 컬렉션 아티클







도디입니다!