Skip to content

Commit 1cab3c3

Browse files
robingenzclaude
andcommitted
refactor: the bridge speaks the cores' new names
Pins the cores at a1d9601 (Android) and deccdcc (iOS) and the protocol at 20053f1; the restart gate's key is isAllowed, the progress event carries progressBytes and downloadSizeBytes, and the README sample prints applyStrategy. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
1 parent ca6db83 commit 1cab3c3

9 files changed

Lines changed: 30 additions & 28 deletions

File tree

‎CLAUDE.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ This package keeps what is React Native's: which bundle the host loads, the relo
2727

2828
- **The host asks for its bundle.** React Native fixes the JavaScript it loads when its host is created, so the app hands that question to the SDK: `HotCodePush.bundleURL()` in `AppDelegate.swift`, `HotCodePushReactHost.getDefaultReactHost` in `MainApplication.kt`. Both are asked again on every reload.
2929
- **The core starts on that first question**, and the host waits for it: the start's verdict — the pending switch, the rollback of a release that never became ready — is in before any JavaScript runs, so a start never loads one bundle and reloads into another. The wait is the core's two seconds: past it the host serves the embedded bundle and the core reloads it into the right one once the start answers. A host that is not in the foreground at that question starts headless, so no release is applied and no gate armed. A reload the SDK did not ask for serves the running bundle, and the core is not told: a waiting release applies at the next start or through `applyUpdate()`.
30-
- **A host that never asked** runs JavaScript the SDK does not serve — Metro in a debug build, or an app that is not wired. The core then runs with `enabledInDebugBuilds` off, and every result is `SKIPPED` with `BUILD_DEBUG`; a debug build's resource file, which the build step writes without an embedded bundle, says the same on its own.
30+
- **A host that never asked** runs JavaScript the SDK does not serve — Metro in a debug build, or an app that is not wired. The core then runs with `isEnabledInDebugBuilds` off, and every result is `SKIPPED` with `BUILD_DEBUG`; a debug build's resource file, which the build step writes without an embedded bundle, says the same on its own.
3131
- **A switch is a reload of the host**, `RCTTriggerReloadCommandListeners` and `ReactHost.reload`: the JavaScript restarts, the process stays. The cores hold every reload but a rollback until the app is up in the run, the app's own `applyUpdate()` and `clearUpdates()` included: a reload while React Native starts an instance crashes the app on iOS. The app is up once it has rendered, called `notifyReady()` or run into the readiness timeout. This package holds no reload back: the loader persists the core's choice and reloads a host that has asked for its bundle. What the cores need from it is the first render, reported on every start and after every reload, whatever `readySignal` is: `HotCodePushRuntime` calls the core's `handleRendered()` in `handleContentDidAppear` on iOS and on Android in the `FirstRenderListener` that `observeFirstRender` registers for every JavaScript instance `HotCodePushReactHost` reports.
3232
- **Readiness is the first frame after the root view renders**, observed natively: `RCTContentDidAppearNotification` on iOS, the first frame of each JavaScript instance at which a React root holds a view on Android, checked at every frame React Native dispatches its mounting work, since the first mount can come before React Native reports the instance and a mount made before the root view is attached runs at the attach, which no mount listener hears, since React Native logs its content-appeared marker once per surface and not again after a reload, and mounts the root itself before any render. A bundle that mounts nothing never becomes ready.
3333
- **A bundle is laid out as React Native's own build lays it out**: `main.jsbundle` with `assets/` on iOS, `index.android.bundle` with its `drawable-*` directories on Android, under the store's `served/<bundleId>`.

‎README.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ import { HotCodePush, useUpdates } from '@hotcodepush/react-native-code-push';
6767

6868
const result = await HotCodePush.sync();
6969
if (result.status === 'DOWNLOADED') {
70-
console.log(`release #${result.release.number} applies at ${result.applyAt}`);
70+
console.log(
71+
`release #${result.release.number} applies at ${result.applyStrategy}`,
72+
);
7173
}
7274

7375
function ReleaseLabel() {

‎android/build.gradle‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ repositories {
4444

4545
dependencies {
4646
implementation 'com.facebook.react:react-android'
47-
implementation 'com.hotcodepush:core-android:1e5575a598be4551fbe10bd575c481721371d8fe'
47+
implementation 'com.hotcodepush:core-android:a1d960187849220113ef530f1caa9a869df29919'
4848
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.10.2'
4949
testImplementation 'junit:junit:4.13.2'
5050
testImplementation 'org.mockito:mockito-core:5.20.0'

‎android/src/main/java/com/hotcodepush/reactnative/HotCodePushModule.kt‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,13 @@ class HotCodePushModule(reactContext: ReactApplicationContext) : NativeHotCodePu
9393
}
9494

9595
override fun setRestartAllowed(options: ReadableMap, promise: Promise) {
96-
if (!options.hasKey("allowed") || options.getType("allowed") != ReadableType.Boolean) {
97-
promise.reject(REJECTION_CODE, "allowed must be a boolean")
96+
if (!options.hasKey("isAllowed") || options.getType("isAllowed") != ReadableType.Boolean) {
97+
promise.reject(REJECTION_CODE, "isAllowed must be a boolean")
9898
return
9999
}
100-
val allowed = options.getBoolean("allowed")
100+
val isAllowed = options.getBoolean("isAllowed")
101101
runtime.invoke(promise) {
102-
it.setRestartAllowed(allowed)
102+
it.setRestartAllowed(isAllowed)
103103
null
104104
}
105105
}

‎android/src/main/java/com/hotcodepush/reactnative/HotCodePushRuntime.kt‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class HotCodePushRuntime internal constructor(private val context: Context) : Co
172172
return null
173173
}
174174
if (!isServedBySdk) Log.w(TAG, NOT_SERVED_MESSAGE)
175-
val configuration = if (isServedBySdk) readConfiguration else readConfiguration.copy(enabledInDebugBuilds = false)
175+
val configuration = if (isServedBySdk) readConfiguration else readConfiguration.copy(isEnabledInDebugBuilds = false)
176176
val core = Core(
177177
configuration = configuration,
178178
device = deviceFacts(context, isServedBySdk),
@@ -222,11 +222,11 @@ class HotCodePushRuntime internal constructor(private val context: Context) : Co
222222
eventSink?.emitEvent("updateFailed", event.toJson())
223223
}
224224

225-
override fun downloadProgress(releaseId: String, downloadedBytes: Long, totalBytes: Long) {
226-
val progress = if (totalBytes > 0) downloadedBytes.toDouble() / totalBytes else 0.0
225+
override fun downloadProgress(releaseId: String, progressBytes: Long, downloadSizeBytes: Long) {
226+
val progress = if (downloadSizeBytes > 0) progressBytes.toDouble() / downloadSizeBytes else 0.0
227227
eventSink?.emitEvent(
228228
"downloadProgress",
229-
JSONObject().put("releaseId", releaseId).put("downloadedBytes", downloadedBytes).put("totalBytes", totalBytes).put("progress", progress),
229+
JSONObject().put("downloadSizeBytes", downloadSizeBytes).put("progress", progress).put("progressBytes", progressBytes).put("releaseId", releaseId),
230230
)
231231
}
232232

@@ -260,7 +260,7 @@ class HotCodePushRuntime internal constructor(private val context: Context) : Co
260260
return Configuration.decode(text)
261261
}
262262

263-
/** A run whose JavaScript the SDK does not serve counts as a debug build, which `enabledInDebugBuilds` then switches off. */
263+
/** A run whose JavaScript the SDK does not serve counts as a debug build, which `isEnabledInDebugBuilds` then switches off. */
264264
private fun deviceFacts(context: Context, isServedBySdk: Boolean): DeviceFacts {
265265
val info = context.packageManager.getPackageInfo(context.packageName, 0)
266266
val versionCode = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) info.longVersionCode else @Suppress("DEPRECATION") info.versionCode.toLong()

‎ios/HotCodePushRuntime.swift‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ import UIKit
123123
return nil
124124
}
125125
if !isServedBySdk {
126-
configuration.enabledInDebugBuilds = false
126+
configuration.isEnabledInDebugBuilds = false
127127
NSLog("[HotCodePush] %@", HotCodePushRuntime.notServedMessage)
128128
}
129129
let events = CoreEvents(runtime: self)
@@ -194,8 +194,8 @@ import UIKit
194194
case .setChannel:
195195
try await core.setChannel(HotCodePushRuntime.channelChoice(from: options))
196196
case .setRestartAllowed:
197-
guard let allowed = options["allowed"] as? Bool else { throw PlainError("allowed must be a boolean") }
198-
await core.setRestartAllowed(allowed)
197+
guard let isAllowed = options["isAllowed"] as? Bool else { throw PlainError("isAllowed must be a boolean") }
198+
await core.setRestartAllowed(isAllowed)
199199
case .showDebugScreen:
200200
await HotCodePushRuntime.presentDebugScreen(core: core)
201201
case .sync:
@@ -262,9 +262,9 @@ import UIKit
262262
eventSink?.emitEvent(eventName, payload: payload)
263263
}
264264

