Repository navigation
useCodePush(): download, install and pending-restart state - #112
Merged
Merged
Conversation
ofalvai
force-pushed
the
use-code-push-download-state
branch
from
November 10, 2026 13:39
f6345c1 to
54f075c
Compare
ofalvai
marked this pull request as ready for review
November 10, 2026 13:40
gsanta
approved these changes
Nov 11, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ofalvai
force-pushed
the
use-code-push-download-state
branch
from
November 11, 2026 09:58
54f075c to
b6c7641
Compare
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the hook-state and download-progress changes.
No open issues 🎉
What changed in this PR
Extends CodePush’s React hooks to expose download activity, installation errors, and updates awaiting restart, regardless of which API initiated the work.
Changes:
- Adds
isDownloading,installError, andpendingUpdatetouseCodePush(). - Introduces
useDownloadProgress()with a separate snapshot so progress events do not re-render consumers of onlyuseCodePush(). - Connects shared download and install operations to the store, with unit tests and API documentation.
| File | Description |
|---|---|
typings/react-native-code-push.d.ts |
Declares new state fields and the progress hook. |
src/update-state/update-store.ts |
Exposes progress separately from the main snapshot. |
src/update-state/update-state.ts |
Tracks downloads, installation failures, and pending updates. |
src/update-state/track-update.ts |
Reports download and install outcomes to the store. |
src/update-state/__tests__/update-store.test.ts |
Tests progress notifications and snapshot stability. |
src/update-state/__tests__/update-state.test.ts |
Tests new state transitions and overlapping downloads. |
src/update-state/__tests__/track-update.test.ts |
Tests operation tracking and error propagation. |
src/react/use-download-progress.ts |
Implements the dedicated progress hook. |
src/react/store-context.ts |
Makes the progress getter available through context. |
src/package-metadata.ts |
Copies package metadata without function properties. |
src/__tests__/package-metadata.test.ts |
Tests metadata filtering without mutating the package. |
docs/api-js.md |
Documents new state fields and progress behavior. |
CodePush.js |
Integrates tracking, enables progress events, and exports the hook. |
Review effort: Balanced
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Additional improvements to
useCodePush(). Two gaps came up that the hook's state could not answer:sync()installs withON_NEXT_RESTART, the update stops being available and nothing in the state says it is installed.checkErroronly covers the server query. A failed download left the state at "update available" with no error. The Provider'sonErroronly sees the syncs the Provider starts, and a component'ssync()only rejects its own promise. There was also no download progress, because the hook'ssynctakes no callbacks.What changes
New state in
useCodePush():isDownloadinginstallError, set when the download or the install of an update fails, and cleared by the next download or a successful installpendingUpdate, set by every install, until the restart starts a new JS contextNew hook
useDownloadProgress()returns{ receivedBytes, totalBytes }orundefined.All of this is reported from the shared download and install functions in
CodePush.js, so it covers the Provider, the hook'ssync, legacycodePush.sync(), the HOC, and manualRemotePackage.download()/LocalPackage.install(). It doesn't matter who started the work.Decisions
useCodePush()caller would re-render at that rate during a download, including a component that only readscheckError. Progress lives in the same store but outside the snapshot, anduseSyncExternalStorere-renders only the components that read it.downloadUpdate()used to ask native for progress only when a callback was passed. Now it always subscribes. Follow-up optimization: Throttle iOS download progress events by time #113installErrorfollowscheckError's rule: a new attempt clears it. A new check does not, so a background check doesn't hide a failure the user hasn't seen yet.🤖 Generated with Claude Code