react-native-update 10.35.7 → 10.35.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -19,6 +19,33 @@
19
19
  7. meta 信息及开放 API,提供更高扩展性。
20
20
  8. 提供付费的专人技术支持。
21
21
 
22
+ ### 与其他热更新库对比
23
+
24
+ | 对比维度 | react-native-update | expo-update | react-native-code-push |
25
+ |---------|---------------------|-------------|------------------------|
26
+ | **价格/成本** | 提供免费额度,多级梯度付费(最低约 66 元/月),流量不单独计费 | 提供免费额度,多级梯度付费(最低约 136 元/月),超出流量额外计费 | ❌ **已停运**(Microsoft App Center 已于 2025 年 3 月 31 日停止服务) |
27
+ | **更新包大小** | ⭐⭐⭐⭐⭐ 几十 KB(增量更新) | ⭐⭐⭐ 全量更新(通常几十 MB) | ❌ **已停运** |
28
+ | **中国地区访问速度** | ⭐⭐⭐⭐⭐ 阿里云 CDN,速度极快 | ⭐⭐ 国外服务器,可能较慢 | ❌ **已停运** |
29
+ | **iOS 支持** | ✅ 支持 | ✅ 支持 | ❌ **已停运** |
30
+ | **Android 支持** | ✅ 支持 | ✅ 支持 | ❌ **已停运** |
31
+ | **鸿蒙支持** | ✅ 支持 | ❌ 不支持 | ❌ **已停运** |
32
+ | **Expo 支持** | ✅ 支持 | ✅ 支持 | ❌ **已停运** |
33
+ | **RN 版本支持** | ⭐⭐⭐⭐⭐ 第一时间支持最新版本 | ⭐⭐⭐⭐ 跟随 Expo SDK | ❌ **已停运** |
34
+ | **新架构支持** | ✅ 支持 | ✅ 支持 | ❌ **已停运** |
35
+ | **Hermes 支持** | ✅ 支持 | ✅ 支持 | ❌ **已停运** |
36
+ | **崩溃回滚** | ✅ 自动回滚机制 | ✅ 支持 | ❌ **已停运** |
37
+ | **管理界面** | ✅ 命令行工具 + Web 管理界面 | ✅ Expo Dashboard | ❌ **已停运** |
38
+ | **CI/CD 集成** | ✅ 支持 | ✅ 支持 | ❌ **已停运** |
39
+ | **API 扩展性** | ✅ Meta 信息 + 开放 API | ⚠️ 有限 | ❌ **已停运** |
40
+ | **中文文档/支持** | ⭐⭐⭐⭐⭐ 完整中文文档,中文社区支持 | ⭐⭐ 英文为主 | ❌ **已停运** |
41
+ | **技术支持** | ✅ 付费专人技术支持 | ⚠️ 社区支持 | ❌ **已停运** |
42
+ | **服务器部署** | ✅ 可托管也可付费私有部署 | ✅ Expo 托管(EAS Update) | ❌ **已停运** |
43
+ | **更新策略** | 灵活配置(静默/提示/立即/延迟) | 相对固定 | ❌ **已停运** |
44
+ | **流量消耗** | ⭐⭐⭐⭐⭐ 极低(增量更新) | ⭐⭐⭐ 较高(全量更新) | ❌ **已停运** |
45
+ | **更新成功率** | ⭐⭐⭐⭐⭐ 极高(国内 CDN 优势) | ⭐⭐⭐ 中等 | ❌ **已停运** |
46
+
47
+
48
+
22
49
  ### 本地开发
23
50
 
