Skip to content

Map doesn't zoom to search results when PRELOAD_MAP is on #736

Description

@jamiefolsom

With PRELOAD_MAP=true, the explore-page map stays at the world view instead of zooming to the results. The console shows TypeError: Cannot read properties of undefined (reading 'getData') from the map search code.

Cause. getBoundingBox in src/apps/search/map/MapSearchContext.tsx has two paths. Without preload it computes the box from the features it already has. With preload it calls map.getSource('source-' + uuid).getData() for every visible feature — assuming each feature's source is already on the map. The zoom effect can run before MultiLayer has added them all, so getSource returns undefined and the call throws an error. The error happens inside the Promise executor, so the promise never settles and nothing retries: the map sits at 0/0/0.

Sites without PRELOAD_MAP never run this path, which is why most sites zoom fine.

Suggested fix. In the preload path, when getSource returns nothing, fall back to the feature itself (what the non-preload path does) or wait for the source to register — and make the promise settle on failure so the zoom can retry.

Seen on a static build (which requires PRELOAD_MAP=true for the geometry snapshot), but reproducible on any deployment with the flag on.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions