fix(react-avatar): make enclosure cleanup linear - #36738
Open
Tudor Popa (tudorpopams) wants to merge 1 commit into
Open
Tudor Popa (tudorpopams) wants to merge 1 commit into
Tudor Popa (tudorpopams) wants to merge 1 commit into
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot started reviewing on behalf of
Tudor Popa (tudorpopams)
September 15, 2026 12:45
View session
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No unresolved issues were identified that would block approval.
Pull request overview
Replaces quadratic enclosure cleanup in Avatar initials generation with a linear UTF-16 scan while preserving existing behavior.
Changes:
- Added indexed enclosure removal.
- Added semantic and performance regression tests.
- Added a patch release change file.
File summaries
| File | Description |
|---|---|
| packages/react-components/react-avatar/library/src/utils/getInitials.ts | Updated as part of this pull request. |
| packages/react-components/react-avatar/library/src/utils/getInitials.test.ts | Updated as part of this pull request. |
| packages/react-components/react-avatar/library/src/utils/getInitials.enclosures.test.tsx | Updated as part of this pull request. |
| change/@fluentui-react-avatar-43a7ed01-2573-4a4a-9a5b-6b56387b4e86.json | Updated as part of this pull request. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
📊 Bundle size reportUnchanged fixtures
|
|
Pull request demo site: URL |
Tudor Popa (tudorpopams)
marked this pull request as ready for review
September 15, 2026 13:35
Tudor Popa (tudorpopams)
requested review from
a team and
Valentyna (ValentinaKozlova)
as code owners
September 15, 2026 13:35
Tudor Popa (tudorpopams)
requested review from
Dmytro Kirpa (dmytrokirpa) and
Victor Genaev (mainframev)
September 15, 2026 13:35
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Previous Behavior
Avatar's default name-to-initials path repeatedly rescanned unterminated enclosure text. Runs of opening parentheses, square brackets or braces incurred quadratic processing time even though the resulting initials were unchanged.
New Behavior
Replace enclosure matching with one indexed UTF-16 scan. Preserve the existing rule: the first opening delimiter is removed through the next closing delimiter, regardless of delimiter type or nesting. Retain unterminated text and leave Unicode/surrogate handling, RTL, firstInitialOnly, unsupported-language filtering, whitespace cleanup and phone-number behavior unchanged.
The implementation lazily collects nonempty retained spans and joins them once. It introduces no per-character buffer, nesting stack, input truncation, dependency or public API. A patch change entry is included for @fluentui/react-avatar.
Local Results
The original bounded regression was replayed unchanged, including its threshold and watchdogs. For 1,024 to 4,096 unmatched square brackets, median processing time changed from approximately 0.611 to 9.663 ms before the repair to 0.00579 to 0.0210 ms after the repair. These are local bounded measurements, not a general timing guarantee. The parentheses and braces assertions also passed.
All 163 Avatar tests passed, including the public Avatar name path, all nine opening/closing delimiter combinations, Unicode cases and a deterministic comparison of all 7,381 strings of length zero through four over a nine-character alphabet against the previous enclosure semantics. Avatar lint, build and type-check passed. Missing local compiled entry points were resolved with the existing eslint-plugin-react-components and react-avatar build targets, without reinstalling dependencies or changing configuration.
Independent pre-commit review approved the exact diff, now committed as 3c93665. The identical original regression and all 163 Avatar tests passed again on that clean committed head. The timings and lint/build/type-check results above are the earlier pre-commit observations. Independent committed-head review and assessment passed for this exact head; no CI readiness is claimed here.
Related Work
PHONENUMBER_REGEX is unchanged, keeping the enclosure optimization separate from #36711.