24
51
  ```
@@ -22,6 +22,10 @@ public class UpdateContext {
22
22
  public static boolean DEBUG = false;
23
23
  private static ReactInstanceManager mReactInstanceManager;
24
24
  private static boolean isUsingBundleUrl = false;
25
+
26
+ // Singleton instance
27
+ private static UpdateContext sInstance;
28
+ private static final Object sLock = new Object();
25
29
 
26
30
  public UpdateContext(Context context) {
27
31
  this.context = context;
@@ -54,13 +58,17 @@ public class UpdateContext {
54
58
  boolean buildTimeChanged = !buildTime.equals(storedBuildTime);
55
59
 
56
60
  if (packageVersionChanged || buildTimeChanged) {
61
+ // Execute cleanUp before clearing SharedPreferences to avoid race condition
62
+ this.cleanUp();
63
+
57
64
  SharedPreferences.Editor editor = sp.edit();
58
65
  editor.clear();
59
66
  editor.putString("packageVersion", packageVersion);
60
67
  editor.putString("buildTime", buildTime);
61
- editor.apply();
62
-
63
- this.cleanUp();
68
+ // Use commit() instead of apply() to ensure synchronous write completion
69
+ // This prevents race condition where getBundleUrl() might read null values
70
+ // if called before apply() completes
71
+ editor.commit();
64
72
  }
65
73
  }
66
74
 
@@ -227,12 +235,26 @@ public class UpdateContext {
227
235
  return mReactInstanceManager;
228
236
  }
229
237
 
238
+ /**
239
+ * Get singleton instance of UpdateContext
240
+ */
241
+ public static UpdateContext getInstance(Context context) {
242
+ if (sInstance == null) {
243
+ synchronized (sLock) {
244
+ if (sInstance == null) {
245
+ sInstance = new UpdateContext(context.getApplicationContext());
246
+ }
247
+ }
248
+ }
249
+ return sInstance;
250
+ }
251
+
230
252
  public static String getBundleUrl(Context context) {
231
- return new UpdateContext(context.getApplicationContext()).getBundleUrl();
253
+ return getInstance(context).getBundleUrl();
232
254
  }
233
255
 
234
256
  public static String getBundleUrl(Context context, String defaultAssetsUrl) {
235
- return new UpdateContext(context.getApplicationContext()).getBundleUrl(defaultAssetsUrl);
257
+ return getInstance(context).getBundleUrl(defaultAssetsUrl);
236
258
  }
237
259
 
238
260
  public String getBundleUrl() {
@@ -27,7 +27,7 @@ public class UpdateModule extends NativePushySpec {
27
27
  }
28
28
 
29
29
  public UpdateModule(ReactApplicationContext reactContext) {
30
- this(reactContext, new UpdateContext(reactContext.getApplicationContext()));
30
+ this(reactContext, UpdateContext.getInstance(reactContext));
31
31
  }
32
32
 
33
33
  @Override
@@ -40,7 +40,7 @@ public class UpdateModule extends ReactContextBaseJavaModule {
40
40
  }
41
41
 
42
42
  public UpdateModule(ReactApplicationContext reactContext) {
43
- this(reactContext, new UpdateContext(reactContext.getApplicationContext()));
43
+ this(reactContext, UpdateContext.getInstance(reactContext));
44
44
  }
45
45
 
46
46
  @Override
@@ -37,10 +37,10 @@ export class UpdateContext {
37
37
  this.preferences.putSync('packageVersion', packageVersion);
38
38
  this.preferences.flush();
39
39
  } else if (storedVersion && packageVersion !== storedVersion) {
40
+ this.cleanUp();
40
41
  this.preferences.clear();
41
42
  this.preferences.putSync('packageVersion', packageVersion);
42
43
  this.preferences.flush();
43
- this.cleanUp();
44
44
  }
45
45
  } catch (e) {
46
46
  console.error('Failed to init preferences:', e);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-update",
3
- "version": "10.35.7",
3
+ "version": "10.35.8",
4
4
  "description": "react-native hot update",
5
5
  "main": "src/index",
6
6
  "scripts": {
package/src/context.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { createContext, useContext } from 'react';
2
2
  import { CheckResult, ProgressData } from './type';
3
3
  import { Pushy, Cresc } from './client';
4
+ import i18n from './i18n';
4
5
 
5
6
  const noop = () => {};
6
7
  const asyncNoop = () => Promise.resolve();
@@ -50,7 +51,16 @@ export const UpdateContext = createContext<{
50
51
  lastError?: Error;
51
52
  }>(defaultContext);
52
53
 
53
- export const useUpdate = () => useContext(UpdateContext);
54
+ export const useUpdate = __DEV__ ? () => {
55
+ const context = useContext(UpdateContext);
56
+
57
+ // 检查是否在 UpdateProvider 内部使用
58
+ if (!context.client) {
59
+ throw new Error(i18n.t('error_use_update_outside_provider'));
60
+ }
61
+
62
+ return context;
63
+ } : () => useContext(UpdateContext);
54
64
 
55
65
  /** @deprecated Please use `useUpdate` instead */
56
66
  export const usePushy = useUpdate;
package/src/locales/en.ts CHANGED
@@ -71,4 +71,8 @@ export default {
71
71
  // Development environment messages
72
72
  dev_incremental_update_disabled:
73
73
  'Currently in development environment, incremental hot update cannot be executed and restart will not take effect. If you need to test effective full hot update in development environment (but will reconnect to metro after restart), please enable "ignore timestamp" switch and retry.',
74
+
75
+ // Context error messages
76
+ error_use_update_outside_provider:
77
+ 'useUpdate must be used within an UpdateProvider. Please wrap your component tree with <UpdateProvider client={...}>.',
74
78
  };
package/src/locales/zh.ts CHANGED
@@ -68,4 +68,8 @@ export default {
68
68
  // Development environment messages
69
69
  dev_incremental_update_disabled:
70
70
  '当前是开发环境,无法执行增量式热更新,重启不会生效。如果需要在开发环境中测试可生效的全量热更新(但也会在再次重启后重新连接 metro),请打开"忽略时间戳"开关再重试。',
71
+
72
+ // Context error messages
73
+ error_use_update_outside_provider:
74
+ 'useUpdate 必须在 UpdateProvider 内部使用。请使用 <UpdateProvider client={...}> 包裹您的组件树。',
71
75
  };