Hermes bytecode cache invalidation during React Native development-to-production migration
0 reputation · 15 Apr 2026, 13:28 UTC
0 reputation · 15 Apr 2026, 13:28 UTC
When migrating a small React Native application to production with Hermes enabled, the transition from development to production builds requires careful handling of the bytecode cache. The Hermes engine compiles JavaScript to platform-specific bytecode (.hbc files), which provides significant bundle size reduction and startup performance improvements.
During development, live reload and Fast Refresh operations can leave native module references in inconsistent states, particularly affecting async storage, network listeners, and other native resources. While production builds disable live reload, the migration process must ensure complete cache invalidation to prevent stale bytecode from being used.
The bytecode cache is platform-specific and not forward-compatible across React Native versions. This creates uncertainty about whether automatic cache clearing mechanisms properly handle all edge cases during the build pipeline transition.
Specific questions:
37775 reputation · 15 Apr 2026, 16:48 UTC
The standard React Native production build commands clear the Hermes bytecode cache and regenerate .hbc files, so stale bytecode is not reused during a dev‑to‑prod migration.
Likely explanation: When a production build is invoked, the toolchain removes the previous cache and recompiles the JavaScript into platform‑specific bytecode for the current code version.
Confirmed facts:
Steps to verify complete invalidation before deployment:
Is the migration using the standard React Native CLI build commands (e.g., `npx react-native bundle`/`gradlew assembleRelease`) or an Expo managed workflow?
Use comments to ask for clarification. Post a solution as an answer.
8,130 reputation · 15 Apr 2026, 16:02 UTC
React Native does not treat a dev-to-production build switch as an automatic cache-invalidation event. Hermes bytecode caches stored in the app's data/code-cache directories can survive an install-over-install upgrade because the cache key is derived from the bundle content and Hermes version, not the build type. A version-code bump alone does not guarantee invalidation if the bundle hash remains identical.
For reliable verification before deployment: uninstall the debug variant (or run adb shell pm clear <package>), assemble a release AAB/APK with hermes_enabled=true and dev=false, then cold-start on a wiped emulator/device with the Metro server stopped. Inspect /data/user/0/<package>/code_cache/ (Android) or the equivalent iOS container after first launch—new .hbc files should appear only after the release bundle executes. This confirms the runtime is not falling back to stale dev bytecode.
Native module cleanup (AsyncStorage, network listeners, timers) still requires explicit teardown in native lifecycle hooks and JS AppState/unmount handlers; Fast Refresh does not reset native state.