Skip to content
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

fix: fix change theme error when open playground #2681

Merged
merged 1 commit into from
Dec 25, 2024

Conversation

zzcr
Copy link
Member

@zzcr zzcr commented Dec 19, 2024

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features

    • Updated version to tiny-vue-version-3.20, enhancing version management.
    • Added support for a new theme, old, alongside existing themes.
  • Bug Fixes

    • Adjusted logic for theme determination in the Demo component to ensure correct theme application.
  • Chores

    • Streamlined theme management by removing deprecated constants and simplifying routing logic.

Copy link

coderabbitai bot commented Dec 19, 2024

Walkthrough

This pull request introduces comprehensive updates to theme management and versioning across multiple files in the project. The changes primarily focus on updating version constants, modifying theme-related configurations, and simplifying theme handling logic. The modifications affect routing, theme selection, and playground functionality, with a particular emphasis on updating theme mappings and removing deprecated references.

Changes

File Change Summary
examples/sites/playground/App.vue - Updated VERSION from 'tiny-vue-version-3.19' to 'tiny-vue-version-3.20'
- Expanded theme conditional checks to include 'smb'
- Replaced 'infinity' theme with 'old'
examples/sites/src/const.ts - Updated theme constants (DEFAULT_THEME, AURORA_THEME, SMB_THEME)
- Added OLD_THEME
- Removed THEME_ROUTE_MAP
- Introduced themeToolValuesMap
examples/sites/src/router.js - Removed import of THEME_ROUTE_MAP
- Simplified route redirection logic
examples/sites/src/tools/useTheme.js - Updated import statements
- Removed designConfigMap
- Simplified theme change logic
examples/sites/src/views/components/demo.vue - Modified openPlayground method to change theme extraction logic

Sequence Diagram

sequenceDiagram
    participant App as App.vue
    participant Router as Router
    participant ThemeTool as useTheme.js
    participant Demo as Demo Component

    App->>ThemeTool: Initialize Theme
    ThemeTool-->>App: Set Current Theme
    App->>Router: Configure Routes
    Router-->>App: Routing Configured
    Demo->>ThemeTool: Request Theme
    ThemeTool-->>Demo: Provide Theme Details
Loading

Possibly related PRs

Suggested labels

bug

Poem

🐰 A Rabbit's Theme Song 🎨

Versions dance, themes take flight,
From tiny vue to new delight,
Old becomes new, routes realign,
Code hops forward, designs refine!
Rabbit's magic makes it shine! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

Documentation and Community

  • 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.

@github-actions github-actions bot added the bug Something isn't working label Dec 19, 2024
Copy link

[e2e-test-warn]
The component to be tested is missing.

The title of the Pull request should look like "fix(vue-renderless): [action-menu, alert] fix xxx bug".

Please make sure you've read our contributing guide

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🧹 Nitpick comments (1)
examples/sites/src/tools/useTheme.js (1)

44-44: Consider adding theme validation

The code assumes theme values are always valid. Consider adding validation when:

  1. Setting the initial theme
  2. Changing themes
  3. Returning the default theme
+const isValidTheme = (theme) => theme in themeToolValuesMap
+
-const currentThemeKey = hooks.ref(DEFAULT_THEME)
+const currentThemeKey = hooks.ref(isValidTheme(DEFAULT_THEME) ? DEFAULT_THEME : Object.keys(themeToolValuesMap)[0])

 export default function useTheme() {
   !initWatchRoute && watchRoute()
   return {
     getThemeData,
     changeTheme,
     currentThemeKey,
     designConfig,
-    defaultTheme: DEFAULT_THEME
+    defaultTheme: isValidTheme(DEFAULT_THEME) ? DEFAULT_THEME : Object.keys(themeToolValuesMap)[0]
   }
 }

Also applies to: 103-103

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8d0429d and d79f224.

📒 Files selected for processing (5)
  • examples/sites/playground/App.vue (4 hunks)
  • examples/sites/src/const.ts (2 hunks)
  • examples/sites/src/router.js (2 hunks)
  • examples/sites/src/tools/useTheme.js (4 hunks)
  • examples/sites/src/views/components/demo.vue (1 hunks)
🔇 Additional comments (5)
examples/sites/src/router.js (1)

38-38: Verify default theme redirect behavior

