Listoca

Feature flags

On-off switches with an optional payload, set by admins and synced to every device, so they work offline (the feature-flags part).

A feature flag is on or off for everyone, with an optional payload (a message, a URL). Admins change flags in the web admin area (Admin → Feature flags). The native app gets them through sync and keeps their last value offline; the web app reads them with the publishable key.

The flags

packages/supabase/src/flags.ts lists each flag with its default and payload fields:

export const flags = {
  // a short message at the top of the apps, e.g. planned maintenance
  announcement: { default: false, payload: { message: "" } },
};

A row in feature_flags (id = the key, enabled, payload) overrides the default. Flags without a row have their default, so a new flag works before anyone saves it.

Reading a flag

// native: from the local database
const { enabled, payload } = useFlag("announcement"); // apps/native/src/hooks/use-flag.ts

// web: one query for all flags
const { enabled, payload } = useFlag("announcement"); // apps/web/src/modules/flags/queries.ts

The announcement flag is the example: while it's on, its message shows along the bottom of the app's main screens and above every page of the web app.

Who may change them

Everyone may read the table, including signed-out visitors. Only admins may write it: the policies use private.is_admin(). Signed out, the native app doesn't sync, so every flag has its default there.

Adding a flag

  1. Add it to flags with its default and payload fields.
  2. Add its title, its description and a label for each payload field under admin.flags.<key> in packages/i18n/translations/<locale>/app.json.
  3. Read it with useFlag where it matters.

Per-user targeting and percentages aren't part of this. Use an analytics or experimentation service for that.

On this page