Skip to content

fix(vite-runner): 修复小程序页面模板缺少 page-meta 导致 PageMeta 失效的问题 - #19500

Merged
Single-Dancer merged 1 commit into
NervJS:mainfrom
INK-MapleShadow:fix/vite-runner-pagemeta-wxml
Sep 20, 2026
Merged

Single-Dancer merged 1 commit into
NervJS:mainfrom
INK-MapleShadow:fix/vite-runner-pagemeta-wxml

Conversation

@INK-MapleShadow

@INK-MapleShadow INK-MapleShadow commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

fix #16900

问题

vite 编译小程序时,页面 wxml 缺少 <page-meta> 节点:配置了 enablePageMeta 的页面里使用 <PageMeta> 完全失效(webpack5 编译器无此问题)。Taro 4.0.5 ~ 4.2.1 均可复现。

原因

packages/taro-vite-runner/src/mini/emit.ts 生成页面模板时存在两个问题:

  1. 调用 buildPageTemplate 时未传入页面配置,平台覆写(如 微信小程序)拿不到 enablePageMeta,不会生成 page-meta 片段;
  2. 页面模板先于 base 模板生成,而覆写读取的 transferComponents 依赖 buildTemplate 填充,此时仍为空。

修复

  • 生成页面模板前先计算 base 模板(结果复用于后续 emit,不重复生成),使组件信息就绪;
  • buildPageTemplate 传入 { content: pageConfig, path: page.name },与 webpack5 编译器(MiniPlugin)行为对齐。

验证

  • 最小复现仓库(React + TS + Vite,weapp):https://github.com/INK-MapleShadow/taro-issue-16900-repro
  • 修复前:dist/pages/index/index.wxml 只有 <import src="../../base.wxml"/><template is="taro_tmpl"/>;
  • 修复后:页面 wxml 正常输出 <page-meta ... page-style="{{pageMeta.p5||''}}" ...>;
  • pnpm --filter @tarojs/vite-runner run build(tsc)与 ESLint 均通过。

Summary by CodeRabbit

  • 改进
    • 优化模板生成流程,提升页面与基础模板生成的一致性。
    • 页面模板生成时 now 传入页面配置和页面名称信息。

@coderabbitai

coderabbitai Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: fd8fa91f-8210-431c-b6e4-f04a7f43fc9e

📥 Commits

Reviewing files that changed from the base of the PR and between d6d69e3 and 7eb444f.

📒 Files selected for processing (1)
  • packages/taro-vite-runner/src/mini/emit.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


Walkthrough

调整小程序模板生成流程:提前构建并复用 baseTemplate,同时向 buildPageTemplate 传入页面配置和页面名称。

Changes

模板生成流程

Layer / File(s) Summary
基础模板与页面模板生成
packages/taro-vite-runner/src/mini/emit.ts
在页面模板循环前构建 baseTemplate。buildPageTemplate 接收页面配置和页面名称。base.xml 复用已构建的基础模板。

Priority: ➖ Normal

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

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 7f21e

该变更修复页面元数据传递与模板生成时序,未发现阻碍合并的问题。

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确说明了修复目标,即修复 Vite Runner 生成小程序页面模板时缺少 节点的问题,与变更内容和 PR 目标一致。
Linked Issues check ✅ Passed PR #16900 的编码目标已覆盖。packages/taro-vite-runner/src/mini/emit.ts 在页面模板生成前计算 baseTemplate,并向 buildPageTemplate 传入 { content: pageConfig, path: page.name }。该流程使平台覆写可以读取 enablePageMeta 和组件信息,从而生成包…
Out of Scope Changes check ✅ Passed 变更仅涉及 packages/taro-vite-runner/src/mini/emit.ts 的页面模板生成顺序、base 模板复用和页面配置传递。这些修改直接支持 #16900 的 PageMeta 编译目标。未发现与该目标无关的代码变更。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1…
✨ 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

小兔敲代码,模板先成形
页面带配置,名称随行
基础模板再次复用
PageMeta 不再隐形
WXML 里绽放新声

Comment @coderabbitai help to get the list of available commands.

页面模板先于 base 模板生成,导致:
1. buildPageTemplate 未收到页面配置,平台覆写(如微信小程序)拿不到 enablePageMeta;
2. 覆写读取的 transferComponents 依赖 buildTemplate 填充,此时仍为空。

与 webpack5 编译器(MiniPlugin)行为对齐。fix NervJS#16900
@Single-Dancer
Single-Dancer force-pushed the fix/vite-runner-pagemeta-wxml branch from 7eb444f to 7f21e09 Compare September 20, 2026 02:47
@Single-Dancer Single-Dancer added this to the 4.2.2 milestone Sep 20, 2026
@codecov

codecov Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 55.70%. Comparing base (e4bc99b) to head (7f21e09).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #19500   +/-   ##
=======================================
  Coverage   55.70%   55.70%           
=======================================
  Files         451      451           
  Lines       23779    23779           
  Branches     5872     5918   +46     
=======================================
  Hits        13247    13247           
- Misses       8652     8685   +33     
+ Partials     1880     1847   -33     
Flag Coverage Δ
taro-cli 56.96% <ø> (ø)
taro-runtime 58.63% <ø> (ø)
taro-web 53.12% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.
see 9 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 merged commit 6c99de7 into NervJS:main Sep 20, 2026
25 checks passed
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.

Taro4.0.5 PageMeta微信小程序不会编译进wxml

2 participants