Skip to content

Commit ae1858d

Browse files
committed
fix(map): resolve initialCoordinates even when IP lookup is skipped
Deep links (skip: true) would leave initialCoordinates null forever; combined with a listing that has no coordinates or resolves to an error sentinel, the <Map> never mounted. Fall back to DEFAULT_COORDINATES on skip so MapView can always render. Made-with: Cursor
1 parent 99cc01d commit ae1858d

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

src/features/map/components/MapView.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ export default function MapView({
181181
// MapLibre's `initialViewState` is only consumed once at mount, so we wait
182182
// for either a selected listing or the IP-based (or fallback) initial
183183
// centre to resolve before mounting the Map. `useIpInitialLocation`
184-
// always resolves (to DEFAULT_COORDINATES on failure), so this cannot
185-
// stall indefinitely.
184+
// always resolves (to DEFAULT_COORDINATES on failure or when skipped), so
185+
// this cannot stall indefinitely.
186186
const hasInitialPosition =
187187
hasValidCoordinates(selectedListing) || Boolean(initialCoordinates);
188188

src/features/map/hooks/useIpInitialLocation.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ function ensureMapTilerConfig() {
3030
hasConfiguredMapTiler = true;
3131
}
3232

33-
// One-time IP-based initial centre. On timeout or error we still resolve to
34-
// `DEFAULT_COORDINATES` so MapView, which gates on `initialCoordinates`
35-
// being set, always eventually mounts.
33+
// One-time IP-based initial centre. On timeout, error, or when skipped we
34+
// still resolve to `DEFAULT_COORDINATES` so MapView, which gates on
35+
// `initialCoordinates` being set, always eventually mounts — including deep
36+
// links to listings with `coordinates: null` or that resolve to an error.
3637
export function useIpInitialLocation({
3738
skip = false,
3839
}: UseIpInitialLocationArgs = {}): UseIpInitialLocationResult {
@@ -42,7 +43,16 @@ export function useIpInitialLocation({
4243
const [countryCode, setCountryCode] = useState<string | null>(null);
4344

4445
useEffect(() => {
45-
if (skip) return;
46+
if (skip) {
47+
// Deep-linked: we're not running the IP lookup, but MapView still
48+
// needs a non-null initial centre in case the listing itself has no
49+
// valid coordinates (error sentinel or coordinates: null).
50+
setInitialCoordinates({
51+
...DEFAULT_COORDINATES,
52+
zoom: ZOOM_LEVEL_DEFAULT,
53+
});
54+
return;
55+
}
4656

4757
ensureMapTilerConfig();
4858

0 commit comments

Comments
 (0)