Skip to content

Conversation

@ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented Oct 19, 2025

Link issues

fixes #6953 #6915

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Fix Cascader to correctly handle async Items assignment by resetting its value when no items are provided and update tests to cover this behavior

Bug Fixes:

  • Clear stale Value and prevent incorrect display when Items are set asynchronously in the Cascader component

Enhancements:

  • Reset Value and _lastValue early when Items list is empty

Tests:

  • Update CascaderTest to expect null Value when no Items and to verify setting Items and Value asynchronously

Copilot AI review requested due to automatic review settings October 19, 2025 06:16
@bb-auto bb-auto bot added the bug Something isn't working label Oct 19, 2025
@bb-auto bb-auto bot added this to the 9.11.0 milestone Oct 19, 2025
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Oct 19, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR fixes the erroneous display of the Cascader component when its Items are set asynchronously by introducing an early-exit guard for empty Items in OnParametersSet (which resets the internal value state) and updating the unit test to verify that behavior.

Sequence diagram for async Items update in Cascader component

sequenceDiagram
participant "Parent Component"
participant "Cascader"
"Parent Component"->>"Cascader": Set Items asynchronously
activate "Cascader"
"Cascader"->>"Cascader": OnParametersSet()
alt Items is empty
"Cascader"->>"Cascader": Reset _lastValue and Value
"Cascader"-->>"Parent Component": Early exit (no display)
else Items is not empty
"Cascader"->>"Cascader": Continue normal processing
end
deactivate "Cascader"
Loading

Class diagram for updated Cascader component state handling

classDiagram
class Cascader {
  - string _lastValue
  - object Value
  - IEnumerable<Item> Items
  OnParametersSet()
}
Cascader : OnParametersSet()
Loading

File-Level Changes

Change Details Files
Guard against empty Items in OnParametersSet to reset component state
  • Initialize Items if null
  • Check for Items.Any() and, if false, clear _lastValue and Value
  • Return early to skip further parameter processing when no Items
src/BootstrapBlazor/Components/Cascader/Cascader.razor.cs
Enhance unit test to cover async Items assignment
  • Change assertion to expect Value is null when Items is not provided
  • Add step to set Items and Value in the test to simulate async loading
test/UnitTest/Components/CascaderTest.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#6953 Fix the bug where the Cascade component displays incorrectly when Items are set asynchronously.
#6953 Ensure that the Cascade component shows the correct value when Items are set asynchronously.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes an issue where the Cascader component displays incorrectly when Items are set asynchronously. The fix ensures that when no Items are provided, the component properly resets its internal state and Value property.

Key changes:

  • Modified OnParametersSet to check if Items is empty and reset state accordingly
  • Updated test to verify behavior when Items are initially absent then provided
  • Bumped version to 9.11.3-beta05

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/BootstrapBlazor/Components/Cascader/Cascader.razor.cs Added early return logic to reset Value and internal state when Items collection is empty
test/UnitTest/Components/CascaderTest.cs Enhanced test to verify Value behavior with and without Items data source
src/BootstrapBlazor/BootstrapBlazor.csproj Version bump to 9.11.3-beta05

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • The new test doesn’t assert the behavior after setting Items and Value asynchronously—please add an assertion to verify that the component’s Value updates to "3" as expected.
  • The inline test comment is in Chinese—consider translating it to English to keep the codebase language consistent.
  • In OnParametersSet, the early return when Items is empty may skip other initializations; consider restructuring the guard clause so you only reset state but still run any shared setup logic needed for async loading.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new test doesn’t assert the behavior after setting Items and Value asynchronously—please add an assertion to verify that the component’s Value updates to "3" as expected.
- The inline test comment is in Chinese—consider translating it to English to keep the codebase language consistent.
- In OnParametersSet, the early return when Items is empty may skip other initializations; consider restructuring the guard clause so you only reset state but still run any shared setup logic needed for async loading.

## Individual Comments

### Comment 1
<location> `src/BootstrapBlazor/Components/Cascader/Cascader.razor.cs:142` </location>
<code_context>
+        if (!Items.Any())
+        {
+            _lastValue = string.Empty;
+            Value = default;
+            return;
+        }
</code_context>

<issue_to_address>
**question:** Setting Value to default may not be appropriate for all value types.

Ensure that assigning default to Value is safe for all possible Value types, especially reference types or complex structs.
</issue_to_address>

### Comment 2
<location> `test/UnitTest/Components/CascaderTest.cs:180-186` </location>
<code_context>
+        // 未提供数据源时 Value 赋值无效
+        Assert.Null(cut.Instance.Value);
+
+        cut.SetParametersAndRender(pb =>
+        {
+            pb.Add(a => a.Items, items);
+            pb.Add(a => a.Value, "3");
+            pb.Add(a => a.ShowFullLevels, false);
+        });
     }
</code_context>

<issue_to_address>
**suggestion (testing):** Missing assertion for Value after setting Items and Value asynchronously.

Add an assertion to check that cut.Instance.Value is set to "3" after setting Items and Value asynchronously.

```suggestion
        cut.SetParametersAndRender(pb =>
        {
            pb.Add(a => a.Items, items);
            pb.Add(a => a.Value, "3");
            pb.Add(a => a.ShowFullLevels, false);
        });

        // 验证异步设置 Items 和 Value 后 Value 被正确赋值为 "3"
        Assert.Equal("3", cut.Instance.Value);
    }
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov
Copy link

codecov bot commented Oct 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (313b0ba) to head (8b8ae5b).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #6954   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          740       740           
  Lines        31891     31896    +5     
  Branches      4472      4473    +1     
=========================================
+ Hits         31891     31896    +5     
Flag Coverage Δ
BB 100.00% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ArgoZhang ArgoZhang merged commit ab2a546 into main Oct 19, 2025
7 checks passed
@ArgoZhang ArgoZhang deleted the fix-cascade branch October 19, 2025 06:20
@ArgoZhang ArgoZhang linked an issue Oct 19, 2025 that may be closed by this pull request
1 task
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.

bug(Cascade): display incorrect when set Items async problem opening the modal the 2nd time

2 participants