Repository navigation
fix(mini-runner): include sub-package pages in prerender page set - #19503
Conversation
Previously getPages() only fed main-package appPages into this.prerenderPages. Prerender.render() iterates all webpack entrypoints (including sub-packages) and validatePrerenderPages accepts any path matching the match glob, so configuring prerender for sub-package pages passed validation but the page loader never got prerender: true (this.prerenderPages.has(module.name) was false for sub-package modules). As a result taro-loader did not inject wx._prerender, and every sub-package page's prerender snapshot silently fell back to the previous page's instance. Fix by unioning sub-package page paths into the prerender page set, so sub-package pages are eligible for prerender when their path matches the config (same as main-package pages).
|
Important Review skippedReview was skipped as selected files did not have any reviewable changes. ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. Walkthrough
Changes预渲染页面覆盖
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #19503 +/- ##
========================================
Coverage 54.63% 54.63%
========================================
Files 464 464
Lines 25391 25391
Branches 6364 6342 -22
========================================
Hits 13872 13872
+ Misses 9640 9532 -108
- Partials 1879 1987 +108
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
|
你好,麻烦开启这个 PR 的 “Allow edits from maintainers”,方便同步 main 分支;或者 rebase 到最新 main 后更新一下 PR,谢谢。 |
点哪个开启?我没找到 |
[mini-runner] 分包页面开启预渲染后快照内容错误(构建无报错、无告警)
环境
main分支 2026-09-20 核实仍未修复)mini.prerender.match包含分包路径,如['pages/**', 'sub/**']现象
为分包页开启预渲染后,构建不会报错也不会告警,但每个分包页的预渲染快照(写入该页自身
.wxml的<block wx:else>兜底块)内容是错误的:index.wxml字节数完全相同(48042 B),且内容都是主包最后一个页面(一个push-landing页)。即每个分包页首屏渲染的是「上一个编译页模块」的实例,而非自己的首屏。根因
框架内两个子系统对「哪些页面可预渲染」口径不一致:
渲染/校验侧——
packages/taro-webpack5-runner/src/prerender/prerender.js的Prerender.render():遍历Object.keys(stat.entrypoints)——全部 webpack 入口,含分包——并调用validatePrerenderPages(paths, prerenderConfig),后者只按match/exclude的 glob 过滤。所以match: ['sub/**']的分包页能过校验、进入渲染队列。注入侧——
packages/taro-webpack5-runner/src/plugins/MiniPlugin.ts的getPages():getSubPackages()只往this.pages加、从不更新this.prerenderPages。下游页面 loader 判断
prerender: this.prerenderPages.has(module.name)。分包模块的module.name形如sub/ai-chat/index,不在this.prerenderPages中 →prerender为false→taro-loader/lib/page.js不注入wx._prerender,但writeScript()仍给每页追加module.exports = wx._prerender→ 分包页require到上一个编译页模块的实例 → 所有分包快照塌缩成同一页。框架静默产出了错误结果,没有在
validatePrerenderPages处拒绝 / 告警分包路径。复现步骤
app.config.ts配置subPackages。config/prod.ts(或 dev / index):mini.prerender = { match: ['sub/**'] }。taro build --type weapp。dist-weapp/sub/<任一>/index.wxml→ 其wx:else兜底块内容错误;grep -rl 'push-landing' dist-weapp/sub有命中。期望:每个分包页携带自己的首屏快照;或者,若框架本就无意支持分包预渲染,应在构建时显式拒绝 / 告警
prerender.match中的分包路径,而不是静默产出坏快照。临时修复(已验证可用)
用 patch-package 改
getPages(),把分包页 union 进预渲染集合(见下方建议修法)。建议修法(已提 PR)
在
getPages()计算this.prerenderPages时,把分包页路径一并纳入:修复分支:
anyone-developer/taro的fix/subpackage-prerender(待开 PR 到NervJS/taro)。Summary by CodeRabbit