miaoda-expo-devkit 0.1.1-beta.121 → 0.1.1-beta.123

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
@@ -78,7 +78,7 @@ Sentry.init({
78
78
 
79
79
  - `console.warn`、`console.error` 不再弹出 LogBox 底部通知;
80
80
  - 原始日志仍会输出到 Metro、ADB 或 Xcode 控制台;
81
- - 未捕获的 JavaScript 异常仍由 React Native 和自定义 Development Build 的错误处理链路处理;
81
+ - 未捕获的 JavaScript 异常继续展示错误详情;未处理的 Promise 拒绝由 RN 与 Expo runtime 托管补丁单独自动打开详情,不受普通通知隐藏影响;
82
82
  - 如需临时恢复 LogBox,可在应用调试代码中调用 `LogBox.ignoreAllLogs(false)`。
83
83
 
84
84
  该策略属于 JavaScript Bundle 的公共启动注入,不修改业务页面,也不需要在每个应用中重复配置。未使用
package/docs/patches.md CHANGED
@@ -24,7 +24,7 @@ dependency 路径,并写入精确版本和完整性校验;无需在生成产
24
24
 
25
25
  ## 托管补丁清单
26
26
 
27
- DevKit 当前管理以下补丁(11 个托管补丁、18 个补丁文件,覆盖 18 个包版本):
27
+ DevKit 当前管理以下补丁(12 个托管补丁、19 个补丁文件,覆盖 20 个包版本):
28
28
 
29
29
  **当前版本:**
30
30
 
@@ -32,7 +32,8 @@ DevKit 当前管理以下补丁(11 个托管补丁、18 个补丁文件,覆
32
32
  - `expo@55.0.6`(HMR 批量编辑控制的客户端;并固定 `expo-audio@55.0.6` 和 `expo-video@55.0.5` 的 Expo 兼容版本表)
33
33
  - `metro-runtime@0.83.3`(HMRClient 透传 `miaoda-hmr-control` 控制消息,并在执行增量前支持异步原生能力检查)
34
34
  - `metro-file-map@0.83.3`(`miaodaFlushChanges` 文件监听栅栏,保证恢复时 watcher 已看到全部写入)
35
- - `react-native@0.83.2`(LogBox 错误页增强:错误标题映射与一键复制)
35
+ - `react-native@0.83.2`(LogBox 错误页增强:错误标题映射、一键复制及未处理 Promise 拒绝独立展示)
36
+ - `@expo/metro-runtime@55.0.11-55.0.12`(Expo 覆盖 RN Promise 跟踪器时保留拒绝来源标记;与 RN 补丁配套,不影响普通 console.error 的隐藏策略)
36
37
  - `expo-modules-core@55.0.15`(Android CMake 打包 worklets 原生库)
37
38
  - `react-native-reanimated@4.2.1`(Android 打包 `libworklets.so` 并关联 worklets 构建任务)
38
39
  - `react-native-worklets@0.7.4`(Babel 插件规范化 TypeScript 函数类型)
@@ -74,8 +75,8 @@ pnpm --dir packages/devkit test:patches
74
75
  ```
75
76
 
76
77
  该命令会自动构建并打包 DevKit,在临时项目中模拟 pnpm 安装 Config Dependency 后的
77
- 目录布局,安装受支持版本范围内的目标依赖,检查 11 个托管补丁(18 个补丁文件,
78
- 覆盖 18 个包版本,含 CSS interop、Worklets、Skia 的历史 legacy 版本)及 lockfile,
78
+ 目录布局,安装受支持版本范围内的目标依赖,检查全部托管补丁及 lockfile(数量与
79
+ 「托管补丁清单」一节一致,含 CSS interop、Worklets、Skia 的历史 legacy 版本),
79
80
  然后执行 frozen-lockfile 复装,并运行真实 Metro 文件监听、HTTP 控制接口和 `/hot`
80
81
  WebSocket 回归,最后清理临时目录。它不会运行 Expo Prebuild、Gradle 或 Android 编译。
81
82
 
package/docs/stubs.md CHANGED
@@ -26,6 +26,8 @@ stub 文件位于 `dist/stubs/`,wrapper 的完整清单与组合关系见
26
26
 
27
27
  由 iOS/Android 的原生入口 stub 在业务代码前加载,调用 `LogBox.ignoreAllLogs(true)` 隐藏普通错误和警告
28
28
  通知。它不删除日志,也不阻止未捕获异常进入自定义错误处理链路。
29
+ RN 托管补丁会为未处理的 Promise 拒绝单独自动打开错误详情,保留非致命级别与调用栈;
30
+ 普通 `console.error` 不会自动弹出,即使消息包含 Promise 错误前缀也不例外。
29
31
 
30
32
  ### expo-router-entry-native-stub.js
31
33
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "miaoda-expo-devkit",
3
- "version": "0.1.1-beta.121",
3
+ "version": "0.1.1-beta.123",
4
4
  "description": "Expo 应用开发工具集:Sentry DSN 替换 stub、错误/网络捕获、Metro 符号化",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.js",
@@ -0,0 +1,26 @@
1
+ diff --git a/src/promiseRejectionTracking.native.ts b/src/promiseRejectionTracking.native.ts
2
+ index b730115..fd2ec08 100644
3
+ --- a/src/promiseRejectionTracking.native.ts
4
+ +++ b/src/promiseRejectionTracking.native.ts
5
+ @@ -52,7 +52,7 @@ export function enablePromiseRejectionTracking() {
6
+ const rejectionError = new Error(`${rejectionPrefix} ${message ?? ''}`, {
7
+ cause: rejection,
8
+ });
9
+ - if (typeof rejection === 'object' && 'stack' in rejection) {
10
+ + if (rejection !== null && typeof rejection === 'object' && 'stack' in rejection) {
11
+ // If original rejection stack exists, use it
12
+ rejectionError.stack = `${rejectionPrefix} ${rejection.stack ?? ''}`;
13
+ } else {
14
+ @@ -60,7 +60,11 @@ export function enablePromiseRejectionTracking() {
15
+ // Stack of the error created here won't be any useful to the user
16
+ rejectionError.stack = `${rejectionPrefix} ${message ?? ''}`;
17
+ }
18
+ - ExceptionsManager.handleException(rejectionError);
19
+ + // Expo 的原生异常管理器直接转发 RN,使用相同的额外数据键标记拒绝来源。
20
+ + (rejectionError as Error & { 'RN$ErrorExtraDataKey': Record<string, boolean> })[
21
+ + 'RN$ErrorExtraDataKey'
22
+ + ] = { miaodaUnhandledPromiseRejection: true };
23
+ + ExceptionsManager.handleException(rejectionError, false);
24
+ },
25
+ onHandled: (id) => {
26
+ const warning =
@@ -21,7 +21,7 @@ index e2b8941..355deae 100644
21
21
  "jest-expo": "~55.0.9",
22
22
  "lottie-react-native": "~7.3.4",
23
23
  diff --git a/src/async-require/hmr.ts b/src/async-require/hmr.ts
24
- index c0ea71e..e1789cc 100644
24
+ index c0ea71e..d696ac1 100644
25
25
  --- a/src/async-require/hmr.ts
26
26
  +++ b/src/async-require/hmr.ts
27
27
  @@ -11,12 +11,25 @@
@@ -50,7 +50,7 @@ index c0ea71e..e1789cc 100644
50
50
  showLoading,
51
51
  } from './hmrUtils';
52
52
 
53
- @@ -29,8 +42,197 @@ let hmrClient: MetroHMRClient | null = null;
53
+ @@ -29,8 +42,246 @@ let hmrClient: MetroHMRClient | null = null;
54
54
  let hmrUnavailableReason: string | null = null;
55
55
  const buildErrorQueue = new Set<unknown>();
56
56
  let didConnect: boolean = false;
@@ -58,35 +58,73 @@ index c0ea71e..e1789cc 100644
58
58
  +// miaodaPaused 是 Agent 的编辑闸门,与用户自己的 Fast Refresh 开关
59
59
  +// (fastRefreshRequested)相互独立:放行后只有用户开着 Fast Refresh 才恢复更新。
60
60
  +let miaodaPaused = false;
61
- +// 暂停状态订阅者:launch/MiaodaHmrOverlay 的全屏遮罩据此在 Agent 批量编辑
62
- +// 期间盖住应用、阻断交互。遮罩挂在 dev 模式的根组件包装里,纯 JS 实现。
63
- +const miaodaPausedListeners = new Set<(paused: boolean) => void>();
61
+ +// 展示与执行闸门独立:resume 仅放开闸门,最终增量注入完成才撤罩。
62
+ +let miaodaPresentationVisible = false;
63
+ +// 仅恢复确实因断线让出的遮罩;错误/暂缓等主动让位必须清除此标记。
64
+ +let miaodaPresentationHiddenByDisconnect = false;
65
+ +let miaodaBatchPending = false;
66
+ +let miaodaControlEpoch = 0;
67
+ +const miaodaPresentationListeners = new Set<(visible: boolean) => void>();
68
+ +
69
+ +function setMiaodaPresentation(visible: boolean) {
70
+ + miaodaPresentationHiddenByDisconnect = false;
71
+ + if (miaodaPresentationVisible === visible) return;
72
+ + miaodaPresentationVisible = visible;
73
+ + for (const listener of miaodaPresentationListeners) {
74
+ + try { listener(visible); } catch {}
75
+ + }
76
+ +}
77
+ +
78
+ +function hideMiaodaPresentationForDisconnect() {
79
+ + const restore = miaodaPresentationVisible || miaodaPresentationHiddenByDisconnect;
80
+ + setMiaodaPresentation(false);
81
+ + miaodaPresentationHiddenByDisconnect = restore;
82
+ +}
83
+ +
84
+ +function showMiaodaPausedPresentation() {
85
+ + setMiaodaPresentation(!miaodaServerDisconnected);
86
+ + // 新 pause 即使发生于断线中,恢复后也应展示;不能继承旧批次的错误让位。
87
+ + miaodaPresentationHiddenByDisconnect = miaodaServerDisconnected;
88
+ +}
64
89
  +
65
- +// miaodaPaused 的唯一写入入口:值真正变化时才广播,订阅者异常不能
66
- +// 反过来打断 HMR 控制链路(ack、reload 等时序敏感操作)。
67
90
  +function setMiaodaPaused(paused: boolean) {
68
91
  + if (miaodaPaused === paused) return;
69
92
  + miaodaPaused = paused;
70
- + for (const listener of miaodaPausedListeners) {
71
- + try {
72
- + listener(paused);
73
- + } catch {}
93
+ + if (paused) {
94
+ + miaodaBatchPending = true;
95
+ + showMiaodaPausedPresentation();
74
96
  + }
75
97
  +}
76
98
  +
77
- +// 订阅暂停状态变化,返回取消订阅函数(供 React useEffect 使用)。
78
- +export function subscribeMiaodaPaused(listener: (paused: boolean) => void): () => void {
79
- + miaodaPausedListeners.add(listener);
80
- + return () => {
81
- + miaodaPausedListeners.delete(listener);
82
- + };
99
+ +export function subscribeMiaodaPresentation(listener: (visible: boolean) => void): () => void {
100
+ + miaodaPresentationListeners.add(listener);
101
+ + return () => { miaodaPresentationListeners.delete(listener); };
102
+ +}
103
+ +
104
+ +export function isMiaodaPresentationVisible(): boolean {
105
+ + return miaodaPresentationVisible;
83
106
  +}
84
107
  +
85
- +// 遮罩挂载时读取当前值,避免错过订阅注册之前发生的迁移。
86
108
  +export function isMiaodaPaused(): boolean {
87
109
  + return miaodaPaused;
88
110
  +}
89
111
  +
112
+ +function finishMiaodaBatch() {
113
+ + // 新 pause 与完整重载优先,迟到的 applied 不能结束它们。
114
+ + if (miaodaPaused || miaodaReloadIntent || miaodaReloadCommitted) return;
115
+ + miaodaBatchPending = false;
116
+ + setMiaodaPresentation(false);
117
+ +}
118
+ +
119
+ +function resumeMiaodaPresentation() {
120
+ + if (!miaodaBatchPending) return;
121
+ + if (!fastRefreshRequested && !miaodaReloadIntent) {
122
+ + finishMiaodaBatch();
123
+ + return;
124
+ + }
125
+ + setMiaodaPresentation(!miaodaServerDisconnected);
126
+ +}
127
+ +
90
128
  +let miaodaServerDisconnected = false;
91
129
  +// 开发服务器断线状态订阅者:launch/ 里的回退横幅(旧客户端)据此提示用户
92
130
  +// Metro 已不可达。新客户端上阻断 UI 由原生阻断页渲染,JS 只上报状态。
@@ -97,6 +135,7 @@ index c0ea71e..e1789cc 100644
97
135
  +function setMiaodaServerDisconnected(disconnected: boolean) {
98
136
  + if (miaodaServerDisconnected === disconnected) return;
99
137
  + miaodaServerDisconnected = disconnected;
138
+ + if (disconnected) hideMiaodaPresentationForDisconnect();
100
139
  + // 新客户端:断线挂原生阻断页(重新尝试 / 退出),恢复时收起。
101
140
  + // 同一时刻只保留一个阻断页且连接优先:热更新确认页已在展示时不再切换
102
141
  + //(该页本身已阻断交互,确认或退出后断线状态仍由轮询驱动重新挂出)。
@@ -196,6 +235,10 @@ index c0ea71e..e1789cc 100644
196
235
  +// 避免 Metro 快速重启时闪烁误报;WebSocket close 本身不触发横幅。
197
236
  +let miaodaPollFailureCount = 0;
198
237
  +const MIAODA_POLL_FAILURE_THRESHOLD = 3;
238
+ +// 轮询单调序号:重试按钮或 WebSocket 重连会与在途定时轮询并发,
239
+ +// 响应可能乱序返回。序号小于最新一轮的响应直接丢弃,防止旧快照
240
+ +// 反向解除新一轮 pause 或触发多余 reload。
241
+ +let miaodaPollSequence = 0;
199
242
  const pendingLogs: [LogLevel, any[]][] = [];
200
243
 
201
244
  +// 完整重载是独立于增量的待执行意图。轮询会反复返回同一个版本,用户暂缓后
@@ -208,6 +251,7 @@ index c0ea71e..e1789cc 100644
208
251
  +function requestMiaodaReload(key: string) {
209
252
  + if (miaodaReloadCommitted) return;
210
253
  + if (!isMiaodaHmrCompatibilityEnabled()) {
254
+ + miaodaReloadCommitted = true;
211
255
  + reload();
212
256
  + return;
213
257
  + }
@@ -224,6 +268,7 @@ index c0ea71e..e1789cc 100644
224
268
  + if (!intent || intent.attempted || miaodaReloadChecking || miaodaReloadCommitted || miaodaPaused) return;
225
269
  + // 连接优先于能力:断线期间检查只会得到 unknown,等恢复后由轮询重新驱动。
226
270
  + if (miaodaServerDisconnected) return;
271
+ + if (miaodaBatchPending) setMiaodaPresentation(true);
227
272
  + intent.attempted = true;
228
273
  + miaodaReloadChecking = true;
229
274
  + const epoch = miaodaReloadEpoch;
@@ -231,13 +276,17 @@ index c0ea71e..e1789cc 100644
231
276
  + try {
232
277
  + if (await checkMiaodaHmrCompatibility(isCurrent) && isCurrent()) {
233
278
  + miaodaReloadCommitted = true;
279
+ + // 保留旧 JS 遮罩直到树卸载,不把原生启动遮罩误当作 reload 完成信号。
234
280
  + reload();
281
+ + } else if (isCurrent()) {
282
+ + setMiaodaPresentation(false);
235
283
  + }
236
284
  + } catch {
237
285
  + // 检查失败保留意图,用户可通过运行中的提示重试;不自动执行新 Bundle。
286
+ + if (isCurrent()) setMiaodaPresentation(false);
238
287
  + } finally {
239
288
  + miaodaReloadChecking = false;
240
- + hideLoading();
289
+ + if (miaodaReloadIntent === intent && miaodaReloadEpoch === epoch) hideLoading();
241
290
  + // 检查过程中收到更新的重载指令时,旧授权无效,新指令需要自己的检查。
242
291
  + if (miaodaReloadIntent !== intent || miaodaReloadEpoch !== epoch) {
243
292
  + void attemptMiaodaReload();
@@ -248,7 +297,7 @@ index c0ea71e..e1789cc 100644
248
297
  type LogLevel =
249
298
  | 'trace'
250
299
  | 'info'
251
- @@ -42,6 +244,127 @@ type LogLevel =
300
+ @@ -42,6 +293,144 @@ type LogLevel =
252
301
  | 'groupEnd'
253
302
  | 'debug';
254
303
 
@@ -275,6 +324,8 @@ index c0ea71e..e1789cc 100644
275
324
  +
276
325
  +async function pollMiaodaStatus() {
277
326
  + if (process.env.EXPO_OS === 'web' || !miaodaStatusHost || miaodaStatusPollingStopped) return;
327
+ + const controlEpoch = miaodaControlEpoch;
328
+ + const sequence = ++miaodaPollSequence;
278
329
  + let protocol = miaodaStatusProtocol ?? miaodaStatusInitialProtocol;
279
330
  + try {
280
331
  + let response;
@@ -318,6 +369,9 @@ index c0ea71e..e1789cc 100644
318
369
  + const state = (await response.json()) as {
319
370
  + paused?: boolean; reloadPending?: boolean; stateVersion?: number; lastMode?: string | null;
320
371
  + };
372
+ + // HTTP 请求期间若已有新控制帧,或已有更新一轮轮询在途/完成,
373
+ + // 旧快照不能反向解除新 pause 或触发多余的 reload。
374
+ + if (controlEpoch !== miaodaControlEpoch || sequence !== miaodaPollSequence) return;
321
375
  + // 拿到合法状态响应说明开发服务器存活:清零失败计数并撤下断线提示。
322
376
  + miaodaPollFailureCount = 0;
323
377
  + setMiaodaServerDisconnected(false);
@@ -334,6 +388,7 @@ index c0ea71e..e1789cc 100644
334
388
  + if (miaodaReloadIntent) miaodaReloadIntent.attempted = false;
335
389
  + }
336
390
  + setMiaodaPaused(true);
391
+ + if (miaodaPresentationHiddenByDisconnect) setMiaodaPresentation(true);
337
392
  + hmrClient?.disable();
338
393
  + // 把观察到的这次暂停作为本地基线版本。之后若出现没有对应 WebSocket
339
394
  + // 控制消息的新版本,说明错过了状态迁移,必须完整 Bundle reload。
@@ -351,6 +406,7 @@ index c0ea71e..e1789cc 100644
351
406
  + setMiaodaPaused(false);
352
407
  + miaodaLastControlVersion = version;
353
408
  + if (shouldReload) {
409
+ + if (miaodaBatchPending) setMiaodaPresentation(!miaodaServerDisconnected);
354
410
  + requestMiaodaReload(`state:${version}`);
355
411
  + return;
356
412
  + }
@@ -358,6 +414,16 @@ index c0ea71e..e1789cc 100644
358
414
  + void attemptMiaodaReload();
359
415
  + return;
360
416
  + }
417
+ + // 轮询观察到 paused=false 时按 resume 语义收尾展示:关闭 Fast Refresh
418
+ + // 或没有待应用增量时撤罩,避免无版本号的状态迁移让遮罩永久残留。
419
+ + // 只撤不挂:错误/能力暂缓的主动让位不能被轮询重新盖住。
420
+ + if (miaodaBatchPending) {
421
+ + if (!fastRefreshRequested && !miaodaReloadIntent) {
422
+ + finishMiaodaBatch();
423
+ + } else if (hmrClient != null && !hmrClient.hasPendingUpdates()) {
424
+ + finishMiaodaBatch();
425
+ + }
426
+ + }
361
427
  + if (fastRefreshRequested) HMRClient.enable();
362
428
  + }
363
429
  + } catch {
@@ -376,7 +442,7 @@ index c0ea71e..e1789cc 100644
376
442
  function assert(foo: any, msg: string): asserts foo {
377
443
  if (!foo) throw new Error(msg);
378
444
  }
379
- @@ -52,6 +375,9 @@ function assert(foo: any, msg: string): asserts foo {
445
+ @@ -52,6 +441,9 @@ function assert(foo: any, msg: string): asserts foo {
380
446
  */
381
447
  const HMRClient = {
382
448
  enable() {
@@ -386,15 +452,29 @@ index c0ea71e..e1789cc 100644
386
452
  if (hmrUnavailableReason !== null) {
387
453
  // If HMR became unavailable while you weren't using it,
388
454
  // explain why when you try to turn it on.
389
- @@ -87,6 +413,7 @@ const HMRClient = {
455
+ @@ -75,6 +467,10 @@ const HMRClient = {
456
+ }
457
+ try {
458
+ hmrClient.enable();
459
+ + } catch (error) {
460
+ + // 未启用异步能力 gate 时注入会同步抛错;让错误界面可见但不重放增量。
461
+ + if (!miaodaPaused) setMiaodaPresentation(false);
462
+ + throw error;
463
+ } finally {
464
+ if (hasUpdates) {
465
+ hideLoading();
466
+ @@ -87,8 +483,10 @@ const HMRClient = {
390
467
  },
391
468
 
392
469
  disable() {
393
470
  + fastRefreshRequested = false;
394
471
  assert(hmrClient, 'Expected HMRClient.setup() call at startup.');
395
472
  hmrClient.disable();
473
+ + if (!miaodaPaused && !miaodaReloadIntent) finishMiaodaBatch();
396
474
  },
397
- @@ -180,6 +507,42 @@ const HMRClient = {
475
+
476
+ registerBundle(requestUrl: string) {
477
+ @@ -180,6 +578,55 @@ const HMRClient = {
398
478
  const origin = `${serverScheme}://${serverHost}`;
399
479
  const client = new MetroHMRClient(`${origin}/hot`);
400
480
  hmrClient = client;
@@ -404,15 +484,25 @@ index c0ea71e..e1789cc 100644
404
484
  + setUpdateGate: (gate: (isCurrent: () => boolean) => Promise<boolean>) => void;
405
485
  + retryPendingUpdate: () => void;
406
486
  + };
407
- + gatedClient.setUpdateGate((isCurrent) => checkMiaodaHmrCompatibility(
408
- + () => isCurrent() && hmrClient === client && !miaodaPaused && !miaodaReloadIntent && !miaodaReloadCommitted
409
- + ));
487
+ + gatedClient.setUpdateGate(async (isCurrent) => {
488
+ + const current = () => isCurrent() && hmrClient === client && !miaodaPaused && !miaodaReloadIntent && !miaodaReloadCommitted;
489
+ + try {
490
+ + const allowed = await checkMiaodaHmrCompatibility(current);
491
+ + // 暂缓让出遮罩给确认/重试入口,但不放行 runtime 缓存的代码。
492
+ + if (!allowed && current()) setMiaodaPresentation(false);
493
+ + return allowed;
494
+ + } catch (error) {
495
+ + if (current()) setMiaodaPresentation(false);
496
+ + throw error;
497
+ + }
498
+ + });
410
499
  + setMiaodaHmrCompatibilityRetry(() => {
411
500
  + if (miaodaPaused || miaodaReloadCommitted) return;
412
501
  + if (miaodaReloadIntent) {
413
502
  + miaodaReloadIntent.attempted = false;
414
503
  + void attemptMiaodaReload();
415
504
  + } else if (fastRefreshRequested) {
505
+ + if (miaodaBatchPending) setMiaodaPresentation(!miaodaServerDisconnected);
416
506
  + gatedClient.retryPendingUpdate();
417
507
  + }
418
508
  + });
@@ -423,10 +513,13 @@ index c0ea71e..e1789cc 100644
423
513
  + client.on('update-gate-error', () => hideLoading());
424
514
  + client.on('update-apply-error', (error: Error) => {
425
515
  + hideLoading();
516
+ + if (!miaodaPaused) setMiaodaPresentation(false);
426
517
  + // 模块可能已经部分执行,不能自动重放同一增量;显示错误并保留完整重载入口。
427
518
  + handleCompileError(error);
428
519
  + });
429
520
  + }
521
+ + // 所有客户端都监听真实注入完成,不限于启用了能力检查的设备。
522
+ + client.on('update-applied', () => finishMiaodaBatch());
430
523
  + if (process.env.EXPO_OS !== 'web') {
431
524
  + // 仅 native 客户端启用状态轮询。初始协议跟随 bundle URL 的 scheme:
432
525
  + // 设备可能拿到证书无效的 HTTPS 开发地址,也有环境只暴露 HTTPS,
@@ -437,7 +530,7 @@ index c0ea71e..e1789cc 100644
437
530
 
438
531
  pendingEntryPoints.push(
439
532
  // HMRServer understands regular bundle URLs, so prefer that in case
440
- @@ -193,6 +556,61 @@ const HMRClient = {
533
+ @@ -193,6 +640,72 @@ const HMRClient = {
441
534
  })
442
535
  );
443
536
 
@@ -458,6 +551,8 @@ index c0ea71e..e1789cc 100644
458
551
  + version: number; action: string; id?: number; error?: any; stateVersion?: number;
459
552
  + }) => {
460
553
  + if (message.version !== 1) return;
554
+ + if (typeof message.stateVersion === 'number' && miaodaLastControlVersion !== null && message.stateVersion < miaodaLastControlVersion) return;
555
+ + miaodaControlEpoch += 1;
461
556
  + if (Number.isInteger(message.stateVersion)) {
462
557
  + if (miaodaSessionBaseVersion === null) miaodaSessionBaseVersion = message.stateVersion!;
463
558
  + miaodaStateVersion = message.stateVersion!;
@@ -470,6 +565,8 @@ index c0ea71e..e1789cc 100644
470
565
  + miaodaReloadEpoch += 1;
471
566
  + if (miaodaReloadIntent) miaodaReloadIntent.attempted = false;
472
567
  + setMiaodaPaused(true);
568
+ + miaodaBatchPending = true;
569
+ + showMiaodaPausedPresentation();
473
570
  + client.disable();
474
571
  + hideLoading();
475
572
  + client.send(JSON.stringify({type: 'miaoda-hmr-ack', version: 1, id: message.id}));
@@ -478,19 +575,26 @@ index c0ea71e..e1789cc 100644
478
575
  + // 解除 Agent 闸门;用户自己的 Fast Refresh 开关保持独立,
479
576
  + // 只有它开着才真正恢复更新。
480
577
  + setMiaodaPaused(false);
578
+ + resumeMiaodaPresentation();
481
579
  + if (miaodaReloadIntent) void attemptMiaodaReload();
482
- + else if (fastRefreshRequested) HMRClient.enable();
580
+ + else if (fastRefreshRequested) {
581
+ + HMRClient.enable();
582
+ + // resume 是缓存投递屏障;无 graph/空批次不能等待未来事件永挡。
583
+ + if (!client.hasPendingUpdates()) finishMiaodaBatch();
584
+ + }
483
585
  + break;
484
586
  + case 'reload':
485
- + // 完整重载意图保持增量闸门,但不使用编辑遮罩困住选择保留旧应用的用户。
587
+ + // 完整重载仍保持增量闸门;能力检查暂缓时才让出遮罩。
486
588
  + setMiaodaPaused(false);
487
589
  + client.disable();
590
+ + if (miaodaBatchPending) setMiaodaPresentation(!miaodaServerDisconnected);
488
591
  + requestMiaodaReload(`state:${message.stateVersion ?? 'socket'}`);
489
592
  + break;
490
593
  + case 'error':
491
594
  + // 批次最终编译失败:闸门仍然关着(服务端等 Agent 修好重试),
492
595
  + // 但错误本身要展示出来,因为它在设备端是可行动的。
493
596
  + hideLoading();
597
+ + setMiaodaPresentation(false);
494
598
  + handleCompileError(message.error);
495
599
  + break;
496
600
  + }
@@ -499,7 +603,7 @@ index c0ea71e..e1789cc 100644
499
603
  client.on('connection-error', (e: Error) => {
500
604
  setHMRUnavailableReason(getConnectionError(serverHost, e));
501
605
  });
502
- @@ -221,7 +639,13 @@ const HMRClient = {
606
+ @@ -221,7 +734,13 @@ const HMRClient = {
503
607
  }) => {
504
608
  // NOTE(@krystofwoldrich): I don't know why sometimes empty updates are sent. But they should not reset the overlay.
505
609
  const isEmpty = added.length === 0 && modified.length === 0 && deleted.length === 0;
@@ -514,18 +618,19 @@ index c0ea71e..e1789cc 100644
514
618
  resetErrorOverlay();
515
619
  }
516
620
  }
517
- @@ -234,6 +658,10 @@ const HMRClient = {
621
+ @@ -234,6 +753,11 @@ const HMRClient = {
518
622
  client.on('error', (data) => this._onMetroError(data));
519
623
 
520
624
  client.on('close', (closeEvent?: { code: number; reason: string }) => {
521
625
  + // 控制通道断开:之后的版本变化都无法通过 socket 同步,
522
626
  + // 启动轮询兜底直到重连。
523
627
  + miaodaWebSocketDisconnected = true;
628
+ + hideMiaodaPresentationForDisconnect();
524
629
  + scheduleMiaodaStatusPoll();
525
630
  hideLoading();
526
631
  const reason = closeEvent?.reason;
527
632
  const code = closeEvent?.code || 1000;
528
- @@ -318,7 +746,8 @@ function setHMRUnavailableReason(reason: string) {
633
+ @@ -318,7 +842,8 @@ function setHMRUnavailableReason(reason: string) {
529
634
  function registerBundleEntryPoints(client: MetroHMRClient | null) {
530
635
  if (hmrUnavailableReason != null) {
531
636
  // "Bundle Splitting – Metro disconnected"
@@ -535,7 +640,7 @@ index c0ea71e..e1789cc 100644
535
640
  return;
536
641
  }
537
642
 
538
- @@ -326,6 +755,9 @@ function registerBundleEntryPoints(client: MetroHMRClient | null) {
643
+ @@ -326,6 +851,9 @@ function registerBundleEntryPoints(client: MetroHMRClient | null) {
539
644
  client?.send(
540
645
  JSON.stringify({
541
646
  type: 'register-entrypoints',
@@ -1034,35 +1139,37 @@ index 0000000..4aecd61
1034
1139
  +});
1035
1140
  diff --git a/src/launch/MiaodaHmrOverlay.tsx b/src/launch/MiaodaHmrOverlay.tsx
1036
1141
  new file mode 100644
1037
- index 0000000..8b8cef4
1142
+ index 0000000..6d47443
1038
1143
  --- /dev/null
1039
1144
  +++ b/src/launch/MiaodaHmrOverlay.tsx
1040
- @@ -0,0 +1,58 @@
1145
+ @@ -0,0 +1,60 @@
1041
1146
  +import * as React from 'react';
1042
1147
  +import { ActivityIndicator, StyleSheet, Text, View } from 'react-native';
1043
1148
  +
1044
- +import { isMiaodaPaused, subscribeMiaodaPaused } from '../async-require/hmr';
1149
+ +import { isMiaodaPresentationVisible, subscribeMiaodaPresentation } from '../async-require/hmr';
1045
1150
  +
1046
1151
  +// Miaoda HMR 批量编辑期间的「更新中」全屏遮罩。
1047
1152
  +//
1048
1153
  +// Agent 通过 `/_hmr/off` 暂停 HMR 后会连续改写工程文件,这期间设备仍在运行
1049
1154
  +// 上一份完好的 JS,但用户看到的是一个随时会被替换掉的界面,继续操作会产生
1050
1155
  +// 基于旧代码的困惑交互。遮罩在暂停期间盖住整个应用并吃掉所有触摸,
1051
- +// resume(或 reload 导致的整树卸载)后自动消失。
1156
+ +// 最终增量注入完成(或 reload 导致的整树卸载)后自动消失。
1052
1157
  +//
1053
- +// 状态源是 async-require/hmr 里的 miaodaPaused 广播:WebSocket 控制帧到达时
1158
+ +// 状态源是 async-require/hmr 里的 独立展示状态广播:WebSocket 控制帧到达时
1054
1159
  +// 同步触发,2 秒轮询兜底路径同样走该广播,因此两种通道下遮罩行为一致。
1055
1160
  +// 纯 JS 实现,挂在 withDevTools 里,只在开发模式出现,不需要原生改动。
1056
1161
  +export default function MiaodaHmrOverlay(): React.ReactElement | null {
1057
- + // 挂载时用当前值初始化,避免错过订阅注册之前就已经开始的暂停。
1058
- + const [paused, setPaused] = React.useState(isMiaodaPaused);
1059
- +
1060
- + React.useEffect(() => subscribeMiaodaPaused(setPaused), []);
1162
+ + // 外部状态订阅同时校验 render 到 commit 的快照,避免这段间隙漏掉完成事件。
1163
+ + const visible = React.useSyncExternalStore(
1164
+ + subscribeMiaodaPresentation,
1165
+ + isMiaodaPresentationVisible,
1166
+ + isMiaodaPresentationVisible
1167
+ + );
1061
1168
  +
1062
- + if (!paused) return null;
1169
+ + if (!visible) return null;
1063
1170
  +
1064
1171
  + // absoluteFill + 默认的 pointerEvents="auto":作为根组件的最后一个兄弟节点
1065
- + // 渲染在用户界面之上,拦截全部触摸,直到暂停解除。
1172
+ + // 渲染在用户界面之上,拦截全部触摸,直到最终更新完成。
1066
1173
  + return (
1067
1174
  + <View style={styles.container}>
1068
1175
  + <ActivityIndicator color="#ffffff" size="large" />
@@ -144,29 +144,55 @@ index 0000000..9b01194
144
144
  + };
145
145
  +}
146
146
  diff --git a/Libraries/LogBox/Data/LogBoxData.js b/Libraries/LogBox/Data/LogBoxData.js
147
- index 2ce92e0..56eb4f8 100644
147
+ index 2ce92e0..da840bd 100644
148
148
  --- a/Libraries/LogBox/Data/LogBoxData.js
149
149
  +++ b/Libraries/LogBox/Data/LogBoxData.js
150
- @@ -146,13 +146,21 @@ function appendNewLog(newLog: LogBoxLog) {
150
+ @@ -139,24 +139,50 @@ function handleUpdate(): void {
151
+ }
152
+ }
153
+
154
+ -function appendNewLog(newLog: LogBoxLog) {
155
+ +// Promise 拒绝仍保留 error 级别,仅改变展示策略;弱引用不延长日志生命周期。
156
+ +const promiseRejectionLogs: WeakSet<LogBoxLog> = new WeakSet();
157
+ +
158
+ +function appendNewLog(newLog: LogBoxLog, isPromiseRejection: boolean = false) {
159
+ // Don't want store these logs because they trigger a
160
+ // state update when we add them to the store.
161
+ if (isMessageIgnored(newLog.message.content)) {
151
162
  return;
152
163
  }
153
164
 
154
165
  - // If the next log has the same category as the previous one
155
166
  - // then roll it up into the last log in the list by incrementing
156
167
  - // the count (similar to how Chrome does it).
157
- + // Only merge logs with the same severity. A fatal exception must retain
158
- + // its own stack and open the inspector even after a matching console error.
168
+ + if (isPromiseRejection) {
169
+ + promiseRejectionLogs.add(newLog);
170
+ + }
171
+ + const shouldOpenInspector = newLog.level === 'fatal' || isPromiseRejection;
172
+ + // 致命错误优先于已打开的非致命详情,但不抢占其他致命错误或语法错误。
173
+ + const shouldSelectLog = () => {
174
+ + const selectedLog = Array.from(logs)[_selectedIndex];
175
+ + return (
176
+ + _selectedIndex < 0 ||
177
+ + (newLog.level === 'fatal' &&
178
+ + selectedLog != null &&
179
+ + selectedLog.level !== 'fatal' &&
180
+ + selectedLog.level !== 'syntax')
181
+ + );
182
+ + };
183
+ + // 相同消息还需匹配级别及来源,避免普通日志吞掉应弹出的 Promise 拒绝。
159
184
  const lastLog = Array.from(logs).pop();
160
185
  - if (lastLog && lastLog.category === newLog.category) {
161
186
  + if (
162
187
  + lastLog &&
163
188
  + lastLog.category === newLog.category &&
164
- + lastLog.level === newLog.level
189
+ + lastLog.level === newLog.level &&
190
+ + promiseRejectionLogs.has(lastLog) === isPromiseRejection
165
191
  + ) {
166
192
  lastLog.incrementCount();
167
193
  - handleUpdate();
168
- + // A repeated uncaught exception must also reopen a hidden inspector.
169
- + if (newLog.level === 'fatal' && _selectedIndex < 0) {
194
+ + // 关闭详情后,同类未捕获异常再次发生时也应重新展示。
195
+ + if (shouldOpenInspector && shouldSelectLog()) {
170
196
  + setSelectedLog(logs.size - 1);
171
197
  + } else {
172
198
  + handleUpdate();
@@ -174,6 +200,32 @@ index 2ce92e0..56eb4f8 100644
174
200
  return;
175
201
  }
176
202
 
203
+ - if (newLog.level === 'fatal') {
204
+ + if (shouldOpenInspector) {
205
+ // If possible, to avoid jank, we don't want to open the error before
206
+ // it's symbolicated. To do that, we optimistically wait for
207
+ // symbolication for up to a second before adding the log.
208
+ @@ -164,7 +190,7 @@ function appendNewLog(newLog: LogBoxLog) {
209
+
210
+ let addPendingLog: ?() => void = () => {
211
+ logs.add(newLog);
212
+ - if (_selectedIndex < 0) {
213
+ + if (shouldSelectLog()) {
214
+ setSelectedLog(logs.size - 1);
215
+ } else {
216
+ handleUpdate();
217
+ @@ -251,7 +277,10 @@ export function addException(error: ExtendedExceptionData): void {
218
+ // otherwise spammy logs would pause rendering.
219
+ setImmediate(() => {
220
+ try {
221
+ - appendNewLog(new LogBoxLog(parseLogBoxException(error)));
222
+ + appendNewLog(
223
+ + new LogBoxLog(parseLogBoxException(error)),
224
+ + error.extraData?.miaodaUnhandledPromiseRejection === true,
225
+ + );
226
+ } catch (loggingError) {
227
+ reportLogBoxError(loggingError);
228
+ }
177
229
  diff --git a/Libraries/LogBox/Data/LogBoxPromptCopy.js b/Libraries/LogBox/Data/LogBoxPromptCopy.js
178
230
  new file mode 100644
179
231
  index 0000000..ceab0e7
@@ -681,3 +733,40 @@ index 48c1b84..41b308d 100644
681
733
  </Text>
682
734
  </View>
683
735
  )}
736
+ diff --git a/Libraries/promiseRejectionTrackingOptions.js b/Libraries/promiseRejectionTrackingOptions.js
737
+ index c14719d..6393f11 100644
738
+ --- a/Libraries/promiseRejectionTrackingOptions.js
739
+ +++ b/Libraries/promiseRejectionTrackingOptions.js
740
+ @@ -36,15 +36,24 @@ let rejectionTrackingOptions: $NonMaybeType<Parameters<enable>[0]> = {
741
+ }
742
+ }
743
+
744
+ - ExceptionsManager.handleException(
745
+ - new Error(
746
+ - `Uncaught (in promise, id: ${id})${message ? `: "${message}"` : ''}`,
747
+ - {
748
+ - cause: rejection,
749
+ - },
750
+ - ),
751
+ - false /* isFatal */,
752
+ + const error = new Error(
753
+ + `Uncaught (in promise, id: ${id})${message ? `: "${message}"` : ''}`,
754
+ + {cause: rejection},
755
+ );
756
+ + // 优先保留拒绝发生处的调用栈,而不是跟踪器延迟回调的内部调用栈。
757
+ + if (
758
+ + rejection != null &&
759
+ + typeof rejection === 'object' &&
760
+ + typeof rejection.stack === 'string'
761
+ + ) {
762
+ + error.stack = `${error.message}\n${rejection.stack}`;
763
+ + }
764
+ + // 标记真实来源,不能根据消息前缀把普通 console.error 误判为 Promise 拒绝。
765
+ + // $FlowFixMe[prop-missing] RN 通过此键将扩展元数据传递给 JS 和 C++ 异常处理链路。
766
+ + error[ExceptionsManager.decoratedExtraDataKey] = {
767
+ + miaodaUnhandledPromiseRejection: true,
768
+ + };
769
+ + ExceptionsManager.handleException(error, false /* isFatal */);
770
+ },
771
+ onHandled: id => {
772
+ const warning =
package/pnpmfile.cjs CHANGED
@@ -11,6 +11,9 @@ const managedPatches = {
11
11
  [REACT_NATIVE_PATCH_SELECTOR]: {
12
12
  filename: 'react-native@0.83.2.patch',
13
13
  legacyHashes: new Set([
14
+ 'd7f25406e993a4d0f2a0f0ee508769ffc630e293456348492f5a1ffa000271d0',
15
+ 'a5cb4e26aa64ec29e7a81bbec0f9ea36bcac15e2eea53b15491cd01095885296',
16
+ '4416d7456eece4b818b0798b04cc71a4f3273a70cf32458749c699d05c779729',
14
17
  '12e2defd1f201b8fd05b318f4f157323f15d25e94358de24e4f03ddad2157023',
15
18
  'bc87e66a7a5c2e0fbe5d1be5c20d1c6b8456e84ea287a1acb15202264b4f2c37',
16
19
  'c03c7638b6393e9876df08f7e9160a9122f00d6e1f1e76e8f4adb4cba3c3b539',
@@ -25,6 +28,11 @@ const managedPatches = {
25
28
  '9a0d662675fba8088396c6cdbab7d36d81fbe9acb3727144a50826ff3500b093',
26
29
  ]),
27
30
  },
31
+ '@expo/metro-runtime@>=55.0.11 <55.0.13': {
32
+ filename: '@expo__metro-runtime@55.0.11-55.0.12.patch',
33
+ legacyHashes: new Set([
34
+ ]),
35
+ },
28
36
  'metro-runtime@0.83.3': {
29
37
  filename: 'metro-runtime@0.83.3.patch',
30
38
  legacyHashes: new Set([
@@ -53,6 +61,13 @@ const managedPatches = {
53
61
  'expo@55.0.6': {
54
62
  filename: 'expo@55.0.6.patch',
55
63
  legacyHashes: new Set([
64
+ '53974f8fd1e682b4da10cbcf0f395996c3734eae2372a9516dee067a3c5ade48',
65
+ '87d5b36485c1e64c4843444aaaf81a37c63eeceb5e3fd49ebf9464f709836da9',
66
+ '9c01c660c3bf23a1d00fd9d3ceb902e256d9241224227acf3ae4c13b6ff499f4',
67
+ 'be8acb91becb6d4a3c9a898d75aef71d06d208bc370bf576aa786286a00ccda7',
68
+ '83ae82f4dbe0ead362f24d891310a129a72df6fc3d1450aa0697c5f3151e4e9a',
69
+ 'fd9ffc51138fad126266f1f786671201cdd793a7e2386c0dc311e097dcdfdf62',
70
+ '8e63bb43a9edc12a4b0839346a1fa211fee64933aa8d4a8711e0ced434516fb5',
56
71
  '8918e9d5c443bf0d5149e5fff2714bf241447d3448e5f568a6669a3cdbf220ac',
57
72
  '612203c64a1fa24a2dd6a402bc3dad8cccdcbfa1185c4535abed741a31e18d12',
58
73
  // 0.1.1-dev.development-build.8 发布时的哈希;合并远端遮罩文案修正后迁移。
@@ -81,12 +96,6 @@ const managedPatches = {
81
96
  'b2c55038b2fa525ad5e84bd4940ddd2b7298b559de2d0d1709f32ced57e929e9',
82
97
  ]),
83
98
  },
84
- 'react-native@0.83.2': {
85
- filename: 'react-native@0.83.2.patch',
86
- legacyHashes: new Set([
87
- '4416d7456eece4b818b0798b04cc71a4f3273a70cf32458749c699d05c779729',
88
- ]),
89
- },
90
99
  'react-native-worklets@0.7.4': {
91
100
  filename: 'react-native-worklets@0.7.4.patch',
92
101
  legacyHashes: new Set([