From be7086bdd7afad40b56fc3ca27bac673b6509261 Mon Sep 17 00:00:00 2001 From: KangShinGyu Date: Thu, 22 Oct 2026 15:42:36 +0900 Subject: [PATCH] =?UTF-8?q?fix(map):=20=ED=98=84=20=EC=9C=84=EC=B9=98=20?= =?UTF-8?q?=EA=B2=80=EC=83=89=20=ED=9B=84=20=ED=95=84=ED=84=B0=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20=EC=8B=9C=20Places=20=EC=A4=91=EB=B3=B5=20=EA=B2=80?= =?UTF-8?q?=EC=83=89=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/map/MapDiscoverPlaces.tsx | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/components/map/MapDiscoverPlaces.tsx b/src/components/map/MapDiscoverPlaces.tsx index b597f5a..ef6de3b 100644 --- a/src/components/map/MapDiscoverPlaces.tsx +++ b/src/components/map/MapDiscoverPlaces.tsx @@ -1,6 +1,6 @@ "use client"; -import { useCallback, useEffect, useRef, useState } from "react"; +import { useCallback, useEffect, useEffectEvent, useRef, useState } from "react"; import { AdvancedMarker, useMap, @@ -128,6 +128,8 @@ export function MapDiscoverPlaces({ const searchSeqRef = useRef(0); const prevCategoryIdRef = useRef(null); + // 요청 ID는 0으로 돌아가지 않는다. 마운트 때 값은 이미 처리한 요청으로 보고 새로 누른 요청만 검색한다 + const seenRecenterIdRef = useRef(discoverRecenterRequestId); const runDiscoverSearch = useCallback( async ( @@ -312,8 +314,7 @@ export function MapDiscoverPlaces({ ]); /** `현 위치 검색` 버튼 → discover 스냅샷 갱신·재조회 */ - useEffect(() => { - if (discoverRecenterRequestId === 0) return; + const recenterDiscover = useEffectEvent(() => { if (!selectedCategoryId || !map || !placesLib) return; const snapshot = buildDiscoverSnapshotFromGoogleMap(map); if (!snapshot) return; @@ -329,15 +330,13 @@ export function MapDiscoverPlaces({ epochRecenter, ); }); - }, [ - discoverRecenterRequestId, - selectedCategoryId, - rating, - openNow, - map, - placesLib, - runDiscoverSearch, - ]); + }); + useEffect(() => { + if (seenRecenterIdRef.current !== discoverRecenterRequestId) { + seenRecenterIdRef.current = discoverRecenterRequestId; + recenterDiscover(); + } + }, [discoverRecenterRequestId]); const selectedNormalized = selectedPlace?.googlePlaceId ? normalizeGooglePlaceResourceId(selectedPlace.googlePlaceId)