Skip to content

fix(runtime): preserve insertAdjacentHTML node order - #19567

Merged
Single-Dancer merged 1 commit into
NervJS:mainfrom
Jarvis636431:fix/runtime-insert-adjacent-html-order
Oct 27, 2026
Merged

Single-Dancer merged 1 commit into
NervJS:mainfrom
Jarvis636431:fix/runtime-insert-adjacent-html-order

Conversation

@Jarvis636431

@Jarvis636431 Jarvis636431 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

这个 PR 做了什么?

修复 Taro runtime insertAdjacentHTML 的节点插入顺序:afterbegin 插入多个节点时会反转顺序;afterend 会把内容追加到父容器末尾,越过目标后方已有的兄弟节点。

在循环前保存原始 firstChild 和 nextSibling,通过现有 insertBefore 路径按解析顺序插入。没有锚点时沿用尾部追加行为。

Closes #19566

这个 PR 是什么类型?

  • 错误修复 (Bugfix)

这个 PR 涉及以下平台:

  • 所有小程序(使用 Taro runtime DOM 的路径)

验证

  • 新增 28 个回归用例,原实现 10 个失败、18 个通过;修复后全部通过。
  • 覆盖四种插入位置、多元素及文本/元素混合、空/非空目标、末尾插入、空 HTML、脱离父节点的既有行为,以及父子和相邻节点关系。
  • 挂载用例使用真实 runtime 根节点和更新队列,通过模拟页面 setData 检查最终渲染数据的节点顺序。
  • pnpm --filter @tarojs/runtime run test:ci --maxWorkers=2:17 个测试文件通过,225 个用例通过、1 个跳过。首次默认并发运行时环境加载用例超过默认 5 秒,降低并发重跑通过,未修改测试超时或相关源码。
  • 修改文件 ESLint 和 git diff --check 通过。
  • 全工作区 pnpm build(包含 runtime 构建):Node.js v22.14.0 / pnpm 10.0.0,退出码 0。未修改文件中仍有类型、组件及外部依赖解析等构建告警。

未进行 Vue 应用、小程序开发者工具或真机测试;没有调整解析器、特性开关或依赖。

Summary by CodeRabbit

  • 问题修复
    • 修正 HTML 片段插入位置:使用 afterbegin 时,内容会插入到原有首个子节点之前;使用 afterend 时,会插入到目标节点的下一个兄弟节点之前。

@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8b216181-592c-4844-ad71-6c88d3b23803
Commits

Reviewing files that changed from the base of the PR and between f910cf9 and 2bc658f.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a279379c-6d21-412d-812a-1c7a3bc03a68
Commits

Reviewing files that changed from the base of the PR and between 8ed2d67 and f910cf9.

Files selected for processing: 2
  • packages/taro-runtime/src/dom-external/node.ts
  • packages/taro-runtime/tests/insert-adjacent-html.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

Walkthrough

insertAdjacentHTML 保存插入前的首子节点和下一个兄弟节点,并据此调整 afterbegin 与 afterend 的插入位置。新增测试覆盖四种插入位置、脱离文档的目标及挂载后的渲染数据。

Changes

insertAdjacentHTML 插入顺序

Layer / File(s) Summary
插入定位与行为验证
packages/taro-runtime/src/dom-external/node.ts, packages/taro-runtime/tests/insert-adjacent-html.spec.ts
afterbegin 在原首子节点前插入节点,afterend 在原下一个兄弟节点前插入节点。新增测试检查节点关系、顺序及挂载后的渲染数据。

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: chen-jj, zakarycode

Merge Risk: Minimal · previous review f910c

The ordering fix appears ready to merge after normal checks; no actionable issue remains from the supplied evidence.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 标题准确概括了本次变更的主要目的,即修复运行时 insertAdjacentHTML 的节点顺序问题。表述简洁且具体。
Linked Issues check Passed PR 满足直接关联 issue [#19566] 的两个编码目标。packages/taro-runtime/src/dom-external/node.ts 在循环前保存 firstChild 和 nextSibling,并通过 insertBefore 按解析顺序处理 afterbegin 和 afterend;无锚点时,`insertBefore(node, null…
Out of Scope Changes check Passed 变更范围与 issue [#19566] 一致。生产代码只调整 runtime 的 insertAdjacentHTML 插入锚点。新增测试直接验证该修复及其渲染结果。未发现解析器、特性开关、依赖或无关功能变更。
Full details: Linked Issues check

Explanation

PR 满足直接关联 issue [#19566] 的两个编码目标。packages/taro-runtime/src/dom-external/node.ts 在循环前保存 firstChild 和 nextSibling,并通过 insertBefore 按解析顺序处理 afterbegin 和 afterend;无锚点时,insertBefore(node, null) 保留尾部追加行为。新增 packages/taro-runtime/tests/insert-adjacent-html.spec.ts 覆盖四种位置、多节点顺序、混合文本、兄弟节点、空 HTML、脱离父节点和挂载更新。

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@coderabbitai
coderabbitai Bot requested review from Chen-jj and ZakaryCode October 26, 2026 04:02
@codecov

codecov Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 57.32%. Comparing base (13b8ba7) to head (2bc658f).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #19567      +/-   ##
==========================================
+ Coverage   57.26%   57.32%   +0.05%     
==========================================
  Files         469      469              
  Lines       25939    25938       -1     
  Branches     6497     6488       -9     
==========================================
+ Hits        14855    14868      +13     
+ Misses       9237     9120     -117     
- Partials     1847     1950     +103     
Flag Coverage Δ
taro-cli 59.69% <ø> (ø)
taro-runtime 63.98% <100.00%> (+0.42%) ⬆️
taro-web 65.76% <ø> (ø)

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

Files with missing lines Coverage Δ
packages/taro-runtime/src/dom-external/node.ts 42.22% <100.00%> (+3.09%) ⬆️

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

@Single-Dancer
Single-Dancer force-pushed the fix/runtime-insert-adjacent-html-order branch from f910cf9 to 2bc658f Compare October 27, 2026 02:28
@Single-Dancer Single-Dancer added this to the 4.3.2 milestone Oct 27, 2026
@Single-Dancer
Single-Dancer merged commit 8f5d030 into NervJS:main Oct 27, 2026
25 checks passed
@Jarvis636431
Jarvis636431 deleted the fix/runtime-insert-adjacent-html-order branch November 3, 2026 03:19
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]: runtime insertAdjacentHTML 插入多个节点时顺序或位置错误

2 participants