Skip to content

fix: black screen when using routeType with navigateTo in Skyline mode#18883

Open
Everestbs wants to merge 2 commits intoNervJS:mainfrom
Everestbs:fix/skyline-navigateto-black-screen
Open

fix: black screen when using routeType with navigateTo in Skyline mode#18883
Everestbs wants to merge 2 commits intoNervJS:mainfrom
Everestbs:fix/skyline-navigateto-black-screen

Conversation

@Everestbs
Copy link

@Everestbs Everestbs commented Feb 13, 2026

这个 PR 做了什么? (简要描述所做更改)

修复 Skyline 渲染模式下使用 navigateTo 配置 routeType 参数导致页面黑屏的问题。

在 Skyline 模式下,当调用 Taro.navigateTo({ url, routeType: 'wx://upwards' }) 时,Taro 运行时会尝试在 JavaScript 层应用动画样式,但 Skyline 的节点存在于原生渲染层,导致 [ui] applyAnimatedStyle can not find corresponding nodes 错误,页面黑屏崩溃。

本次修复通过检测 Skyline 模式并直接调用微信原生 wx.navigateTo API,绕过 Taro 运行时的动画处理层,彻底解决该问题。

这个 PR 是什么类型? (至少选择一个)

这个 PR 涉及以下平台:

  • 所有平台
  • Web 端(H5)
  • 移动端(React-Native)
  • 鸿蒙(Harmony)
  • 鸿蒙容器(Harmony Hybrid)
  • ASCF 元服务
  • 快应用(QuickApp)
  • 所有小程序
  • 微信小程序
  • 企业微信小程序
  • 京东小程序
  • 百度小程序
  • 支付宝小程序
  • 支付宝 IOT 小程序
  • 钉钉小程序
  • QQ 小程序
  • 飞书小程序
  • 快手小程序
  • 头条小程序

问题描述

Closes #18879

现象:在微信小程序 Skyline 渲染模式下,使用 navigateTo 配置 routeType 参数进行页面跳转时,触发以下错误并导致页面黑屏:

Summary by CodeRabbit

  • 新功能
    • 为 Skyline 渲染模式下的页面跳转增加兼容处理:在检测到 Skyline 路由类型时使用原生跳转以提升渲染模式下的导航可靠性。
    • 在非 Skyline 情况下回退到既有跳转行为,且保持云能力、底部栏与渲染器相关接口的现有行为不变。

@coderabbitai
Copy link

coderabbitai bot commented Feb 13, 2026

Walkthrough

在 WeChat 小程序平台的 API 中覆盖了 taro.navigateTo,在检测到带有 Skyline 渲染标记的 routeType 时,将跳转委托给原生 wx.navigateTo(Promise 封装),否则回退到原始实现。

Changes

Cohort / File(s) Summary
Skyline 渲染支持
packages/taro-platform-weapp/src/apis.ts
新增对 taro.navigateTo 的运行时覆盖:检测 options.routeType(Skyline 场景)并通过 Promise 调用 wx.navigateTo(success/fail/complete 映射到 resolve/reject/finally);非 Skyline 情况回退到原始 navigateTo。保留 taro.cloudtaro.getTabBartaro.getRenderer 行为不变。

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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰
天光洒进小程序,
小径换了新花纹,
跳转轻轻不再黑,
兔尾摇摇把路引,
Skyline 里春意真。

🚥 Pre-merge checks | ✅ 5 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: fixing black screen issue when using routeType with navigateTo in Skyline mode, which directly matches the PR's primary objective.
Linked Issues check ✅ Passed The code changes implement the required fix: detecting Skyline mode and routing navigation through native wx.navigateTo to bypass JS animation handling that causes the black screen error described in #18879.
Out of Scope Changes check ✅ Passed All changes are scoped to the navigateTo API override for Skyline mode support; no unrelated modifications to other APIs or functionality detected.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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 以应用这些改动。

Comment on lines 39 to 53
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
})
})
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

fail 路径中 reject 可能不会执行;complete 的处理方式与 success/fail 不一致

两个问题:

  1. 如果用户提供的 fail 回调抛出异常(第 48 行),reject(err) 将不会执行,导致 Promise 永远处于 pending 状态。
  2. complete 直接透传给 wx(第 51 行),而 successfail 则被包装过。如果将来需要在 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 以应用这些改动。

@Everestbs
Copy link
Author

Hi @Single-Dancer 您好!
能否帮忙审阅一下这个 PR?期待您的审阅意见!

@Single-Dancer Single-Dancer added this to the 4.1.12 milestone Feb 26, 2026
This was referenced Feb 28, 2026
@Everestbs
Copy link
Author

Everestbs commented Mar 2, 2026

Hi @Single-Dancer 您好!
如果没有问题,能否请您合并我的PR?

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.

skyline 模式下navigateTo配置routeType跳转,导致页面黑屏报错

2 participants