Skip to content

Commit 5fab977

Browse files
antontranelisclaude
andcommitted
fix: resolve mobile location popup bugs
- Add useEffect cleanup to prevent stacked timeouts from continuous locationfound events on mobile (watch mode fires repeatedly) - Handle all error types in catch block instead of re-throwing unknown errors, which caused silent crashes on mobile - Add .catch() to the "Yes" button promise chain so errors close the modal and prevent it from reappearing Reported by Ocean Nomads crew member testing on iPhone. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 4243d30 commit 5fab977

1 file changed

Lines changed: 28 additions & 22 deletions

File tree

lib/src/Components/Map/Subcomponents/Controls/LocateControl.tsx

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,13 @@ export const LocateControl = (): React.JSX.Element => {
129129
setShowLocationModal(true)
130130
}, 1000)
131131
}
132+
133+
return () => {
134+
if (timeoutRef.current) {
135+
clearTimeout(timeoutRef.current)
136+
timeoutRef.current = null
137+
}
138+
}
132139
}, [active, foundLocation, showLocationModal, hasUpdatedPosition, shouldShowModal])
133140

134141
useMapEvents({
@@ -240,25 +247,19 @@ export const LocateControl = (): React.JSX.Element => {
240247
setHasUpdatedPosition(false)
241248
}, 5000)
242249
} catch (error: unknown) {
243-
if (error instanceof Error) {
244-
toast.update(toastId, {
245-
render: error.message,
246-
type: 'error',
247-
isLoading: false,
248-
autoClose: 5000,
249-
closeButton: true,
250-
})
251-
} else if (typeof error === 'string') {
252-
toast.update(toastId, {
253-
render: error,
254-
type: 'error',
255-
isLoading: false,
256-
autoClose: 5000,
257-
closeButton: true,
258-
})
259-
} else {
260-
throw error
261-
}
250+
const message =
251+
error instanceof Error
252+
? error.message
253+
: typeof error === 'string'
254+
? error
255+
: 'An unexpected error occurred'
256+
toast.update(toastId, {
257+
render: message,
258+
type: 'error',
259+
isLoading: false,
260+
autoClose: 5000,
261+
closeButton: true,
262+
})
262263
}
263264
}, [myProfile.myProfile, foundLocation, updateItem, addItem, layers, user, lc, navigate])
264265

@@ -310,9 +311,14 @@ export const LocateControl = (): React.JSX.Element => {
310311
<label
311312
className='tw:btn tw:mt-4 tw:btn-primary'
312313
onClick={() => {
313-
void itemUpdatePosition().then(() => {
314-
setShowLocationModal(false)
315-
})
314+
void itemUpdatePosition()
315+
.then(() => {
316+
setShowLocationModal(false)
317+
})
318+
.catch(() => {
319+
setShowLocationModal(false)
320+
setHasDeclinedModal(true)
321+
})
316322
}}
317323
>
318324
Yes

0 commit comments

Comments
 (0)