fix(theme): 兼容 VS Code 主题变量并修复 Naive UI var(...) 颜色解析报错#18
Merged
Windsland52 merged 2 commits intomainfrom Mar 23, 2026
Merged
Conversation
There was a problem hiding this comment.
Hey - 我发现了 1 个问题,并给出了一些整体层面的反馈:
'maa-bridge-theme-updated'事件名在Index.vue和App.vue中都被硬编码了;建议将其提取为一个共享常量,以避免触发端和监听端之间出现拼写错误或不一致。isValidCssColor帮助函数在每次重新计算themeOverrides时会被多次调用,并且在可用时总会调用CSS.supports;你可以考虑按值缓存结果(memoize),或者在更早阶段对明显无效的输入进行短路,以减少重复的特性检测工作。
给 AI Agent 的提示
Please address the comments from this code review:
## Overall Comments
- The `'maa-bridge-theme-updated'` event name is hardcoded in both `Index.vue` and `App.vue`; consider extracting it into a shared constant to avoid typos or mismatches between emitter and listener.
- The `isValidCssColor` helper is invoked multiple times per `themeOverrides` recomputation and always calls `CSS.supports` when available; you might want to memoize results per value or short‑circuit obviously invalid inputs earlier to reduce repeated feature-detection work.
## Individual Comments
### Comment 1
<location path="src/App.vue" line_range="590" />
<code_context>
document.body.setAttribute('class', payload.bodyClass)
}
+
+ window.dispatchEvent(new Event('maa-bridge-theme-updated'))
}
</code_context>
<issue_to_address>
**suggestion:** Extract the custom theme event name into a shared constant to avoid string mismatches.
This event name is duplicated here and in `Index.vue` (`window.addEventListener('maa-bridge-theme-updated', refreshVscodeTheme)`). To avoid mismatches if it changes or is mistyped, export a shared constant (e.g. `const BRIDGE_THEME_UPDATED_EVENT = 'maa-bridge-theme-updated'`) and use it in both places.
</issue_to_address>帮我变得更有用!请对每条评论点击 👍 或 👎,我会根据你的反馈改进后续的评审。
Original comment in English
Hey - I've found 1 issue, and left some high level feedback:
- The
'maa-bridge-theme-updated'event name is hardcoded in bothIndex.vueandApp.vue; consider extracting it into a shared constant to avoid typos or mismatches between emitter and listener. - The
isValidCssColorhelper is invoked multiple times perthemeOverridesrecomputation and always callsCSS.supportswhen available; you might want to memoize results per value or short‑circuit obviously invalid inputs earlier to reduce repeated feature-detection work.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `'maa-bridge-theme-updated'` event name is hardcoded in both `Index.vue` and `App.vue`; consider extracting it into a shared constant to avoid typos or mismatches between emitter and listener.
- The `isValidCssColor` helper is invoked multiple times per `themeOverrides` recomputation and always calls `CSS.supports` when available; you might want to memoize results per value or short‑circuit obviously invalid inputs earlier to reduce repeated feature-detection work.
## Individual Comments
### Comment 1
<location path="src/App.vue" line_range="590" />
<code_context>
document.body.setAttribute('class', payload.bodyClass)
}
+
+ window.dispatchEvent(new Event('maa-bridge-theme-updated'))
}
</code_context>
<issue_to_address>
**suggestion:** Extract the custom theme event name into a shared constant to avoid string mismatches.
This event name is duplicated here and in `Index.vue` (`window.addEventListener('maa-bridge-theme-updated', refreshVscodeTheme)`). To avoid mismatches if it changes or is mistyped, export a shared constant (e.g. `const BRIDGE_THEME_UPDATED_EVENT = 'maa-bridge-theme-updated'`) and use it in both places.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by Sourcery
使主题处理与 VS Code 主题变量保持一致,并提升 Naive UI 主题覆盖的健壮性,以避免
var(...)颜色解析错误。新特性:
缺陷修复:
var(...)主题颜色传入主题覆盖之前,先将其解析为具体颜色值,解决 Naive UI 颜色解析错误问题。增强改进:
Original summary in English
Summary by Sourcery
Align theme handling with VS Code theme variables and improve Naive UI theme override robustness to avoid var(...) color parsing errors.
New Features:
Bug Fixes:
Enhancements: