OTA split bundle 已加载但 registerFeature 未注册
Date: 2026-07-08 Status: Fixed Scope: bundleLoader、FeatureHost、build-bundles
问题描述
- 现象:OTA 模式加载 order 时,先显示「加载中…」,随后报错:
bundle 已加载,但组件未注册 - 触发条件:同一 RN runtime 内第二次加载 feature,或切换 OTA/Metro 后再次进入
- 影响范围:所有 OTA Remote feature(order / promo)
根因分析
FeatureHost在加载前调用clearFeatureRegistration(),清除了registerFeature注册。- Native
registerSegmentWithId在同一 session 内对已注册 segment 不会重新 eval bundle,入口__r(entryId)不再执行。 loadFeatureBundle在updated: false时force: false可能跳过加载,加剧问题。- 部分上传的 bundle(如 764B)入口
__r错误,也会导致registerFeature未执行。
解决方案
- 新增
splitBundleEntry.ts:native load 后显式调用global.__r(entryModuleId)重跑入口。 FeatureHostOTA 路径始终force: true并清loadedBundleKeys。finalizeSplitBundle增强入口 module id 匹配,去掉多余__r()。
关键变更:
rn_app/src/features/splitBundleEntry.ts— 解析并重跑 split 入口rn_app/src/features/bundleLoader.ts— load 后调用executeSplitBundleEntryrn_app/src/features/FeatureHost.tsx— 强制重载rn_app/scripts/build-bundles.js— 修复 finalize 逻辑
验证方式
-
npm run build:bundles后 upload order bundle - OTA 模式进入 order → 正常显示
- 切换 Metro/OTA 或退出重进 → 不再报「组件未注册」
- 活动页「检查 Remote 更新」下载新 bundle 后立即生效
后续建议
- 删除 bundle-server 上过小的损坏 bundle(如 order.10.0.1/10.0.2 仅 764B)
- 重新 upload 最新
order.0.0.1.ios.jsbundle并设为 active release