Repository navigation
Bug(1047330): Fixed MS audit agent issues in chart component. - #33
Conversation
| /// or <see cref="ClearSortKey"/> are visible to renderers without mutating the | ||
| /// <see cref="PropertyName"/> parameter. | ||
| /// </summary> | ||
| internal string SortKey => _propertyName; |
There was a problem hiding this comment.
We already possess private fields for those parameters to enable dynamic updates. Why is it not possible to utilize them by modifying the access modifier to internal?
There was a problem hiding this comment.
Changing the existing backing fields from private to internal does not resolve the audit finding, because the component would still be mutating its own [Parameter] properties.
The new accessor properties separate the mutable internal state from the parent-owned parameters, eliminating parameter mutation while preserving existing behavior.
| /// <summary> | ||
| /// Inline style applied to the close-icon <g>. Pointer cursor is fixed for a dismiss button. | ||
| /// </summary> | ||
| private const string _closeCursorStyle = "cursor:pointer"; |
There was a problem hiding this comment.
In SvgSelectionPath.razor.cs, _cursorStyle is correctly promoted to const, but in SvgSelectionRect.razor.cs, the existing _cursorStyle field remains a mutable instance field (private string _cursorStyle = "cursor:move") — only _closeCursorStyle is added as const. For consistency, _cursorStyle in SvgSelectionRect should also be made const.
There was a problem hiding this comment.
The value for _cursorStyle is updated in ChangeCursorAsync(). So, we can't add const here.
| /// </code> | ||
| /// </example> | ||
| [Parameter] | ||
| [EditorRequired] |
There was a problem hiding this comment.
PropertyName now has [EditorRequired] but still defaults to null! — the null-forgiving operator suppresses warnings. Consider changing the default to string.Empty for consistency with XName/YName.
There was a problem hiding this comment.
Updated changes.
Sittiq3586
left a comment
There was a problem hiding this comment.
PR Approval Comment — #33
PR: Bug(1047330): Fixed MS audit agent issues in chart component.
Branch: 1047330-Warnings → source-stabilize
Author: @Yokesh-SF4393
Status: ✅ Approved
Overview
This PR addresses four MS Audit agent findings in the Blazor Chart component without introducing any behavioral regressions. The fixes are well-scoped, properly documented, and consistent with Blazor component design patterns. Approving for merge.
MS Audit Concerns — Verification
✅ 1. Parameter Mutation Issue — Sorting.cs
Audit finding: Imperative methods (SetSortKeyAndDirection, ClearSortKey) were mutating [Parameter] properties (PropertyName, Direction), violating Blazor's parameter contract and risking re-render loops.
Resolution:
-
Introduced
internal string SortKey => _propertyName;andinternal ListSortDirection SortDirection => _direction;as read-only accessors over the backing fields. -
Removed all assignments to
PropertyNameandDirectionfromSetSortKeyAndDirectionandClearSortKey. -
Migrated all 18+ read sites across
ChartSeriesRenderer.cs,SeriesContainer.cs, andBubbleSeriesRenderer.csfrom the parameter properties to the new accessors. -
XML docs explicitly document the invariant:
"Reads from the backing field so imperative updates via
SetSortKeyAndDirectionorClearSortKeyare visible to renderers without mutating thePropertyNameparameter."
Verdict: The right architectural choice. Mutating a [Parameter] from inside the component is a textbook Blazor anti-pattern; the new pattern exposes a controlled read-only view of imperative state while keeping the parameter contract intact. The reviewer-suggested alternative of merely widening the backing field's access modifier was correctly rejected in favor of the more disciplined accessor approach.
✅ 2. EditorRequired Usage Issue — ChartSeries.cs, Sorting.cs
Audit finding: Required Blazor parameters were not annotated with [EditorRequired], allowing consumers to silently skip required values.
Resolution:
- Added
[EditorRequired]toXNameandYNameinChartSeries.cs. - Added
[EditorRequired]toPropertyNameinSorting.cs. - Tightened the
PropertyNamedefault fromnull!(null-forgiving operator suppresses warnings) tostring.Empty, aligning with the newSortKeycontract that is non-nullable string.
Verdict: Consistent with Blazor's [EditorRequired] best practices. The follow-up default change addresses the reviewer's accurate observation that [EditorRequired] is undermined by a non-null-forgiving default.
Note (non-blocking):
Directionwas intentionally not marked[EditorRequired]. This is defensible since the enum default0is a meaningful sentinel, but a one-line justification in the PR description would prevent future churn.
✅ 3. Inline CSS Issue — SvgSelectionPath.razor, SvgSelectionRect.razor, SvgRendering.cs
Audit finding: Razor markup containing inline style="..." attributes.
Resolution:
SvgSelectionPath.razorandSvgSelectionRect.razor: Replaced inlinestyle="cursor:pointer; visibility: visible;"with aprivate const string _closeCursorStyle = "cursor:pointer"declared in each code-behind file.- Promoted
_cursorStyleinSvgSelectionPath.razor.csfrom a mutable field toconst(it was never reassigned), with an XML doc explaining why it cannot be runtime-themed like the rect side. - Kept
_cursorStyleas a mutable instance field inSvgSelectionRect.razor.csbecauseChangeCursorAsync()requires mutating it. The author correctly addressed the reviewer's consistency concern with a clear technical justification. - Additional fix in
SvgRendering.cs:OpenGroupElementnow conditionally emitstabindex,aria-label,aria-hidden,data-point, androleonly when non-empty. This eliminates litter liketabindex=""from the rendered DOM — a related MS audit concern for accessibility/HTML validity.
Note (non-blocking): The drop of
visibility: visiblefrom the inline style is a behavioral change in markup only — SVG<g>elements default tovisibility: visible, so the rendered output is identical. Worth a one-line callout in the PR description for future reviewers.
Verdict: Cleanly resolved. The conditional attribute emission in OpenGroupElement is a thoughtful bonus fix that goes beyond the literal audit finding.
✅ 4. Library Doesn't Leak Per-Circuit State Issue — SfChart.razor.cs, ChartHelper.cs
Audit finding: SfChart.UnWireEventsAsync was calling ChartHelper.ClearStaticStorage() on every chart teardown, evicting entries from the process-wide SizePerCharacter and ChartFontKeys caches — forcing every other live chart on every other circuit to re-measure glyphs via JS interop. A textbook example of per-circuit teardown incorrectly touching process-wide state.
Resolution:
- Removed the call from
UnWireEventsAsync. - Changed the cache properties from
{ get; set; }to read-only{ get; }so they cannot be reassigned. - Kept
ClearStaticStorage()for explicit callers (e.g., tests) but annotated it with[EditorBrowsable(Never)]and[Browsable(false)]to keep it out of IntelliSense. - Added comprehensive XML doc comments to both caches and to
ClearStaticStorage()explaining:- Why the cache is process-wide (glyph metrics are deterministic across the process lifetime).
- Why clearing on disposal is harmful (invalidates entries still in use by other live charts).
- The bound on cache size (
character × FontWeight × FontStyle × FontFamilytuple space).
Verdict: Excellent fix with strong design rationale captured in the XML docs. On a server with N concurrent circuits, the previous code could thrash the cache up to N times per chart dispose. After this fix, the cache lives for the process lifetime, which is correct given its bounded key space.
Cross-Cutting Notes
Strengths
- Minimal, surgical scope: ~131/−53 lines touching exactly the four flagged areas with no opportunistic refactors.
- Documentation-first approach: The XML doc comments explain why, not just what. This is the kind of design rationale that prevents future regressions of the same audit findings.
- Responsive to review: Both inline review comments (the
null!→string.Emptychange and the_cursorStyleconst asymmetry question) were addressed with sound reasoning.
Suggested pre-merge verifications (non-blocking)
- Run a final grep for any remaining
_sorting.PropertyNameor_sorting.Directionreads — should return zero. - Execute existing sorting test suites to confirm
SetSortKeyAndDirection→ render →SortDirectionread path still works end-to-end. - Spot-check a chart with imperative sorting in a sample app.
Optional follow-ups (don't block this PR)
- Add BUnit tests for
SetSortKeyAndDirectionandClearSortKeyto lock in the new non-mutation contract for future contributors. - Declare
_propertyNameas non-nullablestring(notstring?) now that it defaults tostring.Empty, for stronger static analyzer guarantees. - Document
Directionomission from[EditorRequired]in the PR description or in code.
Final Decision
Approving this PR. No major concerns. The only change with non-trivial surface area is the sorting accessor refactor, and even there the risk is mitigated by the fact that the diff is a pure rename — the data flow, control flow, and side effects are unchanged. The other three changes are correctness/perf improvements with no behavior regressions.
Great work addressing the audit findings in a single, well-reasoned PR.
Bug description
Fixed MS audit agent issues in chart component.
Root cause
Need to fix the MS audit reported issues
Solution description
Fixed all issues reported in MS audit related to charts.
Code Studio usage(Mandatory)
Code Studio used in this PR/MR?
If
Yes: Primary use (choose one)Outcome
If “Cost time” explain in short (1 or 2 lines):
Impact assessment
Reason for not identifying earlier
These issues are identified recently with MS audit agents.
Areas tested against this fix
Breaking changes
breaking-issue)If yes, provide breaking commit details link and migration guidance.
Regression testing
Action taken to prevent recurrence
Automation status
Cross-platform verification
Related issues
Is this issue present in EJ2 or other components?
needs-attention-coreteam)Output screenshots
Post the output screenshots if a UI is affected or added due to this bug.
API changes
Performance verification
Reviewer Checklist