Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ios): Update bundleUrl Before Reload for Custom RCTBridges #119

Merged
merged 1 commit into from
Feb 19, 2025

Conversation

wes4m
Copy link
Contributor

@wes4m wes4m commented Feb 18, 2025

Issue

We have a brownfield app, meaning it originally started as a native app, and React Native was integrated later. As a result:

  • The entry point is not React Native.
  • We manually create the RCTBridge.
  • Our AppDelegate does not conform to RCTAppDelegate.

During a forced OTA update (when reload = true), hot-updater triggers RCTTriggerReloadCommandListeners this leads to the following issue:

  • RCTTriggerReloadCommandListeners reaches the registered bridge, which still points to the old bundle URL.
  • App reloads the last set bundleUrl on that bridge, which is not the new one.
  • The old bundle is loaded again triggering an update check and another reload.
  • This creates an infinite reload loop, despite the new bundle being downloaded correctly.
    Note that If reload is not triggered, the new bundle loads correctly on the second run without any issues which makes sense.

This scenario is handled by CodePush by updating the super bridge's bundle URL before triggering the reload. This PR does the same thing.

I believe this change should have no impact on other typical React Native setups.

@gronxb gronxb changed the title fix: Update bundleUrl Before Reload for Custom RCTBridges fix(ios): Update bundleUrl Before Reload for Custom RCTBridges Feb 19, 2025
@gronxb
Copy link
Owner

gronxb commented Feb 19, 2025

Thanks your contribution.

If the bundle URL is set during a reload, what happens in cases where it’s not a forced update? Since reload is not triggered when it’s not a forced update, the system applies the update when the app is restarted. Will it still work correctly in that case?

@wes4m
Copy link
Contributor Author

wes4m commented Feb 19, 2025

Thanks your contribution.

If the bundle URL is set during a reload, what happens in cases where it’s not a forced update? Since reload is not triggered when it’s not a forced update, the system applies the update when the app is restarted. Will it still work correctly in that case?

Yes when it's a regular update there are no issues, as the RCTBridge will be initialized again on app start using HotUpdater.bundleURL() which will always return the updated bundle url.

Copy link
Owner

@gronxb gronxb left a comment

Choose a reason for hiding this comment

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

Thanks !!

@gronxb gronxb merged commit 0860106 into gronxb:main Feb 19, 2025
3 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.

2 participants