Skip to content

fix(@vben/web-ele): the main color tone for switching between dark an… - #6678

Merged
jinmao88 merged 1 commit into
vbenjs:mainfrom
pangxie231:feature/theme
Aug 25, 2025
Merged

jinmao88 merged 1 commit into
vbenjs:mainfrom
pangxie231:feature/theme

Conversation

@pangxie231

@pangxie231 pangxie231 commented Aug 24, 2025 •

Copy link
Copy Markdown
Contributor

the main color tone for switching between dark and light themes has been reset

Description

Fix the issue #6615

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Summary by CodeRabbit

  • Bug Fixes
    • Preserves the custom theme’s primary color when toggling dark mode, preventing unintended resets.
    • Ensures primary color continues to update correctly for non-custom themes.

@changeset-bot

changeset-bot Bot commented Aug 24, 2025

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 2d58cfb

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented Aug 24, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

The theme preferences watcher in builtin.vue now receives the previous dark-mode value and conditionally skips updating themeColorPrimary when the theme is custom and the dark-mode state toggles. All other update logic remains the same.

Changes

Cohort / File(s) Summary of Changes
Theme watcher guard
packages/effects/layouts/src/widgets/preferences/blocks/theme/builtin.vue
Extended watcher callback to accept previous values; added a guard to skip themeColorPrimary updates when theme.type is custom and dark-mode changes; otherwise preserves existing primary color computation and assignment logic.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant UI as Preferences UI
  participant Watcher as Watcher(themeType, isDark, prevIsDark)
  participant Theme as Theme Utils
  participant Store as themeColorPrimary

  UI->>Watcher: Change themeType or isDark
  Watcher->>Theme: compute primaryColor from themeType
  alt themeType == "custom" AND isDark != prevIsDark
    Note over Watcher,Store: Skip updating themeColorPrimary on dark-mode toggle for custom theme
  else
    Watcher->>Store: themeColorPrimary = primaryColor || theme.color
    Note right of Store: Primary color updated
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • mynetfan
  • anncwb
  • jinmao88
  • vince292007

Poem

A hop, a skip, a guarded hue,
When darkness flips, I pause on cue.
Custom coats keep colors tight,
I twitch my nose—no change tonight.
By dawn’s first nibble, all is merry:
Themes stay crisp, and carrots—cherry! 🥕🐇

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.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/effects/layouts/src/widgets/preferences/blocks/theme/builtin.vue (2)

105-111: Guard against undefined oldValue in watcher (future-proofing).

Directly destructuring oldValue can break if this watcher is ever switched to immediate: true (or if Vue delivers undefined on the first run). A tiny default keeps behavior identical today while preventing accidental false positives/negatives later.

Apply this minimal diff:

-watch(
+watch<[BuiltinThemeType, boolean]>(
   () => [modelValue.value, props.isDark] as [BuiltinThemeType, boolean],
-  ([themeType, isDark], [_, isDarkPrev]) => {
+  // Default `oldValue` to current values so the "dark toggled" check is false on first run.
+  ([themeType, isDark], [, isDarkPrev] = [themeType, isDark]) => {

116-118: Simplify theme primary color assignment in dark-mode watcher

To make the intent clearer and reduce cognitive load from the negated condition, invert the logic and early-return when toggling dark mode on a custom theme. This preserves the existing behavior (not overriding the user’s custom color) while improving readability.

File: packages/effects/layouts/src/widgets/preferences/blocks/theme/builtin.vue
Lines: 116–118

Suggested change:

-      if (!(theme.type === 'custom' && isDark !== isDarkPrev)) {
-        themeColorPrimary.value = primaryColor || theme.color;
-      }
+      if (theme.type === 'custom' && isDark !== isDarkPrev) {
+        // Keep user-selected custom color when toggling dark mode
+        return;
+      }
+      themeColorPrimary.value = primaryColor || theme.color;
📜 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.

📥 Commits

Reviewing files that changed from the base of the PR and between cf6c4c9 and 2d58cfb.

📒 Files selected for processing (1)
  • packages/effects/layouts/src/widgets/preferences/blocks/theme/builtin.vue (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: post-update (windows-latest)
  • GitHub Check: post-update (ubuntu-latest)
  • GitHub Check: post-update (windows-latest)

@jinmao88
jinmao88 merged commit adbf793 into vbenjs:main Aug 25, 2025
dtera pushed a commit to dtera/vue-admin that referenced this pull request Sep 5, 2025
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 25, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants