iosobjective-creact-nativecode-splittingmetro-bundler

Loading multiple JS bundles in React Native iOS


I'm trying to implement Code Splitting in a React Native app. Currently I managed to load multiple bundles in Android both in packager mode and in production mode.

However, on iOS I'm facing the following issue: Cannot initialize hmrClient twice. I'm trying to load the additional bundles using [bridge.batchedBridge executeSourceCode] which works in production mode but throws when using the packager.

When looking at the implementation of executeSourceCode I see that it indeed calls setupHMRClientWithBundleURL without checking if it was already initialized.

Is there any way to overcome this issue?


Solution

  • So it seems that metro does things a bit differently in dev vs prod and I didn't account for that.

    Bundling JS with --dev true works. In order to avoid the hmrClient error it's better to use [bridge.batchedBridge executeApplicationScript] rather than executeSourceCode.