fix: Map 컴포넌트 SSR 에러 수정 (500 에러 해결)

This commit is contained in:
Hyungi Ahn
2025-11-09 09:30:55 +09:00
parent a724b1bf32
commit a01897f50f

View File

@@ -1,3 +1,4 @@
import { useEffect, useState } from 'react'
import { MapContainer, TileLayer, Marker, Popup } from 'react-leaflet'
import { Icon } from 'leaflet'
import { Attraction } from '../types'
@@ -18,6 +19,13 @@ const attractionIcon = new Icon({
})
const Map = ({ attractions }: MapProps) => {
const [isMounted, setIsMounted] = useState(false)
// 클라이언트 사이드에서만 렌더링 (SSR 에러 방지)
useEffect(() => {
setIsMounted(true)
}, [])
// 구마모토 중심 좌표
const kumamotoCenter: [number, number] = [32.8031, 130.7079]
@@ -25,6 +33,18 @@ const Map = ({ attractions }: MapProps) => {
const tilesUrl = import.meta.env.VITE_MAP_TILES_URL || 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'
const isCustomTiles = !!import.meta.env.VITE_MAP_TILES_URL
// 서버 사이드에서는 로딩 화면 표시
if (!isMounted) {
return (
<div className="bg-white rounded-lg shadow-md p-6">
<h2 className="text-2xl font-bold text-gray-800 mb-6">🗺 </h2>
<div className="w-full h-96 rounded-lg overflow-hidden border border-gray-200 flex items-center justify-center bg-gray-100">
<p className="text-gray-500"> ...</p>
</div>
</div>
)
}
return (
<div className="bg-white rounded-lg shadow-md p-6">
<h2 className="text-2xl font-bold text-gray-800 mb-6">🗺 </h2>