fix(vite-runner mini): app.css 为空的情况下 自定义组件复用后样式丢失#19116
fix(vite-runner mini): app.css 为空的情况下 自定义组件复用后样式丢失#19116Single-Dancer merged 2 commits intoNervJS:mainfrom
Conversation
app.css 没有内容会被过滤掉,导致不引入生成都 common.wxss。增加了边界条件判断,emit 一个 app${nativeStyleExt}
Close NervJS#17587
概览该修改增强了小程序Vite编译器的样式资源生成逻辑,确保即使Rollup bundle中不存在app chunk,也能正确生成包含公共样式导入语句的主样式资源文件。 变更明细
预计代码审查工作量🎯 2 (简单) | ⏱️ ~10分钟 建议审查者
诗
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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.
🧹 Nitpick comments (1)
packages/taro-vite-runner/src/mini/style.ts (1)
50-59: 可选优化:与上方分支保持格式一致,并简化冗余路径计算
path.relative(sourceDir, path.join(sourceDir, i))归一化后等价于i,这里的往返计算没有实际作用(上方 Line 47 存在同样的冗余,可一并清理)。- 上方分支(Line 46-48)每条
@import以;\n结尾,新分支改用join('\n')且末尾无换行符,两条分支输出格式略有不一致。虽然功能上等价,但建议保持一致以便后续维护。修复本身逻辑是正确的,能解决 app.css 为空时 common 样式未被注入的问题。这只是可选清理建议,不阻塞合入。
♻️ 建议的最小化调整
if (!appStyleChunk && commonStyleFileNames.length > 0) { - const sourceDir = viteCompilerContext.sourceDir this.emitFile({ type: 'asset', fileName: appStyleFileName, source: commonStyleFileNames - .map((i) => `@import "${path.relative(sourceDir, path.join(sourceDir, i))}";`) - .join('\n') + .reduce((prev, current) => prev + `@import "${current}";\n`, '') }) }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/taro-vite-runner/src/mini/style.ts` around lines 50 - 59, The new branch that emits the app style asset should remove the redundant path normalization (replace path.relative(sourceDir, path.join(sourceDir, i)) with just i) and make the import string formatting match the other branch by joining with ';\n' and ensuring a trailing semicolon/newline; update the block that uses appStyleChunk, commonStyleFileNames, viteCompilerContext.sourceDir, this.emitFile and appStyleFileName so it constructs source: commonStyleFileNames.map(i => `@import "${i}";`).join(';\n') + '\n' to keep output formatting consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/taro-vite-runner/src/mini/style.ts`:
- Around line 50-59: The new branch that emits the app style asset should remove
the redundant path normalization (replace path.relative(sourceDir,
path.join(sourceDir, i)) with just i) and make the import string formatting
match the other branch by joining with ';\n' and ensuring a trailing
semicolon/newline; update the block that uses appStyleChunk,
commonStyleFileNames, viteCompilerContext.sourceDir, this.emitFile and
appStyleFileName so it constructs source: commonStyleFileNames.map(i => `@import
"${i}";`).join(';\n') + '\n' to keep output formatting consistent.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 737cc1c7-a0b1-49ee-abe6-90cdd434c764
⛔ Files ignored due to path filters (1)
packages/taro-components/__tests__/__snapshots__/picker-view.spec.tsx.snapis excluded by!**/*.snap
📒 Files selected for processing (1)
packages/taro-vite-runner/src/mini/style.ts
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #19116 +/- ##
=======================================
Coverage 56.07% 56.07%
=======================================
Files 447 447
Lines 23454 23454
Branches 5827 5808 -19
=======================================
Hits 13151 13151
- Misses 8573 8575 +2
+ Partials 1730 1728 -2
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
这个 PR 做了什么? (简要描述所做更改)
原因:app.css 没有内容会被过滤掉,导致不引入生成的 common.wxss。
修复方式:增加了边界条件判断,emit 一个 app${nativeStyleExt}
这个 PR 是什么类型? (至少选择一个)
这个 PR 涉及以下平台:
Summary by CodeRabbit
发布说明