Skip to content

feat(harmony): implement in-memory soft reload using devToolsController RELOAD - #588

Merged
sunnylqm merged 1 commit into
masterfrom
fix/harmony-rollback-reload
Jun 30, 2026
Merged

feat(harmony): implement in-memory soft reload using devToolsController RELOAD#588
sunnylqm merged 1 commit into
masterfrom
fix/harmony-rollback-reload

Conversation

@sunnylqm

@sunnylqm sunnylqm commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

This PR aligns the HarmonyOS reload behavior with iOS/Android by implementing an in-memory soft-reload mechanism:

Changes:

  • PushyFileJSBundleProvider: Modified to dynamically fetch the update bundle URL path on every query. This allows RNOH to load the newly selected update version when reloaded.
  • PushyTurboModule: Implemented reloadBridge() which emits the "RELOAD" event on RNOH's devToolsController for a seamless, in-memory refresh (no window blinking). Falls back to the hard restart of the Ability if DevTools is unavailable.
  • Updated reloadUpdate() and restartApp() to invoke reloadBridge().

Unit tests pass and HAR compiles successfully.

Summary by CodeRabbit

  • New Features

    • App reloads now prefer a faster hot-reload path when available, improving update responsiveness.
  • Bug Fixes

    • Bundle loading now uses the latest bundle location at runtime instead of a potentially stale cached value.
    • Reload and restart actions continue to fall back to the standard app restart flow if hot-reload isn’t available.

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Two independent refactors in the Harmony pushy module: PushyFileJSBundleProvider removes the cached path field and reads the bundle URL from UpdateContext on each call; PushyTurboModule adds a reloadBridge() method that prefers devtools-driven reload over restartAbility(), and both reloadUpdate() and restartApp() now delegate to it.

Changes

Bundle Path Caching Removal

Layer / File(s) Summary
Dynamic bundle URL resolution
harmony/pushy/src/main/ets/PushyFileJSBundleProvider.ets
Removes the private path field; getURL() returns updateContext.getBundleUrl() directly; getBundle() derives a local path from updateContext at call time instead of using the cached field.

Reload Bridge Introduction

Layer / File(s) Summary
reloadBridge() method and call-site updates
harmony/pushy/src/main/ets/PushyTurboModule.ts
Adds private reloadBridge() that emits a "RELOAD" devtools event when devToolsController exists, falling back to restartAbility(). reloadUpdate() and restartApp() now call reloadBridge() instead of restartAbility() directly.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 No more stale paths cached away,
Fresh from context, every day!
When devtools knock, we let them in,
Or restart—either way, we win.
Hop along, the bundle's bright! 🌟

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly reflects the main change: HarmonyOS in-memory soft reload via devToolsController RELOAD.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/harmony-rollback-reload

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

harmony/pushy/src/main/ets/PushyTurboModule.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

Error: .eslintrc.js » @react-native/eslint-config#overrides[4]:
Environment key "jest/globals" is unknown

