DEV Community

江欢(JackSoul)
江欢(JackSoul)

Posted on Originally published at keston.dev

One codebase, three platforms: the parts that actually break

Cross-platform gets sold on the shared 80% of the code. The 80% is real. The problem is
that the remaining 20% is where every support ticket lives, and it is different on each
platform — so it is not 20% of the work, it is 60% of the debugging.

These are the four things that have cost me the most time across mobile and desktop
builds of the same product.

1. The file system is not the file system

On the web, "save a file" is a download. On mobile it is a sandboxed directory the user
cannot see. On desktop it is a path with permissions, a default location, and an
expectation that the app remembers it.

// the abstraction that survives all three
async function saveDocument(bytes, suggestedName) {
  if (isDesktop) {
    const path = await pickSavePath(suggestedName); // native dialog
    return writeAtPath(path, bytes);
  }
  if (isMobile) {
    return writeToAppDocuments(suggestedName, bytes); // sandbox + share sheet
  }
  return triggerBrowserDownload(suggestedName, bytes);
}
Enter fullscreen mode Exit fullscreen mode

The user-visible behaviour has to be designed per platform, not abstracted away. A
"share sheet" on mobile is the correct affordance; a modal that says "saved to
Downloads" is not.

2. Background time is a budget, not a guarantee

Mobile OSes suspend background work aggressively, and the rules differ: iOS gives you
roughly thirty seconds after backgrounding, Android has doze windows, desktop has none
of this. Any sync logic that assumes "it will finish eventually" will lose data.

The pattern that holds: treat every sync as resumable and idempotent, keyed by a client
generated id. If the process dies halfway, the next launch replays the queue and the
server deduplicates. That is the same idempotency key discipline you would use for
payments, and it is not optional once a background task can be killed.

3. Deep links and cold start order

A notification arrives, the user taps it, the OS launches the app, and your routing
layer has to reach a screen that depends on data that has not loaded yet. On the web you
can ignore this because the page reloads. In a shipped app it is the most common
"sometimes it opens the wrong screen" bug.

The fix is a small state machine: buffer the intended route, let the session and the
first data fetch settle, then navigate. Never navigate from the deep-link handler
directly.

pendingRoute = parseDeepLink(url);
await sessionReady;
await firstSyncDone;
if (pendingRoute) { router.replace(pendingRoute); pendingRoute = null; }
Enter fullscreen mode Exit fullscreen mode

4. Updates are a release process, not a deploy

Web: push and everyone is current. Mobile: store review, staged rollout, and a
meaningful share of users on an old version for weeks. Desktop: auto-update, which means
you own the failure mode where an update half-applies.

Design consequences that are easy to forget until it hurts:

  • The API must tolerate three client versions at once, which means additive changes only for anything a shipped client calls.
  • A kill switch per feature beats a forced update, because a forced update is a store-review dependency in the middle of an incident.
  • Version the local database schema and write the migration before the feature, not after the first field rename.

When cross-platform is the wrong answer

If the product is one flow that depends on a native capability — camera pipelines,
background location, Bluetooth, heavy graphics — a shared codebase is a tax you pay on
every release for a saving you already spent. The honest test: list the three core
flows and count how many need a native API. Two or more, and the shared layer becomes
plumbing around three separate implementations.

For everything else, one codebase with per-platform adapters at the four boundaries
above is the cheapest thing that actually works, and it keeps a single team able to ship.

The longer version, with the adapter interfaces and the release checklist I use for
client builds, is at
keston.dev.

Top comments (0)