React Native API
updateBundle
Stage an update transition for the next React Native runtime without reloading the current one.
Usage
Use updateBundle to stage an available update transition, downloading and
verifying a bundle when needed. Use the transition information returned by
checkForUpdate. The function does not reload the React Native runtime
currently in use.
import { HotUpdater } from "@hot-updater/react-native";
async function stageAppUpdate() {
try {
const updateInfo = await HotUpdater.checkForUpdate({
updateStrategy: "appVersion", // or "fingerprint"
requestHeaders: {
Authorization: "Bearer <your-access-token>",
},
});
if (!updateInfo) {
return {
status: "UP_TO_DATE",
};
}
/**
* You can stage updates using one of two methods:
*
* Method 1: (RECOMMENDED) Use the updateBundle() method from the updateInfo object
* - A convenience method built into the return value from checkForUpdate
* - Automatically includes fileHash for secure verification
* - All required arguments are pre-filled from the checkForUpdate response
*/
const didUpdate = await updateInfo.updateBundle();
/**
* Method 2: Call HotUpdater.updateBundle() directly
* - Explicitly pass the necessary values extracted from updateInfo
* - You must manually include fileHash for security
*/
// const didUpdate = await HotUpdater.updateBundle({
// bundleId: updateInfo.id,
// fileUrl: updateInfo.fileUrl,
// fileHash: updateInfo.fileHash,
// status: updateInfo.status,
// });
if (!didUpdate) {
console.warn("Update transition was not staged");
return;
}
console.log("Bundle transition staged successfully");
if (updateInfo.shouldForceUpdate) {
await HotUpdater.reload();
}
} catch (error) {
console.error("Failed to stage update:", error);
}
}Parameters
The object form of HotUpdater.updateBundle() accepts the following required parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
bundleId | string | ✅ | Unique identifier of the update bundle. |
fileUrl | string | null | ✅ | Bundle archive URL, or null for a rollback without an archive. |
fileHash | string | null | ✅ | SHA-256 hash or sig:<base64_signature> verification value; null when verification is not provided. |
status | "ROLLBACK" | "UPDATE" | ✅ | Operation represented by the update. |
Behavior
- Downloads the specified bundle when
fileUrlis notnull. - If
fileHashcontains a SHA-256 hash, verifies the downloaded file before extraction. - If
fileHashstarts withsig:, verifies the bundle signature. - If
fileHashisnull, proceeds without archive verification. - Stages the selected bundle for the next React Native runtime start without replacing the code already running.
- Never reloads the app by itself. Call
HotUpdater.reload()explicitly to start the staged bundle immediately; the automaticHotUpdater.wrapflow handles force updates separately. - An in-progress download is not guaranteed to finish after the app is force-quit.
Security Recommendation
Always preserve a non-null fileHash returned by checkForUpdate(). Native verification rejects corrupted archives and bundles that fail signature verification.
Recommended Approach
Use updateInfo.updateBundle() instead of HotUpdater.updateBundle() whenever possible. It passes the required values from the corresponding update check automatically.
// Recommended: required values are automatically included.
const updateInfo = await HotUpdater.checkForUpdate({
updateStrategy: "appVersion",
});
if (updateInfo) {
await updateInfo.updateBundle();
}