at /node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2079:23
at Array.forEach (<anonymous>)
at ConfigValidator.validateEnvironment (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2073:34)
at ConfigValidator.validateConfigArray (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2223:18)
at CascadingConfigArrayFactory._finalizeConfigArray (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3985:23)
at CascadingConfigArrayFactory.getConfigArrayForFile (/node_modules/.pnpm/@eslint+eslintrc@2.1.4/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3791:21)
at FileEnumerator._iterateFilesWithFile (/node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/cli-engine/file-enumerator.js:368:43)
at FileEnumerator._iterateFiles (/node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/cli-engine/file-enumerator.js:349:25)
at FileEnumerator.iterateFiles (/node_modules/.pnpm/eslint@8.57.1/node_modules/eslint/lib/cli-engine/file-enumerator.js:299:59)
at iterateFiles.next (<anonymous>)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@harmony/pushy/src/main/ets/PushyTurboModule.ts`:
- Around line 68-75: The reloadBridge path currently assumes
devToolsController.eventEmitter.emit("RELOAD", ...) will always succeed, so
reloadUpdate() and restartApp() can fail instead of using the restartAbility
fallback. Update reloadBridge() to guard the RELOAD branch in PushyTurboModule
by checking that eventEmitter exists and wrapping the emit call in error
handling; if emit is unavailable or throws, fall back to restartAbility() just
like the else path. Keep the logic localized to reloadBridge() so callers like
reloadUpdate() and restartApp() continue to resolve through the fallback.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1338b90d-4945-4f9a-9186-f19ca1ef074a

📥 Commits

Reviewing files that changed from the base of the PR and between 2c864be and 1dd9a60.

📒 Files selected for processing (2)
  • harmony/pushy/src/main/ets/PushyFileJSBundleProvider.ets
  • harmony/pushy/src/main/ets/PushyTurboModule.ts

Comment on lines +68 to +75
private async reloadBridge(): Promise<void> {
const devToolsController = (this.ctx as Record<string, any>).devToolsController;
if (devToolsController) {
logger.debug(TAG, 'reloadBridge via devToolsController RELOAD');
devToolsController.eventEmitter.emit("RELOAD", { reason: 'HotReload2' });
} else {
logger.debug(TAG, 'reloadBridge via restartAbility');
await this.restartAbility();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '== devTools reload hook usages =='
rg -n -C2 --glob '*.ts' --glob '*.ets' '\bdevToolsController\b|\beventEmitter\b|\bRELOAD\b|\bHotReload2\b' .

echo
echo '== UITurboModuleContext / related declarations =='
rg -n -C2 --glob '*.d.ts' --glob '*.ts' --glob '*.ets' '\b(interface|type|class)\s+UITurboModuleContext\b' .

Repository: reactnativecn/react-native-update

Length of output: 1060


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '== PushyTurboModule relevant section =='
sed -n '1,220p' harmony/pushy/src/main/ets/PushyTurboModule.ts | cat -n

echo
echo '== Search for reloadBridge callers and restartAbility =='
rg -n -C3 'reloadBridge\(|restartAbility\(|reloadUpdate\(|restartApp\(' harmony/pushy/src/main/ets/PushyTurboModule.ts harmony/pushy/src/main/ets

echo
echo '== Search for devToolsController contract definitions/usages =='
rg -n -C3 --glob '*.ts' --glob '*.ets' --glob '*.d.ts' 'devToolsController|eventEmitter|RELOAD|HotReload2|UITurboModuleContext|TurboModuleContext' harmony .

Repository: reactnativecn/react-native-update

Length of output: 24960


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '== all devToolsController references =='
rg -n -C3 --glob '*.ts' --glob '*.ets' --glob '*.d.ts' 'devToolsController' .

echo
echo '== all TurboModule context type references =='
rg -n -C3 --glob '*.ts' --glob '*.ets' --glob '*.d.ts' 'TurboModuleContext|UITurboModuleContext|ctx:' harmony

echo
echo '== PushyTurboModule file excerpt =='
sed -n '1,180p' harmony/pushy/src/main/ets/PushyTurboModule.ts | cat -n

Repository: reactnativecn/react-native-update

Length of output: 10099


Guard the RELOAD path with the restart fallback. If eventEmitter is missing or emit('RELOAD', ...) throws, reloadUpdate() and restartApp() reject instead of falling back to restartAbility().

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@harmony/pushy/src/main/ets/PushyTurboModule.ts` around lines 68 - 75, The
reloadBridge path currently assumes
devToolsController.eventEmitter.emit("RELOAD", ...) will always succeed, so
reloadUpdate() and restartApp() can fail instead of using the restartAbility
fallback. Update reloadBridge() to guard the RELOAD branch in PushyTurboModule
by checking that eventEmitter exists and wrapping the emit call in error
handling; if emit is unavailable or throws, fall back to restartAbility() just
like the else path. Keep the logic localized to reloadBridge() so callers like
reloadUpdate() and restartApp() continue to resolve through the fallback.

@sunnylqm
sunnylqm merged commit 3b156c9 into master Jun 30, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant