Skip to content

Commit 9d57ca3

Browse files
committed
fix: don't block map init on geoip, add 5s timeout
1 parent 3aa59b0 commit 9d57ca3

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

app/composables/useUserLocation.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ async function fetchIpGeolocation() {
3030
ipGeoStatus.value = 'pending'
3131

3232
try {
33-
const response = await fetch('https://geoip.nimiq-network.com:8443/v1/locate')
33+
const controller = new AbortController()
34+
const id = setTimeout(() => controller.abort(), 5000)
35+
const response = await fetch('https://geoip.nimiq-network.com:8443/v1/locate', { signal: controller.signal })
36+
clearTimeout(id)
3437
const json: NimiqGeoIpResponse = await response.json()
3538

3639
if (json?.location?.latitude && json?.location?.longitude) {

app/pages/index.vue

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const { query, category, autocompleteLocations, autocompleteGeo, autocompleteGeo
1212
const { initialCenter, initialZoom, initialBearing, initialPitch, isInitialized, initializeView, viewCenter, setMapInstance, mapInstance, flyTo } = useMapControls()
1313
useMapUrl()
1414
const { setSearchResults, setSelectedLocation, initializeLayers, updateUserLocation } = useMapIcons()
15-
const { showUserLocation, userLocationPoint, userLocationAccuracy, isGeoReady } = useUserLocation()
15+
const { showUserLocation, userLocationPoint, userLocationAccuracy, isGeoReady, initialPoint, initialAccuracy, hasQueryParams } = useUserLocation()
1616
const { width: windowWidth, height: windowHeight } = useWindowSize()
1717
1818
// Inline composable for map interaction handlers
@@ -77,13 +77,18 @@ function useMapInteractions(options: {
7777
}
7878
7979
const logger = consola.withTag('map')
80-
// Initialize map view with accuracy-based zoom once IP geolocation resolves
81-
watch([isGeoReady, windowWidth], () => {
82-
if (!isInitialized.value && isGeoReady.value && windowWidth.value > 0) {
80+
// Initialize map immediately; don't block on GeoIP
81+
watch(windowWidth, (w) => {
82+
if (!isInitialized.value && w > 0)
8383
initializeView(windowWidth.value, windowHeight.value)
84-
}
8584
}, { immediate: true })
8685
86+
// Fly to IP location once GeoIP resolves (if map already initialized without it)
87+
watch([isGeoReady, mapInstance], ([ready, map]) => {
88+
if (ready && map && !hasQueryParams.value && initialPoint.value)
89+
flyTo(initialPoint.value, { accuracyMeters: initialAccuracy.value ?? undefined })
90+
})
91+
8792
logger.info('Map page loaded')
8893
8994
const selectedLocationUuid = ref<string | null>(null)

0 commit comments

Comments
 (0)