Skip to content

Conversation

lupingW
Copy link

@lupingW lupingW commented Sep 24, 2025

这个 PR 做了什么? (简要描述所做更改)
修复微信小程序React的dangerouslySetInnerHTML无法渲染span标签

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

这个 PR 涉及以下平台:

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

Summary by CodeRabbit

  • 新特性

  • 缺陷修复

    • 修复在特定场景下对 元素渲染不正确的问题,提升 innerHTML 渲染一致性与兼容性。
  • 其他

    • 不涉及任何对外 API 变更,现有功能与接口保持不变。

Copy link

coderabbitai bot commented Sep 24, 2025

Walkthrough

更新了 inner HTML 标签分类逻辑:在构建 internalCompsList 时过滤掉小写的 'span',使 isMiniElements 不再包含 'span'。无导出/公共 API 签名变更。

Changes

Cohort / File(s) Summary
Inner HTML 标签分类
packages/taro-runtime/src/dom-external/inner-html/tags.ts
构建 internalCompsList 时排除 'span',从而使 isMiniElements 不再包含 'span';仅影响内部标签判断逻辑,未改动任何导出签名。

Sequence Diagram(s)

sequenceDiagram
    autonumber
    actor Dev as App(React)
    participant R as Taro Runtime
    participant P as InnerHTML 解析器
    participant C as 标签分类器
    participant V as 宿主视图树

    Dev->>R: dangerouslySetInnerHTML({ __html: "<span>...</span>" })
    R->>P: 解析 HTML 片段
    P->>C: 判定标签类型("span")
    Note over C: 'span' 已从 isMiniElements 中移除
    alt 标签在 isMiniElements 中
        C-->>R: 作为小程序内置组件
        R->>V: 创建内置组件节点
    else 标签不在 isMiniElements 中 (当前分支)
        C-->>R: 作为普通原生元素
        R->>V: 创建标准元素节点 <span>…</span>
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

小兔抖耳敲键盘,
一剪“span”出圈还。
内置名册轻轻减,
内联文本自在还。
微信也把字儿显,
代码跳跃像春山。 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title Check ✅ Passed 标题简洁且切中要点,明确说明本次变更的主要目的为修复微信小程序平台在使用 React 的 dangerouslySetInnerHTML 时无法渲染 span 标签的问题,且与提交修改(packages/taro-runtime/src/dom-external/inner-html/tags.ts)的意图一致,能让审阅者快速理解主要变更。
Linked Issues Check ✅ Passed 根据变更摘要,提交在 packages/taro-runtime/src/dom-external/inner-html/tags.ts 中移除了 internalCompsList 中的小写 'span' 条目,使 isMiniElements 不再包含 span,从而允许 dangerouslySetInnerHTML 正常渲染 span,这直接对应并解决了 issue [#17747] 中描述的渲染缺失问题;提交未修改导出 API 且变更范围有限,因而从代码层面满足该 issue 的主要目标。
Out of Scope Changes Check ✅ Passed 变更摘要仅显示对 inner-html 标签识别逻辑(tags.ts)的调整,未见对其他无关模块或平台代码的修改,因此不存在明显的与 linked issue 无关的变更。
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


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: 0

🧹 Nitpick comments (2)
packages/taro-runtime/src/dom-external/inner-html/tags.ts (2)

20-23: 修复方向正确:从 isMiniElements 中排除 span,解锁 dangerouslySetInnerHTML 正常渲染

这样会让 span 走 HTML 渲染路径而非被误判为小程序内部组件,符合 PR 目标。建议补充注释与回归用例以防回归。

  • 建议在此处加注释,说明为何排除 span(关联 #17747),避免后续合并时误删。可直接应用:
 const internalCompsList = Object.keys(internalComponents)
   .map(i => i.toLowerCase())
-  .filter(i => i !== 'span')
+  // 排除 span:在微信小程序端需将其作为普通内联 HTML 处理,否则 dangerouslySetInnerHTML 会被拦截(见 #17747)
+  .filter(i => i !== 'span')
   .join(',')
  • 请在 weapp + React 下补一个回归测试:dangerouslySetInnerHTML 注入包含 (含内联样式/嵌套文本)的 HTML,断言 span 及内容正常渲染。
  • 若该模块跨端共用,请简单回归其它小程序端(如支付宝/抖音)以确认无副作用。

29-29: 去重小优化:isInlineElements 中 "mark" 出现两次

不影响功能,但建议去重,减少维护噪音。

-export const isInlineElements = makeMap('a,i,abbr,iframe,select,acronym,slot,small,span,bdi,kbd,strong,big,map,sub,sup,br,mark,mark,meter,template,canvas,textarea,cite,object,time,code,output,u,data,picture,tt,datalist,var,dfn,del,q,em,s,embed,samp,b', true)
+export const isInlineElements = makeMap('a,i,abbr,iframe,select,acronym,slot,small,span,bdi,kbd,strong,big,map,sub,sup,br,mark,meter,template,canvas,textarea,cite,object,time,code,output,u,data,picture,tt,datalist,var,dfn,del,q,em,s,embed,samp,b', true)
```<!-- review_comment_end -->
<!-- file_end -->

</blockquote></details>

</blockquote></details>

<details>
<summary>📜 Review details</summary>

**Configuration used**: CodeRabbit UI

**Review profile**: CHILL

**Plan**: Pro

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between 8ff04a2cec2f1e25c91ac3687317b90b29d60bcc and 62fc327488fa6d8bf9f52e690b14a51cfdda8777.

</details>

<details>
<summary>📒 Files selected for processing (1)</summary>

* `packages/taro-runtime/src/dom-external/inner-html/tags.ts` (1 hunks)

</details>

<details>
<summary>⏰ 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). (5)</summary>

* GitHub Check: Build Rust Binding / stable - x86_64-unknown-linux-gnu
* GitHub Check: Build Rust Binding / stable - aarch64-apple-darwin
* GitHub Check: Build Rust Binding / stable - x86_64-apple-darwin
* GitHub Check: Build Rust Binding / stable - x86_64-pc-windows-msvc
* GitHub Check: Build Rust WASM / stable - wasm32-wasi

</details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

Copy link

codecov bot commented Sep 24, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 55.98%. Comparing base (8ff04a2) to head (62fc327).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #18386   +/-   ##
=======================================
  Coverage   55.97%   55.98%           
=======================================
  Files         416      416           
  Lines       21560    21561    +1     
  Branches     5264     5289   +25     
=======================================
+ Hits        12069    12070    +1     
+ Misses       7907     7874   -33     
- Partials     1584     1617   +33     
Flag Coverage Δ
taro-cli 72.85% <ø> (ø)
taro-runtime 59.90% <100.00%> (+0.03%) ⬆️
taro-web 53.13% <ø> (ø)

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

Files with missing lines Coverage Δ
...s/taro-runtime/src/dom-external/inner-html/tags.ts 100.00% <100.00%> (ø)

... and 11 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.


const internalCompsList = Object.keys(internalComponents)
.map(i => i.toLowerCase())
.filter(i => i !== 'span')
Copy link
Contributor

Choose a reason for hiding this comment

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

感觉可能不止这一个,另,这个好加用例吗?

This was referenced Sep 27, 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 标签

2 participants