Skip to content

fix(radio): [radio,select,tree-select,checkbox,radio,button] fix the style of dark themes #3237

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 6 commits into from
Apr 3, 2025

Conversation

MomoPoppy
Copy link
Collaborator

@MomoPoppy MomoPoppy commented Apr 3, 2025

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

    • Added an extra loading button to demo pages, offering additional visual feedback during loading.
  • Style

    • Enhanced dark theme visuals with refined opacity and background mask adjustments.
    • Improved loading state styles for buttons with updated visual cues.
    • Refined interaction states for checkboxes, options, and radios for clearer hover and disabled effects.
    • Streamlined tree view spacing for a more consistent and polished layout.
  • Tests

    • Updated test cases for buttons and checkboxes to reflect new visual specifications and selector adjustments.

Copy link

Walkthrough

This pull request addresses issues related to the dark theme in the Tiny Vue project. It includes changes to the button, checkbox, option, radio, and tree components, focusing on improving the visual consistency and functionality of these components in dark mode.

Changes

Files Summary
examples/sites/demos/pc/app/button/loading-composition-api.vue, examples/sites/demos/pc/app/button/loading.vue Added additional loading buttons for demonstration purposes.
packages/theme/src/base/dark-theme.less Adjusted color variables for better visual consistency in dark mode.
packages/theme/src/button/index.less, packages/theme/src/button/vars.less Enhanced button styles, particularly for loading and disabled states.
packages/theme/src/checkbox/index.less Improved checkbox styles for active and disabled states.
packages/theme/src/option/index.less, packages/theme/src/option/vars.less Updated option component styles for hover and disabled states.
packages/theme/src/radio/vars.less Modified radio button styles for checked and disabled states.
packages/theme/src/tree/index.less, packages/theme/src/tree/vars.less Refined tree component padding and guide line styles.

@@ -111,12 +111,14 @@
&:active,
&:focus,
&:hover,
&.is-active {
&.is-active,
&.is-loading.is-loading.is-loading.is-loading.is-loading {

Choose a reason for hiding this comment

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

The repeated class .is-loading.is-loading.is-loading.is-loading.is-loading seems to be a mistake. It should be corrected to a single .is-loading to avoid redundancy and potential issues.

@@ -221,9 +223,8 @@

// 禁用态+loading 优先级最高, 五优先级
&.is-disabled.is-disabled.is-disabled.is-disabled.is-disabled,

Choose a reason for hiding this comment

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

The repeated class .is-disabled.is-disabled.is-disabled.is-disabled.is-disabled should be corrected to a single .is-disabled to avoid redundancy and potential issues.

Copy link

github-actions bot commented Apr 3, 2025

[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

@MomoPoppy MomoPoppy changed the title Momo poppy/fix dark theme 0402 fix(radio): [radio,select,tree-select,checkbox,radio,button] fix the style of dark themes Apr 3, 2025
@github-actions github-actions bot added the bug Something isn't working label Apr 3, 2025
Copy link

coderabbitai bot commented Apr 3, 2025

Walkthrough

This pull request introduces additional loading button instances in two Vue demo files and refines the styling across various components within the theme package. The changes include new CSS variables, updated color definitions, and adjustments to SVG fill properties and padding for buttons, checkboxes, options, radio buttons, and tree nodes. Overall, the modifications improve the visual presentation of loading states and disabled elements without altering any exported or public JavaScript interfaces.

Changes

File(s) Change Summary
examples/sites/demos/pc/app/button/loading.vue
examples/sites/demos/pc/app/button/loading-composition-api.vue
Added a second <tiny-button> (without the type attribute) in the template with two extra line breaks, maintaining the loading state and text "加载中".
packages/theme/src/base/dark-theme.less Updated CSS custom properties: modified --tv-color-icon-control-disabled opacity and standardized --tv-color-bg-mask-block to use rgba.
packages/theme/src/button/index.less
packages/theme/src/button/vars.less
Introduced new loading state styles for buttons and added CSS variables for default and primary loading icon colors; minor formatting updates included.
packages/theme/src/checkbox/index.less Adjusted SVG fill properties for checkbox icons, refined hover effects, and added a cursor: not-allowed style for disabled states.
packages/theme/src/option/index.less
packages/theme/src/option/vars.less
Modified SVG icon fills for various option states, added a new hover color variable, and removed an unused hover variable for unchecked borders.
packages/theme/src/radio/vars.less Updated the variable for the checked & disabled border color to reference a new icon-based color with a fallback.
packages/theme/src/tree/index.less
packages/theme/src/tree/vars.less
Replaced the left padding variable (--tv-Tree-node-padding-left) with a more generalized horizontal padding variable (--tv-Tree-node-padding-x) for consistent spacing.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant VueComponent
    participant TinyButton

    User->>VueComponent: Request loading page
    VueComponent->>TinyButton: Render first tiny-button (loading state)
    VueComponent->>TinyButton: Render second tiny-button without type attribute
    User->>VueComponent: View updated buttons with refined styling
Loading

Possibly related PRs

Suggested labels

enhancement

Poem

Hop along, I am a coding bunny,
New buttons load, making our UI sunny.
With extra breaks and fresh CSS hues,
Icons and paddings now get their dues.
I dance in lines and style arrays,
Cheering for updates in our code days! 🐰
CodeRabbit leads us through bright, playful ways!

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

examples/sites/demos/pc/app/checkbox/basic-usage.spec.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-vue".

(The package "eslint-plugin-vue" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-vue@latest --save-dev

The plugin "eslint-plugin-vue" was referenced from the config file in ".eslintrc.js » @antfu/eslint-config » @antfu/eslint-config-vue".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

examples/sites/demos/pc/app/select/nest-radio-grid-much-data.spec.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-vue".

(The package "eslint-plugin-vue" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-vue@latest --save-dev

The plugin "eslint-plugin-vue" was referenced from the config file in ".eslintrc.js » @antfu/eslint-config » @antfu/eslint-config-vue".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

examples/sites/demos/pc/app/button/dynamic-disabled.spec.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-vue".

(The package "eslint-plugin-vue" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-vue@latest --save-dev

The plugin "eslint-plugin-vue" was referenced from the config file in ".eslintrc.js » @antfu/eslint-config » @antfu/eslint-config-vue".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

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: 0

🧹 Nitpick comments (3)
packages/theme/src/tree/index.less (2)

238-238: Update tree node connection line positioning

The calculation for the left property in the pseudo-element now uses var(--tv-Tree-node-padding-x) instead of the previous padding variable. This change promotes consistency with the updated naming convention for tree node padding.


252-252: Standardize content indent offset

Similarly, the left value in the .content-indent::before block has been updated to use var(--tv-Tree-node-padding-x). Please verify that all related components are aligned with this new variable.

packages/theme/src/button/index.less (1)

347-349: Icon-Only Button Hover Color Update
The updated hover styling for icon-only buttons uses the variable var(--tv-Button-bg-color-only-icon-hover) to set the SVG fill on hover. This change should help improve the visual feedback in dark theme scenarios.
Please double-check that this variable provides adequate contrast and aligns with the design guidelines for dark mode.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a13b57e and fa4e5e9.

📒 Files selected for processing (11)
  • examples/sites/demos/pc/app/button/loading-composition-api.vue (1 hunks)
  • examples/sites/demos/pc/app/button/loading.vue (1 hunks)
  • packages/theme/src/base/dark-theme.less (2 hunks)
  • packages/theme/src/button/index.less (6 hunks)
  • packages/theme/src/button/vars.less (4 hunks)
  • packages/theme/src/checkbox/index.less (1 hunks)
  • packages/theme/src/option/index.less (2 hunks)
  • packages/theme/src/option/vars.less (2 hunks)
  • packages/theme/src/radio/vars.less (1 hunks)
  • packages/theme/src/tree/index.less (3 hunks)
  • packages/theme/src/tree/vars.less (1 hunks)
🔇 Additional comments (26)
examples/sites/demos/pc/app/button/loading.vue (1)

4-6: UI Enhancement: Consistent Spacing in Loading State

The addition of two <br /> elements and a secondary <tiny-button> (without an explicit type) creates better visual separation during loading. Please verify that the resulting spacing meets the design requirements for the dark theme.

examples/sites/demos/pc/app/button/loading-composition-api.vue (1)

4-6: UI Enhancement in Composition API Template

Introducing two <br /> elements followed by an additional <tiny-button> (without the type attribute) mirrors the changes in the standard template. This helps ensure consistency across different Vue API styles while maintaining the appropriate loading state visuals.

packages/theme/src/tree/vars.less (1)

65-66: CSS Variable Renaming: Tree Node Padding Update

The variable previously used for node left padding appears to have been renamed to --tv-Tree-node-padding-x, reflecting a shift to a generalized horizontal padding approach. Please ensure that all component styles referencing the old variable are updated accordingly to prevent inconsistencies.

packages/theme/src/radio/vars.less (1)

36-37: CSS Variable Update: Radio Button Disabled Border Color

The update to --tv-Radio-input-checked-disabled-border-color now references var(--tv-color-icon-checked-disabled, #dbdbdb), which should help standardize the appearance of disabled radio buttons, especially under dark theme conditions. Confirm that all related components properly reflect this adjusted styling.

packages/theme/src/option/vars.less (1)

28-34: CSS Variables Update: Checkbox Hover State Styling

A new variable --tv-Option-icon-color-hover has been introduced to control the hover color for checkbox icons, effectively replacing the older hover styling mechanism (previously managed by --tv-Option-unchecked-border-color-hover). This change enhances semantic clarity and should improve consistency across UI interactions. Please verify that any legacy styles dependent on the old variable are correctly migrated to the new system.

packages/theme/src/tree/index.less (1)

360-360: Adjust horizontal padding using new variable

The padding now uses padding: 0 var(--tv-Tree-node-padding-x);, which aligns the horizontal spacing with the new padding variable. This improves overall layout consistency.

packages/theme/src/checkbox/index.less (7)

153-158: Refine inner input SVG sizing

The SVG icons within the .@{checkbox-prefix-cls}__inner block now correctly adopt the font size from var(--tv-Checkbox-icon-size). This change ensures consistent icon sizing across checkboxes.


159-166: Update fill for checked and half-selected states

The fill for .icon-checked-sur and .icon-halfselect now uses var(--tv-Checkbox-bg-color-active), with their path:last-child set to var(--tv-Checkbox-border-color-inverse). This update provides clearer visual feedback for active states.


168-174: Correct default fill for unchecked icon

The .icon-check element now has its fill correctly set to var(--tv-Checkbox-unchecked-border-color), and the path:first-child is explicitly made transparent. This adjustment reduces visual ambiguity between different checkbox states.


176-178: Enhance hover feedback for checkbox icons

During hover, the .icon-check now updates its fill to var(--tv-Checkbox-unchecked-border-color-hover), improving the user’s interaction feedback.


182-184: Proper disabled cursor styling

Disabling the input now correctly applies cursor: not-allowed, clearly signifying the non-interactive state.


185-193: Refine disabled state icon styling

Within the disabled state, .icon-checked-sur and .icon-halfselect now use var(--tv-Checkbox-checked-disabled-bg-color) and set their path:last-child fill to var(--tv-Checkbox-icon-inverse-disabled). This enhances the visual distinction for disabled checkboxes.


194-200: Normalize disabled styling for unchecked icon

The .icon-check in a disabled state now uniformly applies var(--tv-Checkbox-bg-color-disabled) to both its fill and path:first-child, ensuring consistency.

packages/theme/src/option/index.less (3)

52-57: Update SVG fill for selected option icons

The .checked-sur.tiny-svg and .halfselect.tiny-svg selectors now apply a fill of var(--tv-Option-icon-color-checked) with the path:last-child using var(--tv-Option-icon-inverse-disabled). This change aligns the selected state visuals with the updated theme variables.


58-67: Introduce hover state for option check icons

The .check.tiny-svg block now sets a default fill using var(--tv-Option-icon-color-unchecked) and changes on hover to var(--tv-Option-icon-color-hover). This provides enhanced visual cues on interaction.


113-120: Refine disabled state styling for option check icons

Disabled checkbox icons within options now correctly use var(--tv-Option-icon-color-unchecked-disabled) for the .check class, with the inner path:first-child receiving var(--tv-Option-bg-color-disabled). This strengthens the visual treatment for disabled options.

packages/theme/src/base/dark-theme.less (2)

331-332: Adjust disabled icon opacity for dark theme

The variable --tv-color-icon-control-disabled has been updated to rgba(255, 255, 255, 0.15) for a subtler disabled icon appearance across checkbox and radio components. Confirm that this opacity meets design requirements.


349-350: Normalize background mask variable format

Changing from rgb(26, 26, 26, 70%) to rgba(26, 26, 26, 70%) for --tv-color-bg-mask-block ensures a proper RGBA format, which is essential for transparency effects in the dark theme.

packages/theme/src/button/vars.less (2)

93-95: Add loading icon color for default button state

A new variable --tv-Button-icon-color-default-loading has been introduced, inheriting its value from var(--tv-color-icon-control, #191919). This allows for distinct styling of loading state icons for default buttons.


104-105: Introduce loading icon color for primary buttons

The addition of --tv-Button-icon-color-primary-loading, which draws from var(--tv-color-icon-inverse-tint, #ffffff), ensures that primary buttons have a dedicated loading icon color. Verify that the loading indicators integrate well with the overall theme.

packages/theme/src/button/index.less (6)

5-6: Variable Declaration with Tilde
The use of the tilde (~) in the declarations of @button-prefix-cls and @svg-prefix-cls is correct. It outputs the unquoted string values and ensures proper interpolation with other Less variables.


114-115: Redundant .is-loading Repetition
The selector repeats .is-loading five times:

&.is-loading.is-loading.is-loading.is-loading.is-loading {

This redundancy can lead to confusion and difficulty in maintenance. As noted in previous reviews, please simplify this to a single instance (&.is-loading).


225-232: Redundant .is-disabled Repetition
The disabled state selector uses the repeated class .is-disabled (five times) as well as repeated attribute selectors. This pattern is redundant and could be streamlined to a single class to improve readability and maintenance.


248-259: Enhanced Loading State Styling
A new block for the .is-loading state has been added for both default and primary button styles. This addition clearly differentiates the loading state by setting SVG fill colors using the variables --tv-Button-icon-color-default-loading and --tv-Button-icon-color-primary-loading.
Please verify that these variables are defined (e.g., in vars.less) and that they provide the correct contrast for both dark and light themes.


237-245: Disabled Icon-Only Button Styling
The block for .is-only-icon under the disabled state now updates the SVG fill and sets the background to transparent for buttons without borders. This approach is appropriate for dark mode adjustments.
Ensure that var(--tv-Button-icon-color-disabled) is defined with color values that maintain sufficient contrast in dark theme contexts.


373-378: Disabled Icon Hover State Styling
Within the disabled icon-only buttons, the hover state now sets the SVG fill color using var(--tv-Button-disabled-color-only-icon-hover). This ensures that even in the disabled state, the icon’s visual treatment is clear.
Verify that this variable is defined and that its value delivers consistent UI behavior under dark theme conditions.

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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between fa4e5e9 and 2836b10.

📒 Files selected for processing (3)
  • examples/sites/demos/pc/app/button/dynamic-disabled.spec.ts (1 hunks)
  • examples/sites/demos/pc/app/checkbox/basic-usage.spec.ts (1 hunks)
  • examples/sites/demos/pc/app/select/nest-radio-grid-much-data.spec.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: PR E2E Test (pnpm test:e2e3)
🔇 Additional comments (2)
examples/sites/demos/pc/app/checkbox/basic-usage.spec.ts (1)

8-8:

❓ Verification inconclusive

Updated SVG path selector to match updated component structure.

The selector has been changed from .first() to .nth(1) to target the second SVG path instead of the first one. This change appears to be necessary to adapt the test to structural changes in the checkbox component's SVG implementation as part of the dark theme styling fixes.


🏁 Script executed:

#!/bin/bash
# Check the structure of the SVG paths in the checkbox component to verify why we need to target the second path
cd examples/sites/demos/pc
rg -A 5 "checkbox__inner svg path" --type=vue

Length of output: 104


Re-run verification of Vue component structure for updated SVG path selector

The previous command failed because the “vue” file type wasn’t recognized. To verify that targeting the second SVG path (using .nth(1)) is indeed required by the updated component structure, please run the following command to search within Vue files:

#!/bin/bash
# Re-run search for the SVG path structure in Vue files
rg --type-add "vue:*.vue" -A 5 "checkbox__inner svg path" examples/sites/demos/pc

Ensure that the output confirms that the component now contains multiple SVG path elements and that the intended element is indeed the second one. This will validate the change from .first() to .nth(1) made for the dark theme styling fixes.

examples/sites/demos/pc/app/button/dynamic-disabled.spec.ts (1)

15-15:

✅ Verification successful

Updated disabled button border color to match new theme specifications.

The expected border-bottom-color has been changed from rgb(240, 240, 240) to rgb(219, 219, 219), which is a slightly darker gray. This change aligns with the PR objective to fix dark theme styling issues.


🏁 Script executed:

#!/bin/bash
# Check if this border color value is consistently applied in the theme CSS variables
cd packages/theme/src
rg -A 1 "\-\-tv\-color\-border\-disabled" --type=less

Length of output: 3539


Action: Disabled Button Border Color Update Confirmed

The test update in examples/sites/demos/pc/app/button/dynamic-disabled.spec.ts now correctly expects the disabled button’s border-bottom-color to be rgb(219, 219, 219). This value matches the theme specification where the CSS variable --tv-color-border-disabled falls back to #dbdbdb (i.e. rgb(219, 219, 219)) in several theme files (e.g., button/vars.less). The change effectively replaces the old expectation of rgb(240, 240, 240) to address the dark theme styling issues.

@@ -32,5 +32,6 @@ test('下拉表格大数据', async ({ page }) => {
await expect(row).toHaveCount(6)
await row.nth(5).scrollIntoViewIfNeeded()
await expect(row).toHaveCount(6)
await page.waitForTimeout(500)
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Added timeout before clicking on grid row to improve test stability.

Adding a fixed timeout of 500ms before clicking on a row element might help with test stability, but fixed timeouts can make tests flaky and unpredictable. Consider using explicit waiting conditions instead.

-  await page.waitForTimeout(500)
+  // Wait for element to be stable and ready for interaction instead of using a fixed timeout
+  await page.getByRole('row', { name: '华南区 12 广东省 广州市' }).waitFor({state: 'visible', timeout: 5000})

🏁 Script executed:

#!/bin/bash
# Check for other instances of waitForTimeout in the codebase that might benefit from similar improvements
cd examples/sites/demos/pc
rg "waitForTimeout" --type=ts

Length of output: 25658


Replace Fixed Timeout with Explicit Wait for Element Visibility

The current fixed timeout of 500 ms may boost stability in a quick fix, but it can ultimately lead to flakiness. It’s recommended to replace this fixed delay with an explicit wait that confirms the grid row element is visible and stable before interacting with it. For instance:

-  await page.waitForTimeout(500)
+  // Wait for the grid row element to become visible and stable before interaction
+  await page.getByRole('row', { name: '华南区 12 广东省 广州市' }).waitFor({ state: 'visible', timeout: 5000 })

This change not only targets a more reliable condition but also aligns with improvements observed in several other tests within the codebase. Please update this instance—and consider reviewing similar waitForTimeout usages—to enhance overall test stability.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
await page.waitForTimeout(500)
// Wait for element to be stable and ready for interaction instead of using a fixed timeout
await page.getByRole('row', { name: '华南区 12 广东省 广州市' }).waitFor({ state: 'visible', timeout: 5000 })

@zzcr zzcr merged commit 466796a into opentiny:dev Apr 3, 2025
8 of 10 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants