Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented Aug 19, 2025

Link issues

fixes #6653

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

Improve SelectTree component by optimizing selection change handling, introducing caching for items and expanded items, standardizing private field naming, and cleaning up initialization logic.

Bug Fixes:

  • Prevent redundant ItemChanged invocation when the selected value remains unchanged

Enhancements:

  • Rename private fields to _selectedItem, _itemCache, and _expandedItemsCache and update Razor bindings
  • Cache the items list and its expanded items to avoid unnecessary recomputation in GetExpandedItems
  • Remove the obsolete OnInitializedAsync override and consolidate initialization in TriggerItemChanged
  • Move IconTheme injection to the top-level class scope

@ArgoZhang ArgoZhang requested a review from Copilot August 19, 2025 10:08
@bb-auto bb-auto bot added the chore This are tasks or bot action label Aug 19, 2025
@bb-auto bb-auto bot added this to the 9.9.0 milestone Aug 19, 2025
Copy link
Contributor

sourcery-ai bot commented Aug 19, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR refactors SelectTree's state management by replacing public properties with private fields, consolidates and optimizes the item caching logic, prevents redundant selection events, cleans up an unnecessary lifecycle override, and updates the component template binding.

Sequence diagram for optimized item selection event triggering

sequenceDiagram
    participant User
    participant SelectTree
    participant TreeViewItem
    User->>SelectTree: Selects an item
    SelectTree->>TreeViewItem: Check if item is already selected
    alt Item is not already selected
        SelectTree->>SelectTree: ItemChanged(currentItem)
    else Item is already selected
        SelectTree-->>User: No event triggered
    end
Loading

File-Level Changes

Change Details Files
Refactor selected item and cache storage
  • Replaced SelectedItem, ItemCache, ExpandedItemsCache properties with private fields (_selectedItem, _itemCache, _expandedItemsCache)
  • Removed obsolete property definitions
src/BootstrapBlazor/Components/Select/SelectTree.razor.cs
Optimize expanded items caching
  • Compare _itemCache against current Items and refresh _expandedItemsCache when source changes
  • Return cached _expandedItemsCache instead of rebuilding on each call
src/BootstrapBlazor/Components/Select/SelectTree.razor.cs
Prevent redundant ItemChanged invocation
  • Add condition in TriggerItemChanged to skip ItemChanged if selection value hasn’t changed
src/BootstrapBlazor/Components/Select/SelectTree.razor.cs
Remove unnecessary initialization override
  • Deleted OnInitializedAsync override that triggered initial selection based on Value
src/BootstrapBlazor/Components/Select/SelectTree.razor.cs
Update template binding for selected item
  • Changed input value binding from SelectedItem?.Text to _selectedItem?.Text
src/BootstrapBlazor/Components/Select/SelectTree.razor
Remove duplicate IconTheme injection
  • Removed redundant [Inject] IIconTheme property declaration
src/BootstrapBlazor/Components/Select/SelectTree.razor.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#6653 Prevent SelectTree's OnSelectedItemChanged event from being triggered when other controls (such as Select) change selection.

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 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 refactors the SelectTree component by converting public properties to private fields and removing the OnInitializedAsync override. The changes improve encapsulation and potentially fix timing issues in the component initialization.

  • Convert public properties to private fields with underscore prefix
  • Remove OnInitializedAsync override that was causing premature item changes
  • Update version number to 9.9.3-beta02

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
SelectTree.razor.cs Converts properties to private fields, removes OnInitializedAsync, and improves logic in TriggerItemChanged
SelectTree.razor Updates template to use the new private field name
BootstrapBlazor.csproj Increments version number to beta02

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 and they look great!


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.

@ArgoZhang ArgoZhang changed the title fix(SelectTree): fix(SelectTree): optimizing selection change handling Aug 19, 2025
@ArgoZhang ArgoZhang changed the title fix(SelectTree): optimizing selection change handling fix(SelectTree): optimize select item change event Aug 19, 2025
@ArgoZhang ArgoZhang merged commit dbb2914 into main Aug 19, 2025
5 checks passed
@ArgoZhang ArgoZhang deleted the fix-select-tree branch August 19, 2025 10:10
Copy link

codecov bot commented Aug 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (8517b7b) to head (09cc3ff).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #6654   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          739       739           
  Lines        31674     31667    -7     
  Branches      4459      4459           
=========================================
- Hits         31674     31667    -7     
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore This are tasks or bot action
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug(SelectTree): 页面刷新时触发 OnSelectedItemChanged 事件
1 participant