The redirect now uses DEFAULT_THEME directly instead of going through THEME_ROUTE_MAP. While this simplifies the code, ensure that:

  1. The redirect works correctly with the new theme value format
  2. All components support the new theme path format
✅ Verification successful

Let me gather more information about the theme-related changes to verify the impact comprehensively.


Let me gather one final piece of information about the theme path handling in components.


Let me check the const.ts file specifically to understand the theme configuration.


Based on the gathered information, I can now provide the final response:

Theme redirect behavior is correctly implemented

The redirect using DEFAULT_THEME directly is safe because:

  1. DEFAULT_THEME is properly defined as 'os-theme' in const.ts
  2. The theme system is well-structured with proper mappings in themeToolValuesMap
  3. Components correctly handle theme paths through useTheme hook which supports all defined themes including the default one
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for components that might expect the old theme format in routes
rg -A 5 "params\.theme" --glob '!{*.test.*,*.spec.*}'

Length of output: 868


Script:

#!/bin/bash
# Check for DEFAULT_THEME definition and usage
rg "DEFAULT_THEME" -A 2

# Check for any other theme-related route handling
rg "theme.*route" -i

# Look for theme-related component configurations
ast-grep --pattern 'const $_ = {
  theme: $_,
  $$$
}'

Length of output: 6965


Script:

#!/bin/bash
# Check for theme-related path construction in components
rg -A 3 "/${theme}/" --glob '*.{vue,js,ts}'

# Check the const.ts file for theme-related configurations
cat examples/sites/src/const.ts

Length of output: 67752


Script:

#!/bin/bash
# Check the theme-related constants and configurations
cat examples/sites/src/const.ts

# Check for any theme path usage in components
rg -A 2 "/${theme}/" --type-add 'vue:*.vue' --type vue

Length of output: 73262

examples/sites/playground/App.vue (3)

14-14: LGTM: Version bump to 3.20

The version update is consistent with the versions array and CDN import logic.


86-89: Verify SMB theme configuration

The addition of 'smb' theme support needs corresponding design configuration package.

✅ Verification successful

SMB theme configuration is properly set up

The SMB theme is well-configured in the codebase with:

  • Package @opentiny/vue-design-smb exists with proper dependencies
  • Theme is properly imported and used in multiple files including examples/sites/src/tools/useTheme.js
  • Theme configuration is documented and referenced across the codebase
  • Multiple components have been adapted to support the SMB theme as evidenced by the changelog entries
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence and configuration of SMB theme package

# Check if the SMB theme package exists in package.json
rg -A 5 "@opentiny/vue-design-smb"

# Check for SMB theme-related configurations
rg "smb.*theme" 

Length of output: 12029


157-167: Verify theme import configurations

The theme import logic has been updated to support the new theme structure.

✅ Verification successful

Let me gather more information about the theme configuration to ensure completeness of verification.


Theme import configurations are correctly structured

The verification confirms that:

  • Theme tool imports are consistently used across the codebase
  • Both aurora and old themes are properly imported in theme-tool.js
  • Design configuration is correctly provided using design.configKey
  • The theme import logic in App.vue aligns with the theme structure used throughout the project
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify theme import configurations

# Check theme tool imports
rg "import.*theme-tool"

# Check old theme imports
rg "import.*old-theme-index"

# Verify theme configuration usage
ast-grep --pattern 'import TinyThemeTool from "@opentiny/vue-theme/theme-tool"'

Length of output: 1558


Script:

#!/bin/bash
# Check theme-related imports and configurations
# Check aurora theme imports
rg "import.*aurora-theme-index"

# Check theme configuration patterns
rg "designThemeMap\[.*\]"

# Check theme configuration object
ast-grep --pattern "const designThemeMap = {
  $$$
}"

# Check other theme-related configurations
rg "provide\(design\.configKey"

Length of output: 592

examples/sites/src/views/components/demo.vue (1)

193-193: ⚠️ Potential issue

Fix: Theme key extraction logic

The change in theme key extraction from split('-')[1] to split('-')[0] appears to be the root cause fix for the theme change error. This modification affects how themes are determined when opening the playground.

Please verify:

  1. The format of currentThemeKey values
  2. The impact on existing theme configurations
  3. Test different theme combinations to ensure the fix works as expected
✅ Verification successful

Let me gather more context about the theme-related code to understand the change better.


Let me check the theme configuration and initialization code to fully understand the theme key structure.


