Skip to content

fix(devtools): 新开页面收不到 pageShow、切设备收不到 onResize - #201

Merged
lbb00 merged 3 commits into
mainfrom
fix/fresh-page-show-lifecycle
Sep 7, 2026
Merged

fix(devtools): 新开页面收不到 pageShow、切设备收不到 onResize#201
lbb00 merged 3 commits into
mainfrom
fix/fresh-page-show-lifecycle

Conversation

@lbb00

@lbb00 lbb00 commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

现象

在 devtools 模拟器里首次打开一个页面,它的 onShow/onReady 不会触发,要等一次 navigateBack 回来才补上。切换机型或横竖屏后,Page.onResize 从来不跑。原因是 kit 侧从没给新页发过 pageShow,也没有任何地方产生 pageResize

改动

  • 页面栈:新增 revealTopEffects,frame 首次变为可见时给真实栈顶发一次 pageShow。软重载时新 shell 先隐藏挂载,这段时间里 frame 只向 service 转发 pageUnload/closePage,不发 pageShow/pageHide,激活后再统一补一次栈顶的 pageShow
  • 设备变更bridge.setDevice 之后按会话发 hostEnvUpdatepageResize(几何或朝向变了且有可见页时才发)。启动时按当前选中设备合成 hostEnv,新会话不会再拿到旧机型的窗口尺寸。
  • service 就绪前的消息排队forwardToService 在会话就绪前把消息按到达顺序压进队列,bootServiceHost 确认 TO_SERVICE 监听已装好后一次性 flush。此前 handleSpawn 返回时 service 窗口还没 did-finish-load,消息落在还没装监听的预热 preload 上被 Electron 直接丢掉——而新开页的 launch pageShow 只发一次、不重试。池化与全新窗口两条 spawn 路径都汇入这同一处;就绪前被 dispose 的会话不重放。
  • service-host preload:入站消息改为单一 FIFO(service-message-queue.cjs),hostEnvUpdate 在真正派发给 service 的那一刻才合并进 hostEnvSnapshot。这样排队中的 pageResizeonResize 里调 wx.getSystemInfoSync() 拿到的尺寸和事件尺寸一致。重入 deliverbeforeDispatch 或 handler 抛错都不会乱序或丢消息。
  • 异步 system-info 跟随设备getSystemSettingdeviceOrientation 改从 deviceInfoToHostEnv 派生,与同步的 getSystemInfoSync 同源,不再在同一个 onResize 回调里给出互相矛盾的朝向。
  • 删除单独的 service-host:host-env:update IPC 通道,设备变更只剩 setDevice 一条路。

已知限制

上游 service 在页面实例还没建好时收到 pageResize 会直接丢弃,没有像 pageShow 那样的 pending 重放。页面创建完成前切设备的那一次 resize 会丢,文档里已注明是上游行为。

另有一个 main 上既有的问题本 PR 未处理:软重载中的 shell 被下一次重载替换或等 DOM 就绪超时时,存活页面收不到 pageUnload(webview 会被物理关闭,但 Page.onUnload 不执行)。这段卸载逻辑本 PR 没有改动。

验证

  • 单测:runtime 新增 page-stack-controller-fresh-showminiapp-frame-fresh-page-showbridge-router-page-resizebridge-router-spawn-device;devtools 新增 host-env-updateservice-message-queue(含重入顺序与 beforeDispatch 抛错用例),先红后绿。
  • ./scripts/gate.sh:lint / typecheck / test / pawl 四项全过(pawl file-length 棘轮保持 55,未重录基线)。
  • runtime build:package 后 e2e:native-host-page-lifecycle.spec.ts(新增,覆盖首页 onShow/onReady、navigateTo 后子页 onShow、切设备后 onResize 且 getSystemInfoSync 与事件尺寸一致)+ native-host-device.spec.ts,6/6 通过。
  • 本分支已 rebase 到 main。rebase 后 NativeDeviceInfo.orientation 成为必填、setDevice 直接读它,e2e 的设备工厂还是旧形状,表现为 onResize 拿到 deviceOrientation: undefined;e2e 目录不在 typecheck 范围内,这个不匹配只有真跑才暴露,已一并修正。
  • codex 四轮评审:第一轮 4 条、第二轮 2 条、第三轮 2 条、第四轮 2 条 finding 均已修复并有回归测试;第三轮另 1 条即上面的既有卸载问题。

🤖 Generated with Claude Code

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 4, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-04T15:22:28.543861Z cc7ffb9 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cc7ffb93b7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/dimina-electron-runtime/src/main/ipc/bridge-router-device-geometry.ts Outdated
Comment thread packages/dimina-electron-runtime/src/simulator-ui/miniapp-frame.tsx
lbb00 and others added 2 commits September 7, 2026 11:59
模拟器里首次打开的页面从未收到 pageShow,onShow/onReady 要等一次 navigateBack 才触发;切换设备也没有任何一方派发 pageResize,Page.onResize 永远不跑。

- 页面栈控制器新增 revealTopEffects,frame 首次激活时对真实栈顶发 pageShow;未激活(软重载中隐藏挂载)的 frame 不向 service 发 pageShow/pageHide,只放行 pageUnload/closePage。
- bridge.setDevice 后按会话发 hostEnvUpdate 与 pageResize,spawn 时按当前设备合成 hostEnv,可见页才收 resize。
- service-host preload 的入站消息改为单一 FIFO(service-message-queue.cjs),hostEnvUpdate 在派发瞬间合并进 hostEnvSnapshot,排队中的 pageResize 在 onResize 里读到的 getSystemInfoSync 与事件尺寸一致;beforeDispatch 或 handler 抛错都不丢消息。
- 删除独立的 service-host:host-env:update 通道,设备变更只走 setDevice 一条路。

上游 service 对无实例时的 pageResize 直接丢弃、没有 pendingResize,属上游限制,文档已注明。

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
新开页面的 launch pageShow 只发一次、不重试。此前 handleSpawn 返回时 service
窗口还没 did-finish-load,forwardToService 没有任何就绪判断就 send 出去,消息
落在还没装 TO_SERVICE 监听的预热 preload 上,被 Electron 直接丢掉。现在会话就
绪前的消息按到达顺序排队,bootServiceHost 确认监听已装后一次 flush;就绪前被
dispose 的会话不重放。池化和全新窗口两条 spawn 路径都汇入这同一处。

getSystemSetting 的 deviceOrientation 改从 deviceInfoToHostEnv 派生,与同步的
getSystemInfoSync 同源,不再在同一个 onResize 回调里给出互相矛盾的朝向。

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@lbb00
lbb00 force-pushed the fix/fresh-page-show-lifecycle branch from cc7ffb9 to 06c7eb3 Compare September 7, 2026 04:43
NativeDeviceInfo 现在要求 orientation,setDevice 直接读它、不再从宽高反推。e2e 目录不在 typecheck 范围内,这个旧形状(带 notchType、缺 orientation)在门禁里是隐形的,只在真跑 native-host e2e 时表现为 onResize 的 deviceOrientation 为 undefined。
@lbb00
lbb00 merged commit 42f0dc2 into main Sep 7, 2026
2 checks passed
@lbb00
lbb00 deleted the fix/fresh-page-show-lifecycle branch September 7, 2026 05:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant