-
Notifications
You must be signed in to change notification settings - Fork 4.9k
feat(taro-platform-harmony-cpp): 支持虚拟样式 #18253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Walkthrough在 Harmony 样式加载流程中新增文件存在性检查:处理样式请求时先判断原始路径是否存在,存在则加入监视并读取内容;不存在则跳过监听与读取并不返回内容,避免因缺失文件抛出异常。 Changes
Sequence Diagram(s)sequenceDiagram
participant Client as 调用方
participant Loader as Harmony 样式 Loader
participant FS as 文件系统
Client->>Loader: 请求处理样式 (rawId)
Loader->>FS: 检查是否存在 (fs.existsSync(rawId))
alt 文件存在
Loader->>FS: 读取文件内容
Loader->>Loader: 将文件加入 watch 列表
Loader-->>Client: 返回内容
else 文件不存在
note right of Loader: 跳过读取与监听\n不返回内容以避免异常
Loader-->>Client: 返回空结果 / 无内容
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. 📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ Finishing Touches
🧪 Generate 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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/taro-vite-runner/src/harmony/style.ts (1)
236-266
: 统一 cssCache 缓存键的规范化
当前在写入缓存时使用:id = stripVirtualModulePrefix(id).replace(STYLE_SUFFIX, '') cssCache.set(id, css)而读取缓存时用到的键是:
const rawId = stripVirtualModulePrefix(cssId) .replace(STYLE_SUFFIX_RE, '') .replace(usedRE, '') return cssCache.get(rawId) || ''两者对
id
的处理逻辑不一致(写入时未去除?used
查询参数,且使用了不同的后缀替换方式),会导致缓存未命中(例如*.module.css?used
场景)。请在写入缓存前同样执行.replace(STYLE_SUFFIX_RE, '').replace(usedRE, '')
,示例修改:@@ packages/taro-vite-runner/src/harmony/style.ts:236 - id = stripVirtualModulePrefix(id).replace(STYLE_SUFFIX, '') + // 规范化 id:移除虚拟前缀、样式后缀及 '?used' 查询参数 + const normalizedId = stripVirtualModulePrefix(id) + .replace(STYLE_SUFFIX_RE, '') + .replace(usedRE, '') + id = normalizedId @@ packages/taro-vite-runner/src/harmony/style.ts:263 - cssCache.set(id, css) + cssCache.set(normalizedId, css)请务必保证
cssCache.set
与cssCache.get
使用同样的键规范化策略,否则会造成缓存命中失败。
- 影响文件:packages/taro-vite-runner/src/harmony/style.ts(第 236–266 行)
- 可用命令检验:
rg -n -C1 'cssCache\.set\(' rg -n -C1 'cssCache\.get\('
🧹 Nitpick comments (1)
packages/taro-vite-runner/src/harmony/style.ts (1)
63-75
: 预加载阶段遗漏 virtual:*.css:入口全局样式可能未被提前加载getCssIdSets 仅在
resolveSync
成功时加入cssIdSet
。对virtual:uno.css
这类虚拟样式,resolveSync
会失败,导致未加入集合,后续“确保 CSS 文件已经加载”的逻辑可能错过该样式(尽管最终由下游插件加载,但这里的预加载与缓存填充会缺席)。建议在未解析且判断为虚拟 CSS 时,直接把原始 id 纳入集合,让后续
this.load({ id })
触发下游插件处理。@@ function getCssIdSets (raw: string, id: string, sourceDir: string) { - if (resolveId && CSS_LANGS_RE.test(rawId)) { + if (resolveId && CSS_LANGS_RE.test(rawId)) { // Note: 预加载依赖的 CSS 文件 const cssId = appendVirtualModulePrefix(resolveId + STYLE_SUFFIX) cssIdSet.add(cssId) + } else if (CSS_LANGS_RE.test(rawId) && rawId.startsWith('virtual:')) { + // 支持虚拟样式:交由后续 load 钩子与下游插件处理 + cssIdSet.add(rawId) }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
packages/taro-vite-runner/src/harmony/style.ts
(1 hunks)
🔇 Additional comments (1)
packages/taro-vite-runner/src/harmony/style.ts (1)
146-149
: 方向正确:为样式加载增加存在性检查以兼容虚拟 CSS当文件不存在时不再读盘,可让下游(如 unocss)插件接管加载,避免异常,符合 PR 目标。
6ef46fa
to
c448a0a
Compare
c448a0a
to
8a72f2c
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #18253 +/- ##
=======================================
Coverage 55.06% 55.06%
=======================================
Files 416 416
Lines 21563 21563
Branches 5278 5293 +15
=======================================
Hits 11873 11873
- Misses 8163 8173 +10
+ Partials 1527 1517 -10
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
这个 PR 做了什么? (简要描述所做更改)
允许加载虚拟 css,如 unocss vite 插件生成的虚拟样式,现在会因为找不到文件导致编译失败。
这个 PR 是什么类型? (至少选择一个)
这个 PR 涉及以下平台:
Summary by CodeRabbit