fix: 修复微信skyline标签和h5标签命名冲突时, taro默认使用小程序标签渲染. 但是项目可能没有开启skyline模式, 导致渲染html模版字符串异常#18536
fix: 修复微信skyline标签和h5标签命名冲突时, taro默认使用小程序标签渲染. 但是项目可能没有开启skyline模式, 导致渲染html模版字符串异常#18536lupingW wants to merge 1 commit intoNervJS:mainfrom
Conversation
概览修改了 innerHTML 解析器,使 变更内容
工作流程图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 元素
预估代码审查工作量🎯 2 (Simple) | ⏱️ ~12 分钟
建议审查者
诗句
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 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 Report❌ Patch coverage is
❌ 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. Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
这个 PR 做了什么? (简要描述所做更改)
微信小程序skyline模式下有span标签, 而h5也有span标签. 在用react的dangerouslySetInnerHTML解析html字符串模版时,不知道用哪一个去解析. 本次只要在有命名冲突的标签上增加attribute属性(skyline-mode), 则用skylin标签渲染,否则依旧转为view和text进行渲染.
这个 PR 是什么类型? (至少选择一个)
这个 PR 涉及以下平台:
Summary by CodeRabbit
发布说明