Based on the code analysis, I can now generate the final response:

Theme key extraction change is correct

The modification from split('-')[1] to split('-')[0] is the right fix because:

  1. The theme keys in const.ts are defined as os-theme, aurora-theme, and smb-theme
  2. The tinyTheme variable is used to load design configurations and theme files with the base theme name (e.g., 'saas', 'os', 'aurora')
  3. Taking the first part of the theme key (split('-')[0]) correctly extracts the base theme name needed for imports
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify theme key format and usage

# Check theme key formats in the codebase
rg "currentThemeKey.*split.*\[.*\]"

# Check theme-related constants and their usage
ast-grep --pattern 'const currentThemeKey = $$$'

Length of output: 320


Script:

#!/bin/bash
# Check the DEFAULT_THEME constant and theme-related configurations
rg "DEFAULT_THEME.*=.*" -A 2

# Look for theme-related patterns and their usage
rg "theme.*split.*\[.*\]" -B 2 -A 2

# Check for any other theme key processing
ast-grep --pattern 'const $_ = $_.split("-")'

# Find theme-related imports and configurations
rg "import.*Theme" -A 2

Length of output: 8447


Script:

#!/bin/bash
# Check the content of useTheme.js to understand theme initialization
cat examples/sites/src/tools/useTheme.js

# Look for theme key usage in demo.vue
cat examples/sites/src/views/components/demo.vue

Length of output: 23969

Comment on lines +22 to +27
// 主题工具导出主题变量和主题的映射关系
export const themeToolValuesMap = {
[DEFAULT_THEME]: '',
[AURORA_THEME]: tinyAuroraTheme,
[SMB_THEME]: '',
[OLD_THEME]: tinyOldTheme
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Review empty theme implementations in themeToolValuesMap

The map contains empty string values for DEFAULT_THEME and SMB_THEME. This could lead to unexpected behavior when these themes are selected.

Please clarify:

  1. Why are some theme values empty strings?
  2. What is the expected behavior when a theme with an empty value is selected?
  3. Should we import and use the corresponding theme implementations for these themes?

Comment on lines +17 to +20
export const DEFAULT_THEME = 'os-theme'
export const AURORA_THEME = 'aurora-theme'
export const SMB_THEME = 'smb-theme'
export const OLD_THEME = 'old-theme'
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Theme constant values need to be updated across multiple files

The verification reveals several files still using the old theme values with 'tiny-' prefix that need to be updated to match the new simplified theme constants:

  • examples/sites/src/views/components/float-settings.vue: Uses 'tiny-smb-theme'
  • examples/docs/newsrc/uses/useTheme.js: References 'tiny-default-theme', 'tiny-aurora-theme', and 'tiny-smb-theme'
  • examples/docs/newsrc/pc.vue: Multiple occurrences in dropdown items and config map
  • packages/theme/src/aurora-theme-index.js: Theme ID using 'tiny-aurora-theme'
  • packages/theme/build/release.js: Theme ID using 'tiny-aurora-theme'
🔗 Analysis chain

Verify theme constant value changes across the codebase

The theme constant values have been simplified by removing the 'tiny-' prefix. This change could impact other parts of the codebase that might be using the old values.


Let's examine the actual usage of these theme values in the found files to determine if they need updates.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining references to old theme values
rg -l "tiny-(default|aurora|smb)-theme"

Length of output: 235


Script:

#!/bin/bash
# Check the context of theme value usage in the affected files
echo "=== float-settings.vue ==="
rg -A 2 -B 2 "tiny-(default|aurora|smb)-theme" examples/sites/src/views/components/float-settings.vue

echo -e "\n=== useTheme.js ==="
rg -A 2 -B 2 "tiny-(default|aurora|smb)-theme" examples/docs/newsrc/uses/useTheme.js

echo -e "\n=== pc.vue ==="
rg -A 2 -B 2 "tiny-(default|aurora|smb)-theme" examples/docs/newsrc/pc.vue

echo -e "\n=== aurora-theme-index.js ==="
rg -A 2 -B 2 "tiny-(default|aurora|smb)-theme" packages/theme/src/aurora-theme-index.js

echo -e "\n=== release.js ==="
rg -A 2 -B 2 "tiny-(default|aurora|smb)-theme" packages/theme/build/release.js

Length of output: 2210

Comment on lines +86 to +89
if (!loadedTheme && themeToolValuesMap[val]) {
currentThemeKey.value = val
const themeTool = new TinyThemeTool()
themeTool.changeTheme(tinyAuroraTheme)
themeTool.changeTheme(themeToolValuesMap[val])
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Review theme loading logic

The theme loading logic has potential issues:

  1. The loadedTheme flag prevents subsequent theme changes
  2. No error handling for invalid theme values
  3. No cleanup of theme tool instance

Consider these improvements:

 watch(
   () => router.currentRoute.value.params.theme,
   (val) => {
-    if (!loadedTheme && themeToolValuesMap[val]) {
+    if (themeToolValuesMap[val]) {
       currentThemeKey.value = val
       const themeTool = new TinyThemeTool()
       themeTool.changeTheme(themeToolValuesMap[val])
-      loadedTheme = true
+    } else {
+      console.warn(`Theme '${val}' not found in themeToolValuesMap`)
     }
   }
 )

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +28 to +34
{
value: [OLD_THEME],
label: isEn ? 'Default Theme' : '冰川主题',
tips: isEn ? 'Accurate, Efficient, Distinct' : '精准、高效、清晰',
icon: glaciersIcon,
bgImage: glaciers
},
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Based on the evidence gathered, I can now provide the final response:

Theme metadata for OLD_THEME is inconsistent with its identifier

The OLD_THEME (defined as 'old-theme' in const.ts) is being presented with misleading metadata:

  • It's labeled as "Default Theme"/"冰川主题" (Glacier theme)
  • It uses glacier-themed assets (glaciers.png, glaciers-icon.png)
  • The description suggests "Accurate, Efficient, Distinct"/"精准、高效、清晰"

This creates a confusing user experience as the theme name 'old-theme' doesn't match its presentation as a glacier/default theme. The theme metadata should accurately reflect the theme's identity and visual characteristics.

🔗 Analysis chain

Verify theme metadata for OLD_THEME

The OLD_THEME entry reuses the "冰川主题" (Glacier theme) metadata. This might be confusing for users if the visual appearance doesn't match the theme name and description.


Let me check the content of these files to understand how the theme names and descriptions are used.


Let me check the OLD_THEME definition and usage to understand its relationship with the theme metadata.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other occurrences of theme names/descriptions
rg -l "冰川主题|Glacier theme|Default Theme"

Length of output: 254


Script:

#!/bin/bash
# Check content of files containing theme references
echo "=== useTheme.js ==="
rg -A 2 -B 2 "冰川主题|Glacier theme|Default Theme" examples/sites/src/tools/useTheme.js

echo -e "\n=== changelog.md ==="
rg -A 2 -B 2 "冰川主题|Glacier theme|Default Theme" examples/sites/demos/pc/webdoc/changelog.md

echo -e "\n=== theme-en.md ==="
rg -A 2 -B 2 "冰川主题|Glacier theme|Default Theme" examples/sites/demos/pc/webdoc/theme-en.md

echo -e "\n=== badge.js ==="
rg -A 2 -B 2 "冰川主题|Glacier theme|Default Theme" examples/sites/demos/mobile-first/app/badge/webdoc/badge.js

echo -e "\n=== pc.vue ==="
rg -A 2 -B 2 "冰川主题|Glacier theme|Default Theme" examples/docs/newsrc/pc.vue

Length of output: 2302


Script:

#!/bin/bash
# Search for OLD_THEME definition and usage
echo "=== OLD_THEME definition ==="
rg -A 2 -B 2 "OLD_THEME.*=|const.*OLD_THEME|let.*OLD_THEME|var.*OLD_THEME"

echo -e "\n=== OLD_THEME usage ==="
rg -A 2 -B 2 "OLD_THEME"

Length of output: 1823

@@ -143,7 +143,7 @@ const state = reactive({

const designThemeMap = {
aurora: 'tinyAuroraTheme',
infinity: 'tinyInfinityTheme'
old: 'tinyOldTheme'
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Breaking Change: Renamed 'infinity' theme to 'old'

This change removes support for the 'infinity' theme key, which could break existing implementations using this theme.

Consider:

  1. Adding a deprecation notice for 'infinity' theme
  2. Supporting both theme keys temporarily for backward compatibility
  3. Documenting the migration path in the changelog

@kagol kagol merged commit f07fa1a into dev Dec 25, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants