> ## Content Index
> Fetch the complete content index at: https://blog.sudowl.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# One Empty Field in an Admin Panel Crashed the Mobile App
- URL: https://blog.sudowl.com/one-empty-field-in-admin-panel-crashed-mobile-app/
- Published: 2026-12-03T16:00:00.000Z
- Updated: 2026-12-04T12:22:14.000Z
- Description: A shop saved with an empty type field made a React Native app crash on almost every search. Fix the data first, then the code, then the panel.
- Author: Lukas
- Tags: Linux

Late at night I got the message every app maintainer loves: "the app crashes really often". It's a city app I maintain for a client, React Native with Expo, Supabase behind it, and a small web admin panel where staff can edit entries. Those edits are stored as "corrections" that get laid over the default data built into the app. Shops, restaurants and so on ship inside the app, and the panel can change, hide or add entries without an app update.

That flexibility is exactly what bit us. One shop had been added in the panel with the "type" field left empty. That single `null` crashed the shopping search on almost every search, for every user, on every version already in the stores.

**TL;DR:** The shopping search did `shop.art.toLowerCase()` (`art` is the type field). One panel entry had `art: null`, so the filter threw as soon as anyone typed. I fixed it in this order: (1) correct the row in the production database, which fixes the crash immediately for all app versions, users just have to fully close and reopen the app; (2) make the app's merge ignore empty panel fields so they can never override defaults; (3) make the panel refuse to save a shop without a type. Then a second crash from the store console turned out to be the same class of problem on the map: a point with an invalid latitude.

## The line that crashed

```tsx
const filtered = useMemo(() => {
  const q = search.trim().toLowerCase();
  return allShops.filter((shop) => {
    if (category && shop.category !== category) return false;
    return (
      shop.name.toLowerCase().includes(q) ||
      shop.art.toLowerCase().includes(q)   // art === null -> TypeError
    );
  });
}, [allShops, category, search]);

```

TypeScript was happy because the built-in type says `art: string`, and the built-in data (from OpenStreetMap) always has it. The panel data is whatever JSON comes out of the database.

It crashed on almost every search, not only when searching for that shop, because the filter walks every shop for every query. The broken entry just had to be in the list.

There was a second symptom: the shop didn't show up under its category tile either. Its category was saved as "other" instead of "fashion". Same root cause, a panel form that let you save half an entry.

## Step 1: fix the data in production, right now

Before touching any code I checked all 144 panel entries for missing fields. Only this one was broken. Then I fixed it directly in the database (in a transaction, checking the result before commit):

```sql
BEGIN;
UPDATE corrections
   SET fields = fields || '{"art": "clothes", "category": "fashion"}'::jsonb
 WHERE key = 'shop:new/abc123';
SELECT key, fields->>'name', fields->>'art', fields->>'category'
  FROM corrections WHERE key = 'shop:new/abc123';
COMMIT;

```

Then I read the entry back through the public API, the same way the app fetches it, to make sure the app would see `clothes` and `fashion`.

This step feels like a hack, but it's the most important one. A code fix needs a store build, review and users actually updating. The data fix works for every installed version as soon as the app loads fresh data.

The catch: the app caches the corrections it loaded at startup, so "fixed in the database" doesn't mean "fixed on the phone". Users had to close the app completely and reopen it with internet.

## Gotcha: Android keeps your app alive for days

The next day two separate reports came in: the app still crashing on Android, and the shop still missing from the fashion tile. The live data was clean. I took the old app code (the version on Android at that point) and ran it against the live data: all 230 shops through the list, the fashion tile, search, detail page and global search. Zero errors.

Two things were going on. The missing shop had a second, boring cause: the shop list was capped at 40 entries, fashion now had 57 shops, and this one sorted alphabetically past position 40\. Tap the tile, never see it. That's fixed in the next version: with a category or search active, the list shows everything; without a filter it stays at 40 with a "show all" link.

The crash most likely came from the cache. Android often keeps apps running in the background for days, and the app only loads panel data on start. My best guess: they couldn't find the shop in the tile, searched for it, and the app was still running with the previous night's data, where the type was still empty. I can't prove that without a crash report, and I said so. But it fits, and it's the reason "fully close and reopen" has to be in the message to users.

## Step 2: empty panel fields never override defaults

The real bug in the code was the merge. Panel corrections were spread over the built-in entry, and `null` happily overwrote a perfectly good default. The fix: only non-empty values from the panel win. This applies to shops, restaurants, accommodation and ski schools.

```ts
function withDefaults<T extends object>(
  base: T,
  override: Partial<Record<keyof T, unknown>>,
): T {
  const out = { ...base } as Record<string, unknown>;
  for (const [key, value] of Object.entries(override)) {
    if (value === null || value === undefined) continue; // empty never wins
    out[key] = value;
  }
  return out as T;
}

// Built-in entry + panel correction
const shop = withDefaults(builtInShop, correction.fields);

// Brand new panel entry: merge onto a template of safe empty values
const newShop = withDefaults(EMPTY_SHOP, correction.fields);

```

New entries that only exist in the panel have no built-in base, so they get merged onto a template with safe empty values instead. And the search line got the obvious belt-and-braces fix too:

```tsx
(shop.art ?? '').toLowerCase().includes(q)

```

## Step 3: the panel stops accepting broken shops

The panel now refuses to save a shop without a type. If the type field is empty, it fills one in from the chosen category tile on save:

| Tile      | Type                 |
| --------- | -------------------- |
| Fashion   | clothes              |
| Jewellery | jewelry              |
| Sport     | sports               |
| Home      | interior\_decoration |
| Groceries | convenience          |
| Beauty    | beauty               |

(Plus a couple more tiles, each with its own fallback value.)

```js
function beforeSave(values) {
  if (!values.art) values.art = TYPE_FOR_TILE[values.category] ?? FALLBACK_TYPE;
  return values;
}

```

Two decisions here that I'd make again:

- **Fill it on save, not when the form opens.** If you prefill on open, someone changes the tile afterwards and you've saved a type that matches the old tile. On save it always matches what they finally picked. The filled-in type is visible in the form afterwards.
- **The default tile for new shops stays "other".** I could have defaulted it to fashion, since that's what this one shop needed. But then every bakery and hardware store added in a hurry would land in fashion. A wrong default is worse than an obvious empty one.

Staff need to reload the panel once to get the new version. It's a static page, so a reload is all it takes.

## The second crash: MapLibre and an invalid latitude

While I was in the store consoles anyway, the Play Console showed a different crash: inside MapLibre's `LatLng.setLatitude` on Android. That happens when the map gets a point whose latitude is missing or invalid (`NaN`, or outside -90 to 90). MapLibre doesn't skip the point, it takes the whole app down.

According to the report it only hit old versions, 1.3.0 and 1.3.1, and the last occurrence was 35 hours earlier. I didn't find a single broken source: the live panel data has no invalid coordinates now. Probably an entry was saved for a while without a valid location, just like the shop with no type.

Since I couldn't find the one bad record, the fix is that the map trusts nobody. Every coordinate is checked before it reaches MapLibre: pins, the route line, flying to a place, and the initial view. Invalid points are skipped instead of crashing.

```ts
export function isValidCoord(lat: unknown, lon: unknown): lat is number {
  return (
    typeof lat === 'number' &&
    typeof lon === 'number' &&
    Number.isFinite(lat) &&
    Number.isFinite(lon) &&
    lat >= -90 && lat <= 90 &&
    lon >= -180 && lon <= 180
  );
}

const safePins = pins.filter((p) => isValidCoord(p.latitude, p.longitude));
const safeLine = (line ?? []).filter((p) => isValidCoord(p.latitude, p.longitude));
const routeLine = safeLine.length > 1 ? safeLine : null;

const center = isValidCoord(region.latitude, region.longitude)
  ? [region.longitude, region.latitude]
  : FALLBACK_CENTER;

```

On top of that, the same merge rule from step 2 covers location: an empty latitude or longitude from the panel can't override the built-in coordinates of a place anymore.

## Gotcha: `Number.isFinite`, not `isFinite`

Global `isFinite('47.4')` is `true` because it coerces strings. `Number.isFinite('47.4')` is `false`. If coordinates come from JSON that a human typed into a form, you want the strict one, and you want the `typeof` check anyway so a string never reaches native code.

## What I'd tell anyone with an admin panel in front of a mobile app

The panel is an input to your app's runtime, just like user input, and it's filled in by busy people between other tasks. Your TypeScript types describe the data you built in, not the data your colleagues save. Three layers, in this order of urgency:

1. Fix the data in production. It's the only fix that reaches versions already installed.
2. Make the app tolerate bad data: empty never overrides a default, and anything going into native code (maps!) gets validated.
3. Make the panel stop producing bad data in the first place.

And tell users to fully close the app. I hit the same "alive for days" effect in this app before, with [random logouts and stale events](/supabase-react-native-random-logout-token-refresh/). For servers I get errors pushed to me with [Discord alerts from server logs](/discord-alerts-server-logs-systemd/); for the app, the store crash consoles are that channel, and I should read them before a colleague has to tell me. Like [the idempotency bug that uploaded one file 153 times](/idempotency-cron-automation-duplicate-uploads/), the expensive part wasn't the bug, it was assuming the input would always be well-formed.

---

### Related posts

- [Apache: Redirect /blog to a Subdomain When the Site Is a Reverse-Proxied Node App](https://blog.sudowl.com/apache-redirect-path-to-subdomain-behind-reverse-proxy/)
- [Moving a XenForo Forum to a New Server: Empty Pages and a Forgotten Hosts Entry](https://blog.sudowl.com/xenforo-server-move-empty-pages-hosts-file-letsencrypt/)
- [Lower Your DNS TTL Before You Migrate a Server (A Checklist)](https://blog.sudowl.com/lower-dns-ttl-before-migration/)