fix: black screen when using routeType with navigateTo in Skyline mode#18883
fix: black screen when using routeType with navigateTo in Skyline mode#18883Everestbs wants to merge 2 commits intoNervJS:mainfrom
Conversation
Walkthrough在 WeChat 小程序平台的 API 中覆盖了 Changes
Sequence Diagram(s)sequenceDiagram
participant App as "调用方 (App)"
participant Taro as "taro.navigateTo"
participant WX as "wx.navigateTo (原生)"
App->>Taro: navigateTo({ url, routeType })
alt routeType 是 Skyline
Taro->>WX: wx.navigateTo({ url, routeType }, callbacks)
WX-->>Taro: success / fail / complete
Taro-->>App: Promise resolve / reject
else 非 Skyline
Taro->>Taro: 调用 originalNavigateTo(options)
Taro-->>App: 原始返回值/行为
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@packages/taro-platform-weapp/src/apis.ts`:
- Around line 39-53: 当前 wx.navigateTo 包装没有保护用户回调:调用 success/fail
前直接执行用户回调可能会抛出,导致 resolve/reject 不被调用,且 complete 未被统一包装。修改 wx.navigateTo
包装逻辑(在包裹的函数中操作 options 的 success/fail/complete)将 success/fail/complete
三个回调都用内部封装替换;在 success 回调中用 try/catch/ finally 或先行 resolve 再调用用户
success(或将用户回调包在 try/catch 并在 finally 中 resolve),在 fail 回调中保证不论用户 fail 回调是否抛出都执行
reject(即在 try { userFail?.(err) } catch{} finally { reject(err) }),并把 complete
也替换为内部函数(在 resolve/reject 后统一调用用户 complete 并用 try/catch 包裹),并在代码中定位到 options,
wx.navigateTo, success, fail, complete 以应用这些改动。
| return new Promise((resolve, reject) => { | ||
| const { success, fail, complete, ...restOptions } = options | ||
| wx.navigateTo({ | ||
| ...restOptions, | ||
| success: (res) => { | ||
| success?.(res) | ||
| resolve(res) | ||
| }, | ||
| fail: (err) => { | ||
| fail?.(err) | ||
| reject(err) | ||
| }, | ||
| complete | ||
| }) | ||
| }) |
There was a problem hiding this comment.
fail 路径中 reject 可能不会执行;complete 的处理方式与 success/fail 不一致
两个问题:
- 如果用户提供的
fail回调抛出异常(第 48 行),reject(err)将不会执行,导致 Promise 永远处于 pending 状态。 complete直接透传给 wx(第 51 行),而success和fail则被包装过。如果将来需要在complete中添加逻辑(或保证与 resolve/reject 的执行顺序一致),当前写法不便扩展。
建议统一包装所有回调,并对 fail 分支做防护处理:
🛠️ 建议修改
return new Promise((resolve, reject) => {
const { success, fail, complete, ...restOptions } = options
wx.navigateTo({
...restOptions,
success: (res) => {
success?.(res)
+ complete?.(res)
resolve(res)
},
fail: (err) => {
- fail?.(err)
- reject(err)
+ try {
+ fail?.(err)
+ } catch (e) {
+ // ignore
+ }
+ complete?.(err)
+ reject(err)
},
- complete
})
})🤖 Prompt for AI Agents
In `@packages/taro-platform-weapp/src/apis.ts` around lines 39 - 53, 当前
wx.navigateTo 包装没有保护用户回调:调用 success/fail 前直接执行用户回调可能会抛出,导致 resolve/reject 不被调用,且
complete 未被统一包装。修改 wx.navigateTo 包装逻辑(在包裹的函数中操作 options 的
success/fail/complete)将 success/fail/complete 三个回调都用内部封装替换;在 success 回调中用
try/catch/ finally 或先行 resolve 再调用用户 success(或将用户回调包在 try/catch 并在 finally 中
resolve),在 fail 回调中保证不论用户 fail 回调是否抛出都执行 reject(即在 try { userFail?.(err) }
catch{} finally { reject(err) }),并把 complete 也替换为内部函数(在 resolve/reject 后统一调用用户
complete 并用 try/catch 包裹),并在代码中定位到 options, wx.navigateTo, success, fail,
complete 以应用这些改动。
|
Hi @Single-Dancer 您好! |
|
Hi @Single-Dancer 您好! |
这个 PR 做了什么? (简要描述所做更改)
修复 Skyline 渲染模式下使用
navigateTo配置routeType参数导致页面黑屏的问题。在 Skyline 模式下,当调用
Taro.navigateTo({ url, routeType: 'wx://upwards' })时,Taro 运行时会尝试在 JavaScript 层应用动画样式,但 Skyline 的节点存在于原生渲染层,导致[ui] applyAnimatedStyle can not find corresponding nodes错误,页面黑屏崩溃。本次修复通过检测 Skyline 模式并直接调用微信原生
wx.navigateToAPI,绕过 Taro 运行时的动画处理层,彻底解决该问题。这个 PR 是什么类型? (至少选择一个)
这个 PR 涉及以下平台:
问题描述
Closes #18879
现象:在微信小程序 Skyline 渲染模式下,使用
navigateTo配置routeType参数进行页面跳转时,触发以下错误并导致页面黑屏:Summary by CodeRabbit