Skip to content

Bug(1047330): Fixed MS audit agent issues in chart component. - #33

Merged
Indhumathy-Loganathan merged 3 commits into
source-stabilizefrom
1047330-Warnings
Aug 17, 2026
Merged

Indhumathy-Loganathan merged 3 commits into
source-stabilizefrom
1047330-Warnings

Conversation

@Yokesh-SF4393

@Yokesh-SF4393 Yokesh-SF4393 commented Aug 14, 2026 •

Copy link
Copy Markdown
Collaborator

Bug description

Fixed MS audit agent issues in chart component.

  • Parameter mutate issue - ChartSorting was directly modifying parameter values (PropertyName, Direction) within the child component.
  • Editor required usage issue - Required chart configuration parameters (XName, YName, PropertyName) could be left unset without any design-time warning.
  • Library doesn't leak per-circuit state issue - Shared font metric caches were being cleared whenever an individual chart instance was disposed.
  • Inline CSS - SVG selection components contained unnecessary inline styling and mutable style fields for fixed values.
  • Accessibility issue - SVG group elements with role="button" could be rendered without the expected accessibility state metadata.

Root cause

Need to fix the MS audit reported issues

  • Blazor parameters are parent-owned, and mutating [Parameter] properties inside a child component violates the component lifecycle contract.
  • The parameters were missing the [EditorRequired] attribute, preventing Razor from validating mandatory bindings.
  • ClearStaticStorage() was called during per-chart teardown even though the cached glyph measurements were process-wide, deterministic, and reusable.
  • Presentation-specific CSS (cursor:pointer, visibility:visible) was embedded directly in markup, and immutable style values were stored in mutable fields.
  • ARIA attributes were conditionally rendered and were not consistently applied for button-role SVG elements.

Solution description

Fixed all issues reported in MS audit related to charts.

  • Introduced internal accessor properties backed by private fields, removed parameter mutations, and updated all renderer call sites to use the internal accessors.
  • Added [EditorRequired] to ChartSeries.XName, ChartSeries.YName, and ChartSorting.PropertyName.
  • Removed the cache-clear operation from chart disposal and eliminated unused public setters so the static cache remains available across chart instances.
  • Moved cursor styling into private constant fields, removed redundant visibility: visible, and converted immutable style fields to const.
  • Standardized ARIA attribute rendering to ensure accessibility information is always emitted for interactive SVG elements.

Code Studio usage(Mandatory)

  • Code Studio used in this PR/MR?

    • Yes
    • No
  • If Yes: Primary use (choose one)

    • Generate new code
    • Refactor/improve existing code
    • Tests
    • Bug fix / debugging help
    • Docs / comments
    • Review assistance (explanations/summaries)
    • Other:
  • Outcome

    • Saved time
    • Neutral
    • Cost time
  • If “Cost time” explain in short (1 or 2 lines):

Impact assessment

  • Low - Affects a single feature with minimal user impact
  • Medium - Affects multiple features or has moderate user impact
  • High - Critical functionality or significant user impact

Reason for not identifying earlier

These issues are identified recently with MS audit agents.

Areas tested against this fix

Breaking changes

  • Yes (Tag breaking-issue)
  • No

If yes, provide breaking commit details link and migration guidance.

Regression testing

  • Verified fix doesn't reintroduce previous bugs
  • Checked edge cases and error scenarios

Action taken to prevent recurrence

  • Added/updated unit tests
  • Other (specify): _________________
  • NA

Automation status

  • BUnit (provide PR link: _________________)
  • Playwight (provide PR link: _________________)
  • NA

Cross-platform verification

  • Blazor Server
  • Blazor WASM
  • NA

Related issues

Is this issue present in EJ2 or other components?

  • Resolved in EJ2 (PR link: _________________)
  • Created task for EJ2 (Task link: _________________)
  • Needs attention in other components (tag needs-attention-coreteam)
  • NA

Output screenshots

Post the output screenshots if a UI is affected or added due to this bug.

API changes

  • New API added (API Review task link: _________________)
  • Existing API renamed/modified (API Review task link: _________________)
  • No API changes

Performance verification

  • Verified no memory leaks introduced
  • Verified no performance degradation
  • Not applicable

Reviewer Checklist

  • Reviewed the provided Code Studio usages related information.
  • Code changes follow component guidelines
  • All provided information reviewed and verified
  • Solution addresses the root cause effectively

@Sittiq3586 Sittiq3586 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Changes requested

/// or <see cref="ClearSortKey"/> are visible to renderers without mutating the
/// <see cref="PropertyName"/> parameter.
/// </summary>
internal string SortKey => _propertyName;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

private string _propertyName = null!;

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?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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 &lt;g&gt;. Pointer cursor is fixed for a dismiss button.
/// </summary>
private const string _closeCursorStyle = "cursor:pointer";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The value for _cursorStyle is updated in ChangeCursorAsync(). So, we can't add const here.

/// </code>
/// </example>
[Parameter]
[EditorRequired]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Updated changes.

@Sittiq3586 Sittiq3586 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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; and internal ListSortDirection SortDirection => _direction; as read-only accessors over the backing fields.

  • Removed all assignments to PropertyName and Direction from SetSortKeyAndDirection and ClearSortKey.

  • Migrated all 18+ read sites across ChartSeriesRenderer.cs, SeriesContainer.cs, and BubbleSeriesRenderer.cs from the parameter properties to the new accessors.

  • XML docs explicitly document the invariant:

    "Reads from the backing field so imperative updates via SetSortKeyAndDirection or ClearSortKey are visible to renderers without mutating the PropertyName parameter."

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] to XName and YName in ChartSeries.cs.
  • Added [EditorRequired] to PropertyName in Sorting.cs.
  • Tightened the PropertyName default from null! (null-forgiving operator suppresses warnings) to string.Empty, aligning with the new SortKey contract 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): Direction was intentionally not marked [EditorRequired]. This is defensible since the enum default 0 is 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.razor and SvgSelectionRect.razor: Replaced inline style="cursor:pointer; visibility: visible;" with a private const string _closeCursorStyle = "cursor:pointer" declared in each code-behind file.
  • Promoted _cursorStyle in SvgSelectionPath.razor.cs from a mutable field to const (it was never reassigned), with an XML doc explaining why it cannot be runtime-themed like the rect side.
  • Kept _cursorStyle as a mutable instance field in SvgSelectionRect.razor.cs because ChangeCursorAsync() requires mutating it. The author correctly addressed the reviewer's consistency concern with a clear technical justification.
  • Additional fix in SvgRendering.cs: OpenGroupElement now conditionally emits tabindex, aria-label, aria-hidden, data-point, and role only when non-empty. This eliminates litter like tabindex="" from the rendered DOM — a related MS audit concern for accessibility/HTML validity.

Note (non-blocking): The drop of visibility: visible from the inline style is a behavioral change in markup only — SVG <g> elements default to visibility: 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 × FontFamily tuple 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.Empty change and the _cursorStyle const asymmetry question) were addressed with sound reasoning.

Suggested pre-merge verifications (non-blocking)

  1. Run a final grep for any remaining _sorting.PropertyName or _sorting.Direction reads — should return zero.
  2. Execute existing sorting test suites to confirm SetSortKeyAndDirection → render → SortDirection read path still works end-to-end.
  3. Spot-check a chart with imperative sorting in a sample app.

Optional follow-ups (don't block this PR)

  • Add BUnit tests for SetSortKeyAndDirection and ClearSortKey to lock in the new non-mutation contract for future contributors.
  • Declare _propertyName as non-nullable string (not string?) now that it defaults to string.Empty, for stronger static analyzer guarantees.
  • Document Direction omission 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

4 participants