Skip to content

fix: getFeatureId crashes on features without id #69

@wazolab

Description

@wazolab

Severity

P0 — Runtime crash

Description

In `src/utils/index.ts:47`:
```ts
return (metadata?.id ?? feature.properties?.id).toString()
```

If a feature has neither `metadata.id` nor `properties.id`, the expression evaluates to `undefined.toString()`, throwing an uncaught `TypeError`. Since `getFeatureId` is called in the core render loop (`renderCustom`), a single feature without an id crashes the entire map rendering.

Reproduction

Any GeoJSON feature without `properties.id` and without `properties.metadata.id` will trigger this.

Suggested Fix

Add an explicit guard:
```ts
const id = metadata?.id ?? feature.properties?.id
if (id == null)
throw new Error('Feature is missing an "id" in properties or metadata.')
return id.toString()
```

This converts a confusing `TypeError` into a meaningful error message. Alternatively, consider falling back to `feature.id` (the GeoJSON spec-level id) before throwing.

Files

  • `src/utils/index.ts:47`

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions