Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideTreeView APIs that operate on Items are now null-safe by guarding against Items being null before accessing or mutating them, preventing potential null reference exceptions when no Items collection is set. Sequence diagram for TreeView.SetActiveItem null-safe behaviorsequenceDiagram
participant Caller
participant TreeView
participant Items
Caller->>TreeView: SetActiveItem(item)
alt Items is not null
TreeView->>Items: GetAllItems()
Items-->>TreeView: IEnumerable<TreeViewItem<TItem>>
TreeView->>TreeView: SetActiveItem(val)
else Items is null
TreeView->>TreeView: [no-op]
end
Sequence diagram for TreeView.ClearCheckedItems null-safe behaviorsequenceDiagram
participant Caller
participant TreeView
participant Items
participant TreeNodeStateCache
Caller->>TreeView: ClearCheckedItems()
alt Items is not null
TreeView->>Items: ForEach(item)
loop each item and subitem
TreeView->>item: CheckedState = UnChecked
TreeView->>TreeNodeStateCache: ToggleCheck(item)
TreeView->>item: GetAllTreeSubItems()
TreeView->>TreeNodeStateCache: ToggleCheck(subitem)
end
TreeView->>TreeView: StateHasChanged()
else Items is null
TreeView->>TreeView: [no-op]
end
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- In both SetActiveItem and ClearCheckedItems, consider using an early return when Items is null to reduce nesting and keep the methods’ main logic at the top level.
- Review whether ClearCheckedItems should still call StateHasChanged when Items is null, as the current guard prevents UI updates even if other state might have changed.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In both SetActiveItem and ClearCheckedItems, consider using an early return when Items is null to reduce nesting and keep the methods’ main logic at the top level.
- Review whether ClearCheckedItems should still call StateHasChanged when Items is null, as the current guard prevents UI updates even if other state might have changed.
## Individual Comments
### Comment 1
<location path="src/BootstrapBlazor/Components/TreeView/TreeView.razor.cs" line_range="845-854" />
<code_context>
{
- item.CheckedState = CheckboxState.UnChecked;
- _treeNodeStateCache.ToggleCheck(item);
- item.GetAllTreeSubItems().ToList().ForEach(s =>
+ Items.ForEach(item =>
{
- s.CheckedState = CheckboxState.UnChecked;
- _treeNodeStateCache.ToggleCheck(s);
+ item.CheckedState = CheckboxState.UnChecked;
+ _treeNodeStateCache.ToggleCheck(item);
</code_context>
<issue_to_address>
**suggestion (performance):** Avoid the `ToList()` allocation and use `foreach` for sub-items iteration.
`item.GetAllTreeSubItems().ToList().ForEach(...)` creates an unnecessary list just to use `List<T>.ForEach`. Iterate directly over `GetAllTreeSubItems()` with `foreach` (e.g., `foreach (var s in item.GetAllTreeSubItems()) { ... }`) to avoid extra allocations and keep the code clearer.
```suggestion
Items.ForEach(item =>
{
item.CheckedState = CheckboxState.UnChecked;
_treeNodeStateCache.ToggleCheck(item);
foreach (var s in item.GetAllTreeSubItems())
{
s.CheckedState = CheckboxState.UnChecked;
_treeNodeStateCache.ToggleCheck(s);
}
});
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| Items.ForEach(item => | ||
| { | ||
| s.CheckedState = CheckboxState.UnChecked; | ||
| _treeNodeStateCache.ToggleCheck(s); | ||
| item.CheckedState = CheckboxState.UnChecked; | ||
| _treeNodeStateCache.ToggleCheck(item); | ||
| item.GetAllTreeSubItems().ToList().ForEach(s => | ||
| { | ||
| s.CheckedState = CheckboxState.UnChecked; | ||
| _treeNodeStateCache.ToggleCheck(s); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
suggestion (performance): Avoid the ToList() allocation and use foreach for sub-items iteration.
item.GetAllTreeSubItems().ToList().ForEach(...) creates an unnecessary list just to use List<T>.ForEach. Iterate directly over GetAllTreeSubItems() with foreach (e.g., foreach (var s in item.GetAllTreeSubItems()) { ... }) to avoid extra allocations and keep the code clearer.
| Items.ForEach(item => | |
| { | |
| s.CheckedState = CheckboxState.UnChecked; | |
| _treeNodeStateCache.ToggleCheck(s); | |
| item.CheckedState = CheckboxState.UnChecked; | |
| _treeNodeStateCache.ToggleCheck(item); | |
| item.GetAllTreeSubItems().ToList().ForEach(s => | |
| { | |
| s.CheckedState = CheckboxState.UnChecked; | |
| _treeNodeStateCache.ToggleCheck(s); | |
| }); | |
| }); | |
| Items.ForEach(item => | |
| { | |
| item.CheckedState = CheckboxState.UnChecked; | |
| _treeNodeStateCache.ToggleCheck(item); | |
| foreach (var s in item.GetAllTreeSubItems()) | |
| { | |
| s.CheckedState = CheckboxState.UnChecked; | |
| _treeNodeStateCache.ToggleCheck(s); | |
| } | |
| }); |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #8170 +/- ##
==========================================
- Coverage 98.79% 98.79% -0.01%
==========================================
Files 766 766
Lines 34224 34230 +6
Branches 4699 4701 +2
==========================================
+ Hits 33811 33816 +5
- Partials 413 414 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Link issues
fixes #8169
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Add null-safety checks around TreeView Items usage to prevent errors when no items are set.
Bug Fixes: