Invalidate map and geolocate only when visible

Move the setTimeout and its contents inside the visible check so map.invalidateSize() and navigator.geolocation.getCurrentPosition(...) are only invoked when the map container is shown. This avoids unnecessary map invalidation and geolocation requests when the view is hidden; try/catch and the 0ms defer are preserved.
This commit is contained in:
Namhyeon, Go 2026-02-09 23:28:34 +09:00
parent 2804a4a4df
commit 92f434ec07

View File

@ -367,17 +367,17 @@
containerRef.current.style.display = (visible ? "block" : "none"); containerRef.current.style.display = (visible ? "block" : "none");
// defer until after layout/display change // defer until after layout/display change
if (visible) {
setTimeout(function () { setTimeout(function () {
try { try {
map.invalidateSize(); map.invalidateSize();
if (visible) {
navigator.geolocation.getCurrentPosition(pos => { navigator.geolocation.getCurrentPosition(pos => {
mark(pos.coords.latitude, pos.coords.longitude, `My Location: (${pos.coords.latitude}, ${pos.coords.longitude})`); mark(pos.coords.latitude, pos.coords.longitude, `My Location: (${pos.coords.latitude}, ${pos.coords.longitude})`);
}); });
}
} catch (e) {} } catch (e) {}
}, 0); }, 0);
}
}, [visible]); }, [visible]);
return _e('div', { id: 'mapView', ref: containerRef }); return _e('div', { id: 'mapView', ref: containerRef });