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
Copy Markdown

@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
Copy Markdown

coderabbitai Bot commented Feb 13, 2026

Walkthrough

在 WeChat 小程序平台的 API 初始化中,保存原始 taro.navigateTo 并以包装器替换:当传入 options.routeTypetaro.getRenderer?.() 返回 'skyline' 时,使用原生 wx.navigateTo(Promise 封装并映射 success/fail/complete);否则调用原始实现。

Changes

Cohort / File(s) Summary
Skyline 跳转处理
packages/taro-platform-weapp/src/apis.ts
保存原始 taro.navigateTo 并替换为包装实现:若 options.routeType 存在且渲染器为 skyline,则调用 wx.navigateTo 并以 Promise 返回(映射 success/fail/complete);其它情况回退到原始 navigateTo。未修改其他公开 API(如 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 存在 且 renderer === 'skyline'
        Taro->>WX: wx.navigateTo({ url, routeType }, callbacks)
        WX-->>Taro: success / fail / complete
        Taro-->>App: Promise resolve / reject
    else
        Taro->>Taro: originalNavigateTo.call(taro, options)
        Taro-->>App: 原始返回值/行为
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰
天光穿过渲染云,
跳转路由轻轻巡,
若见 Skyline 指明路,
便托原生把门柬,
兔耳一摆笑迎春。

🚥 Pre-merge checks | ✅ 4 | ❌ 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 (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题清晰准确地描述了PR的主要改动:修复在Skyline模式下使用routeType的navigateTo导致黑屏的问题。
Linked Issues check ✅ Passed PR实现了issue #18879的主要目标:在Skyline模式下检测到routeType时,直接调用原生wx.navigateTo绕过Taro的JS动画处理层,避免节点查找错误。
Out of Scope Changes check ✅ Passed 所有改动仅限于覆盖taro.navigateTo以实现Skyline模式的特殊处理,与issue #18879的需求完全对齐,没有发现范围外的改动。

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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
Copy Markdown

@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
Copy Markdown

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
Copy Markdown
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
Copy Markdown
Author

Everestbs commented Mar 2, 2026

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

@Single-Dancer Single-Dancer force-pushed the fix/skyline-navigateto-black-screen branch from b0cc5b5 to 0191020 Compare April 13, 2026 03:22
Copy link
Copy Markdown

@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.

♻️ Duplicate comments (1)
packages/taro-platform-weapp/src/apis.ts (1)

48-60: ⚠️ Potential issue | 🟠 Major

回调异常会打断 Promise settle,仍可能出现 pending

在 Line 49/50/59,success/complete 的异常未被完整隔离;若用户回调抛错,resolve/reject 可能不执行,调用方会卡住。建议统一做“安全回调 + 保证 settle”。

建议修改
       if (renderer === 'skyline') {
         return new Promise((resolve, reject) => {
           const { success, fail, complete, ...restOptions } = options
+          const safeCall = (cb, arg) => {
+            try {
+              cb?.(arg)
+            } catch (e) {
+              // ignore user callback errors to avoid breaking promise settlement
+            }
+          }
           wx.navigateTo({
             ...restOptions,
             success: (res) => {
-              success?.(res)
-              complete?.(res)
+              safeCall(success, res)
+              safeCall(complete, res)
               resolve(res)
             },
             fail: (err) => {
-              try {
-                fail?.(err)
-              } catch (e) {
-                // ignore
-              }
-              complete?.(err)
+              safeCall(fail, err)
+              safeCall(complete, err)
               reject(err)
             }
           })
         })
       }

Based on learnings: 在 Taro 的 getRectSizeSync 函数中,如果找不到指定的节点,函数会一直处于 pending 状态而不是抛出错误,需要避免无限等待。

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/taro-platform-weapp/src/apis.ts` around lines 48 - 60, The Promise
can remain pending if user-provided callbacks (success/complete/fail) throw; to
fix, ensure resolve/reject always run regardless of callback errors by invoking
resolve(res)/reject(err) before calling user callbacks or by wrapping user calls
in try/catch (safeInvoke) and then settling the Promise; update the handlers in
apis.ts for the success, fail and complete paths (the success: (res) => { ... },
fail: (err) => { ... } blocks) to guarantee resolve(res)/reject(err) is executed
even if success/fail/complete throw, and optionally extract a small helper
(e.g., safeInvoke(callback, arg)) to centralize the try/catch.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@packages/taro-platform-weapp/src/apis.ts`:
- Around line 48-60: The Promise can remain pending if user-provided callbacks
(success/complete/fail) throw; to fix, ensure resolve/reject always run
regardless of callback errors by invoking resolve(res)/reject(err) before
calling user callbacks or by wrapping user calls in try/catch (safeInvoke) and
then settling the Promise; update the handlers in apis.ts for the success, fail
and complete paths (the success: (res) => { ... }, fail: (err) => { ... }
blocks) to guarantee resolve(res)/reject(err) is executed even if
success/fail/complete throw, and optionally extract a small helper (e.g.,
safeInvoke(callback, arg)) to centralize the try/catch.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b472a016-b077-4462-a29d-b57be515e4f3

📥 Commits

Reviewing files that changed from the base of the PR and between b0cc5b5 and 0191020.

📒 Files selected for processing (1)
  • packages/taro-platform-weapp/src/apis.ts

@Single-Dancer Single-Dancer removed this from the 4.2.0 milestone Apr 13, 2026
This was referenced Apr 18, 2026
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