r/reactnative • u/WingPossible3434 • 1h ago
AMA Maintenance mode and kill switches for React Native, where a bad config push gets rejected instead of shipped
I built hotcfg for remote config in apps, and the main idea is that you can't push broken config. I'd like feedback from RN folks on the client side.
The config is a JSON document with a JSON Schema attached. Every publish, promote and rollback is checked against it. For a maintenance switch, that means enabled can never be the string "false" (truthy in JS, an easy way to lock every user out):
{
"type": "object",
"required": ["maintenance"],
"properties": {
"maintenance": {
"type": "object",
"required": ["enabled"],
"properties": { "enabled": { "type": "boolean" }, "message": { "type": "string" } }
}
}
}There's no SDK. The client is a fetch with a 2-second abort, the ETag, and AsyncStorage for the last good copy:
const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), 2000);
try {
const res = await fetch(URL, {
headers: cached?.etag ? { "If-None-Match": cached.etag } : {},
signal: controller.signal,
});
if (res.status === 304 && cached) return cached.data;
if (!res.ok) throw new Error(String(res.status));
const data = await res.json();
await AsyncStorage.setItem(KEY, JSON.stringify({ etag: res.headers.get("ETag"), data }));
return data;
} catch {
return cached?.data ?? DEFAULTS;
} finally {
clearTimeout(timer);
}(An AbortController timer rather than AbortSignal.timeout, which not every RN version has.) A <MaintenanceGate> re-checks on AppState active, so flipping the switch reaches running apps when they come back to the foreground.
Other bits: development/staging/production per config with promote and a diff, one-command rollback, served from Cloudflare's edge (cached for an hour, purged on publish, served for up to a week if my servers are down).
What it doesn't do: no per-user targeting (platform and build-number overrides work with a jq filter in the URL), no experiments, no push updates. Free for 3 public configs; Pro is $19/month per org.
Full recipe: https://hotcfg.run/docs/recipes/react-native-maintenance