React Native OTA Updates
React Native OTA updates let an installed app load newer Metro Module Federation remote bundles, environment values, and remote selections without releasing a new binary through the App Store or Play Store. Zephyr supports this flow with two packages:
zephyr-metro-pluginpublishes Metro Module Federation bundles to Zephyr Cloud, resolves remote manifests foriosandandroidbuilds, rewritesZE_PUBLIC_*reads into runtime lookups, and injects the runtime plugin that applies each environment's values and remote overrides on the device.zephyr-native-cacheruns in the host app, verifies remote bundle hashes, stores valid bundles on device, polls remote manifests for changes, exposes APIs to apply downloaded updates, and stores the last environment manifests for offline starts.
OTA updates only update JavaScript bundles loaded through Metro Module Federation. Native code changes, new native modules, native dependency linking changes, permission changes, and host-shell changes still require a normal app-store release.
For a complete working reference, see the zephyr-native-cache-test example. The example includes a host app, two remotes, local OTA fixtures, Zephyr-backed OTA scripts, update prompts, cache status UI, and rollback coverage. To control every installed app from one environment, see the Native Shell + Host architecture.
What Changes Without A Store Release
How It Works
- You run a Zephyr-wrapped React Native CLI or RNEF
bundle-mf-remotecommand for each platform. - The command uploads the Metro Module Federation artifacts, and Zephyr Cloud creates an immutable version with platform-specific artifacts, an
mf-manifest.json, and azephyr-manifest.json. - Your released host app resolves the remote through a Zephyr dependency such as
zephyr:profile@production-${target}, which becomesproduction-iosorproduction-androidfor the platform being built. - When the host resolves the remote at runtime, the Zephyr runtime plugin loads the environment's
zephyr-manifest.jsonand applies itsZE_PUBLIC_*values and remote overrides before the remote's code runs. zephyr-native-cachereads bundle hashes from themf-manifest.jsonthrough its Module Federation runtime plugin.- When a remote is loaded, the cache layer downloads the bundle natively, verifies its SHA-256 hash, caches it on device, and evaluates it.
- Background polling or a manual update check fetches known manifests again. If hashes changed, the cache layer pre-downloads the new bundles.
- Your app decides when to apply the update by reloading the React Native JavaScript context.
Rollbacks use the same mechanism. If you roll back a Zephyr environment or move a tag back to an older remote version, manifest polling sees the older bundle hash as the active target, downloads it, and the host can apply it on the next reload.
withZephyr() configures remote resolution; it does not publish an OTA version. See Metro configuration and publication for the upload boundary, Git identity inference, and explicit zephyr.config.ts overrides.
Install Packages
Install the Metro and Module Federation packages in every host and remote app. Environment values and runtimeManifest need version 1.8.0 or newer:
Install the native cache package in the host app:
zephyr-native-cache contains a native module, so rebuild and reinstall the app after adding it. An app that is already installed cannot gain the module through an OTA update. For iOS, run CocoaPods first:
Use One Environment Per Platform
A Zephyr environment serves a single version, and each Metro version is built for one platform. If iOS and Android builds share one production environment, the platform published last replaces the other, and installed apps on the other platform load a bundle built for the wrong platform.
Create one environment per platform on every app that installed devices load, for example production-ios and production-android, and select them with the ${target} placeholder. Zephyr replaces ${target} with the platform being bundled. See Per-platform selectors.
Configure The Host
Add the native cache runtime plugin to the host's Module Federation config. The plugin extracts bundle hashes from remote manifests and registers the manifest URLs that polling will check later. Keep a local manifest URL in remotes for development:
Declare where Zephyr builds load the remote from, under the same key:
start keeps loading the remote from localhost. When bundle-mf-host or bundle-mf-remote runs, Zephyr resolves the selector for the bundled platform and replaces the profile entry in remotes with that environment's mf-manifest.json URL. The dependency also makes the relationship visible in the dashboard. You can declare it as remoteDependencies in zephyr.config.* instead.
Use environment or tag selectors such as @production-${target} or @staging-${target} for builds that should receive OTA changes. The default selector URL mode embeds the environment or tag URL, so the installed host follows whatever that label serves. With dependencyUrlMode: 'version', the host embeds immutable version URLs; a newer remote then needs a new host build or a remote override delivered through runtimeManifest.
For more dependency selector options, see Remote Dependencies.
Register The Cache At Startup
Register the native cache before any remote bundle can load. In a Metro Module Federation host, this usually means registering it in index.js before AppRegistry.registerComponent.
register() returns the cache layer. Calling it again returns the same instance without applying the new options.
Production builds enable the cache automatically. Development builds keep the cache disabled by default so normal Metro development behavior is preserved. Set forceCacheInDev: true only when you intentionally want to debug OTA behavior against Metro dev servers.
Registration also gives the Zephyr runtime plugin a file-backed store for environment manifests, whether or not the bundle cache is enabled. Without it, environment values and remote overrides still apply while the device is online, but offline starts fall back to build-time values, and runtimeManifest has no effect.
Configure Remote Builds
RNEF projects must use the Zephyr RNEF plugin so rnef bundle-mf-remote and rnef bundle-mf-host upload Metro artifacts to Zephyr after the Module Federation build completes. React Native CLI projects must register the equivalent Zephyr-wrapped commands described in the Metro bundler guide.
Then publish a remote for each platform you support. ZE_ENV labels each build with its platform's environment; see Deploying to Specific Environments:
Running start or a debug run-ios / run-android build is not publication. After the first bundle-mf-remote upload completes, verify in the Zephyr dashboard that the remote application exists and has a version before configuring an OTA environment or tag.
The host must resolve the same platform that the remote was published for. The publication commands resolve remotes for their --platform, and withZephyr({ target }) should match it.
Build The Host Binary
The host's own bundle ships inside the binary, so the release build's native bundle step must run the Zephyr bundle-mf-host command. Otherwise the binary keeps the local URLs from remotes. See Release builds for the Android and Xcode settings.
Environment Values And Remote Overrides
The publication commands inject a Zephyr runtime plugin into apps that consume Zephyr-resolved remotes. It applies environment-level overrides on the device.
ZE_PUBLIC_* Values
withZephyr() rewrites process.env.ZE_PUBLIC_* and import.meta.env.ZE_PUBLIC_* reads in each app's own sources into lookups scoped by that app's application UID, with the build-time value as the fallback. Read them as usual:
Before a remote's code runs, the runtime plugin fetches the zephyr-manifest.json next to the remote's entry and applies that environment's values to that remote only. Setting ZE_PUBLIC_API_URL on the profile environment does not change the host's value.
Remote Overrides
A remote override set on a remote's environment changes which deployment that remote loads for its own remotes. When the host loads profile from production-ios, the runtime plugin points profile's requests for its remotes at the entries that environment's zephyr-manifest.json lists. Nested remotes follow the environment their parent was loaded from.
Overrides repoint remotes the app already declares. They cannot add a remote that the build did not include.
Offline Starts
The runtime plugin gives each manifest request three seconds. If the request fails or times out, it uses the copy stored by the last successful load. Without a stored copy, the app keeps the build-time values.
Follow An Environment From The Binary
The app inside the binary is not loaded from an environment URL, so overrides set on its own environment do not reach it by default. Set runtimeManifest to make it follow a tag or environment:
@label selects the app's own tag or environment, and app@label another app's. Write the selector in plain quotes, not a template literal. You can also pass runtimeManifest to withZephyr(), which wins over the config file.
At runtime:
- The first remote request applies the
zephyr-manifest.jsonstored by the previous launch: its remote overrides for the app's remotes and itsZE_PUBLIC_*values. - The plugin then fetches a fresh copy in the background and stores it for the next launch. Remotes never change in the middle of a session.
- A change made in the dashboard applies on the second launch after it, or on
ZephyrNativeCache.reloadApp()once a launch has fetched and stored it. A reload before that background refresh finishes still applies the previous copy.
Until a launch has stored a copy, as on the first launch after installing, the app keeps its build-time remotes and values. Apps without zephyr-native-cache registered always keep them. The stored copy lives in the app's documents (iOS) or files (Android) directory, so it survives app updates that keep the same runtimeManifest label. Native cache polling does not watch this manifest; the launch-time refresh does.
The publication commands resolve the label's alias URL, never a version URL, and fail when the label has no version for the bundled platform. Publish the app to that environment once before you add runtimeManifest. With dependencyUrlMode: 'version', the manifest lists pinned version URLs, so only remote overrides change the loaded remotes.
Apply Updates In The App
The cache never replaces modules that are already running. Downloaded bundles take effect when the app reloads its JavaScript or starts again, and your app decides when that happens:
- Next launch: keep the default
downloadOnlypolling. Users get the update the next time they open the app. - Prompt: show a banner or a settings control, and call
ZephyrNativeCache.reloadApp()when the user accepts. - Immediate: call
checkForUpdates({ policy: 'downloadAndApply' })where a reload is acceptable.
reloadApp() reloads the React Native JavaScript context without terminating the native app. The cache does not force any of these; it provides state and controls for each.
Use useCacheStatus to drive an update prompt:
Use manual checks when you want a pull-to-refresh, settings, or internal QA flow:
Use downloadAndApply only when an immediate JavaScript reload is acceptable:
downloadAndApply reloads only when that check downloads at least one changed bundle. If background polling already downloaded the update, the check finds nothing new and does not reload; call reloadApp() instead. Persist any critical UI state before either reload.
checkForUpdates() resolves to { checked, updated, applied }. It returns zeros when the native module is unavailable or another check is already running.
Automatic polling always uses downloadOnly. It checks only the manifests of remotes the app has resolved since it started, not every remote your project publishes.
To observe individual cache events, subscribe on the instance that register() returns:
The events are bundle:load, poll:start, update:available, update:downloaded, and poll:complete.
Runtime Behavior
When a remote bundle loads, the cache layer returns one of these statuses:
The cache skips safely when a bundle has no manifest hash, a hash verification fails, a native file operation fails, or the native module is unavailable. Hash mismatches are not cached.
The hash check decides what the cache stores and serves from disk. It is not a signature check: when the cache skips a bundle, the normal network loader evaluates it without comparing hashes.
register() accepts these options:
The cache evicts stale bundles with an LRU policy on cold start. Fresh bundles are preserved even if the cache is temporarily over the size limit.
Deploy And Roll Back
To deploy an OTA update:
- Publish a new remote version for
iosandandroid, each to its platform's environment. - Point the environment that the host depends on at the new version, for each platform. A version-based environment changes when you deploy a version to it. A tag-based environment follows its tag and advances on its own when a newer version matches the tag's conditions, such as a build published with
ZE_ENV. See Environment Configuration. - Wait for polling or call
ZephyrNativeCache.checkForUpdates(). - Prompt the user or call
ZephyrNativeCache.reloadApp()when your app is ready to apply the downloaded update.
To roll back, use the Zephyr dashboard to roll the remote environment back or move the tag back to a previous version. The next update check downloads the rolled-back bundle and applies it through the same reload flow. A rollback does not replace JavaScript that is already running on a device.
New versions and rollbacks reach installed hosts only through environment or tag URLs. With dependencyUrlMode: 'version', a host keeps loading the version it was built against.
ZE_PUBLIC_* values and remote overrides do not need a new version. Edit them on the environment in the dashboard; they apply as described in What Changes Without A Store Release.
Example Repository
Use zephyr-native-cache-test as the implementation reference for bundle caching, polling, update prompts, and rollback. Start with these files:
apps/host/index.jsfor cache registration.apps/host/metro.config.jsfor host runtime plugin wiring.apps/host/rnef.config.mjsfor RNEF command integration.apps/host/src/components/DevToolsPanel.tsxfor polling status and manual controls.ZEPHYR_OTA_DEMO.mdfor the Zephyr-backed OTA dashboard walkthrough.