265-
fileprivate func emitDownloadProgress(releaseId: String, downloadedBytes: Int, totalBytes: Int) {
266-
let progress = totalBytes > 0 ? Double(downloadedBytes) / Double(totalBytes) : 0
267-
eventSink?.emitEvent("downloadProgress", payload: ["releaseId": releaseId, "downloadedBytes": downloadedBytes, "totalBytes": totalBytes, "progress": progress])
265+
fileprivate func emitDownloadProgress(releaseId: String, progressBytes: Int, downloadSizeBytes: Int) {
266+
let progress = downloadSizeBytes > 0 ? Double(progressBytes) / Double(downloadSizeBytes) : 0
267+
eventSink?.emitEvent("downloadProgress", payload: ["downloadSizeBytes": downloadSizeBytes, "progress": progress, "progressBytes": progressBytes, "releaseId": releaseId])
268268
}
269269

270270
/// Kept until the JavaScript of the start that follows the rollback listens: the instance that saw the rollback is gone by then.
@@ -312,7 +312,7 @@ import UIKit
312312
}
313313
}
314314

315-
/// A run whose JavaScript the SDK does not serve counts as a debug build, which `enabledInDebugBuilds` then switches off.
315+
/// A run whose JavaScript the SDK does not serve counts as a debug build, which `isEnabledInDebugBuilds` then switches off.
316316
private static func deviceFacts(isServedBySdk: Bool) -> DeviceFacts {
317317
let info = Bundle.main.infoDictionary ?? [:]
318318
#if DEBUG
@@ -355,8 +355,8 @@ private final class CoreEvents: CoreListener {
355355
runtime?.emit("updateFailed", event)
356356
}
357357

358-
func downloadProgress(releaseId: String, downloadedBytes: Int, totalBytes: Int) {
359-
runtime?.emitDownloadProgress(releaseId: releaseId, downloadedBytes: downloadedBytes, totalBytes: totalBytes)
358+
func downloadProgress(releaseId: String, progressBytes: Int, downloadSizeBytes: Int) {
359+
runtime?.emitDownloadProgress(releaseId: releaseId, progressBytes: progressBytes, downloadSizeBytes: downloadSizeBytes)
360360
}
361361

362362
func updateRolledBack(_ event: UpdateRolledBackEvent) {

‎package-lock.json‎

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@
6262
}
6363
},
6464
"hotcodepush": {
65-
"coreIos": "e6fbe041b7a780730cb5aadc40cce778264cf57e"
65+
"coreIos": "deccdcc294bbc2ab6f678b0ecf242f84fba71a15"
6666
},
6767
"dependencies": {
68-
"@hotcodepush/protocol": "https://pkg.pr.new/hotcodepush-team/protocol/@hotcodepush/protocol@cf04f51425c17de9f1f65d4649b2e7df8eb1dac1"
68+
"@hotcodepush/protocol": "https://pkg.pr.new/hotcodepush-team/protocol/@hotcodepush/protocol@20053f1"
6969
},
7070
"devDependencies": {
7171
"@eslint/js": "10.0.1",

‎src/hot-code-push.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ vi.mock('./NativeHotCodePush', () => ({
1515
}));
1616

1717
const UPDATE_ROLLED_BACK_EVENT: UpdateRolledBackEvent = {
18-
from: {
18+
fromRelease: {
1919
bundleId: '0f8fad5b-d9cb-469f-a165-70867728950e',
2020
bundleVersion: '1.4.2',
2121
id: '7c9e6679-7425-40de-944b-e07fc1f90ae7',
2222
isMandatory: false,
2323
number: 43,
2424
},
2525
reason: 'READINESS_TIMED_OUT',
26-
to: null,
26+
toRelease: null,
2727
};
2828

2929
describe('HotCodePush', () => {

0 commit comments

Comments
 (0)