Skip to content

Conversation

@lupingW
Copy link
Contributor

@lupingW lupingW commented Oct 28, 2025

这个 PR 做了什么? (简要描述所做更改)
微信小程序skyline模式下有span标签, 而h5也有span标签. 在用react的dangerouslySetInnerHTML解析html字符串模版时,不知道用哪一个去解析. 本次只要在有命名冲突的标签上增加attribute属性(skyline-mode), 则用skylin标签渲染,否则依旧转为view和text进行渲染.

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

这个 PR 涉及以下平台:

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

Summary by CodeRabbit

发布说明

  • 性能优化
    • 优化了迷你元素的渲染逻辑,支持 skyline-mode 属性控制元素渲染方式。启用 skyline-mode 时,块级和行内迷你元素将按原始标签类型渲染,而非通用容器。

@coderabbitai
Copy link

coderabbitai bot commented Oct 28, 2025

概览

修改了 innerHTML 解析器,使 getTagName 函数能够根据元素属性判断是否启用 skyline 模式。当块级/内联迷你元素包含 skyline-mode 属性时,返回原始标签名,否则返回通用包装标签(view/text)。

变更内容

内聚 / 文件 变更摘要
innerHTML 解析器增强
packages/taro-runtime/src/dom-external/inner-html/parser.ts
扩展 getTagName 函数签名以接收 attributes 参数;新增逻辑处理块级迷你元素(有 skyline-mode 属性时返回原始标签,否则返回 'view')和内联迷你元素(有 skyline-mode 属性时返回原始标签,否则返回 'text');创建子元素时将属性传递至 getTagName 调用

工作流程图

sequenceDiagram
    participant Parser
    participant getTagName
    participant Document
    
    Parser->>Parser: 解析 HTML 元素
    Parser->>getTagName: getTagName(tagName, attributes)
    
    alt 块级迷你元素 + skyline-mode
        getTagName->>getTagName: 返回原始标签
    else 块级迷你元素
        getTagName->>getTagName: 返回 'view'
    else 内联迷你元素 + skyline-mode
        getTagName->>getTagName: 返回原始标签
    else 内联迷你元素
        getTagName->>getTagName: 返回 'text'
    else 其他
        getTagName->>getTagName: 返回原始标签
    end
    
    getTagName->>Parser: 返回解析后的标签名
    Parser->>Document: createElement(解析后的标签名)
    Document->>Parser: 返回 DOM 元素
Loading

预估代码审查工作量

🎯 2 (Simple) | ⏱️ ~12 分钟

  • 变更集中在单个文件,涉及函数签名扩展和条件逻辑补充
  • 需要关注 skyline-mode 属性的判断逻辑是否完整
  • 验证块级和内联元素的处理流程是否正确覆盖所有场景

建议审查者

  • tutuxxx
  • Single-Dancer

诗句

🐰 小小解析器,迎来新变化
Skyline 模式来助力,span 标签终有其家
属性层层传递,innerHTML 从此展笑颜
微信小程序不再惆怅,新的渲染就在眼前!

Pre-merge checks and finishing touches

❌ 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%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ 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 标签和 H5 标签的命名冲突、Taro 默认使用小程序标签渲染,以及项目可能未开启 skyline 模式导致的 HTML 模板字符串渲染异常。标题与代码变更直接相关,代码通过在 getTagName 函数中增加对 skyline-mode 属性的判断逻辑来解决这个问题,标题准确反映了修复的主要改动。
Linked Issues Check ✅ Passed 代码变更完全满足关联 Issue #17747 的需求。该 Issue 报告的问题是 dangerouslySetInnerHTML 中的 span 标签在微信小程序中无法渲染,而此 PR 通过修改 getTagName 函数逻辑来解决:当元素包含 skyline-mode 属性时,使用原始标签(如 span);否则降级为通用标签(inline 元素用 text,block 元素用 view)。这正是区分 skyline 模式和非 skyline 模式的关键,直接修复了 span 标签的渲染问题。
Out of Scope Changes Check ✅ Passed 所有代码变更均在 packages/taro-runtime/src/dom-external/inner-html/parser.ts 文件中,包括 getTagName 函数签名扩展、skyline-mode 属性判断逻辑的添加以及 createElement 调用的相应更新。这些变更都直接针对解决 Issue #17747 中 span 标签渲染问题所需的功能,没有发现与关联 Issue 无关的变更。
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 66cef71 and d970cd7.

📒 Files selected for processing (1)
  • packages/taro-runtime/src/dom-external/inner-html/parser.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Build Rust WASM / stable - wasm32-wasi
  • GitHub Check: Build Rust Binding / stable - x86_64-unknown-linux-gnu
  • GitHub Check: Build Rust Binding / stable - x86_64-unknown-linux-musl
  • GitHub Check: Build Rust Binding / stable - x86_64-apple-darwin
  • GitHub Check: Build Rust Binding / stable - aarch64-apple-darwin
  • GitHub Check: Build Rust Binding / stable - x86_64-pc-windows-msvc
🔇 Additional comments (2)
packages/taro-runtime/src/dom-external/inner-html/parser.ts (2)

139-139: 函数调用更新正确。

正确地将 child.attributes 传递给 getTagName 函数,类型安全得到保障(Element 接口中 attributes 定义为必需的 string[])。


74-97: 第 90 行代码是必需的,非死代码。

验证表明:internalComponents 包含 41 个小程序自定义组件(如 view、icon、progress、swiper 等),其中仅 form、block、textarea、canvas、map、slot 等少数几个被纳入标准 HTML block/inline 元素列表。大多数自定义组件(超过 35 个)既不属于 block 也不属于 inline 类别。

第 90 行的 return tag 正是为这些自定义小程序组件提供必要的回退逻辑,确保它们作为原始标签名返回。代码设计完全正确,无需修改。

@codecov
Copy link

codecov bot commented Oct 28, 2025

Codecov Report

❌ Patch coverage is 66.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 55.97%. Comparing base (8ff04a2) to head (d970cd7).
⚠️ Report is 16 commits behind head on main.

Files with missing lines Patch % Lines
...taro-runtime/src/dom-external/inner-html/parser.ts 66.66% 2 Missing ⚠️

❌ Your patch check has failed because the patch coverage (66.66%) is below the target coverage (75.00%). You can increase the patch coverage or adjust the target coverage.
❌ Your project check has failed because the head coverage (55.97%) is below the target coverage (75.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #18536      +/-   ##
==========================================
- Coverage   55.97%   55.97%   -0.01%     
==========================================
  Files         416      416              
  Lines       21560    21564       +4     
  Branches     5264     5307      +43     
==========================================
+ Hits        12069    12071       +2     
+ Misses       7907     7876      -31     
- Partials     1584     1617      +33     
Flag Coverage Δ
taro-cli 72.85% <ø> (ø)
taro-runtime 59.83% <66.66%> (-0.04%) ⬇️
taro-web 53.13% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...taro-runtime/src/dom-external/inner-html/parser.ts 78.91% <66.66%> (-0.81%) ⬇️

... and 8 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This was referenced Nov 1, 2025
This was referenced Nov 15, 2025
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.

[Bug]: dangerouslySetInnerHTML 无法渲染 span 标签

1 participant