"use client" import * as React from "react" import { Provider as JotaiProvider } from "jotai" import { ThemeProvider as NextThemesProvider } from "next-themes" import { NuqsAdapter } from "nuqs/adapters/next/app" import { SessionProvider } from "next-auth/react" import { CacheProvider } from '@emotion/react' import { SWRConfig } from 'swr' // ✅ SWR 추가 import { TooltipProvider } from "@/components/ui/tooltip" import createEmotionCache from './createEmotionCashe' const cache = createEmotionCache() // 간소화된 SWR 설정 const swrConfig = { // 기본 동작 설정 revalidateOnFocus: false, // 포커스시 자동 갱신 비활성화 revalidateOnReconnect: true, // 재연결시 갱신 활성화 shouldRetryOnError: false, // 에러시 자동 재시도 비활성화 (수동으로 제어) dedupingInterval: 2000, // 2초 내 중복 요청 방지 refreshInterval: 0, // 기본적으로 자동 갱신 비활성화 (개별 훅에서 설정) // 간단한 전역 에러 핸들러 (토스트 없이 로깅만) onError: (error: any, key: string) => { // 개발 환경에서만 상세 로깅 if (process.env.NODE_ENV === 'development') { console.warn('SWR fetch failed:', { url: key, status: error?.status, message: error?.message }) } // 401 Unauthorized의 경우 특별 처리 (선택사항) if (error?.status === 401) { console.warn('Authentication required') // 필요시 로그인 페이지로 리다이렉트 // window.location.href = '/login' } }, // 전역 성공 핸들러는 제거 (너무 많은 로그 방지) // 기본 fetcher 제거 (각 훅에서 개별 관리) } export function ThemeProvider({ children, ...props }: React.ComponentProps) { return ( {/* ✅ 간소화된 SWR 설정 적용 */} {children} ) }