Skip to content

fix(Avatar): draw initials from letters, digits and emoji, not punctuation - #6698

Merged
imdreamrunner merged 1 commit into
meta:mainfrom
light-merlin-dark:fix/avatar-initials-letters-only
Sep 28, 2026
Merged

imdreamrunner merged 1 commit into
meta:mainfrom
light-merlin-dark:fix/avatar-initials-letters-only

Conversation

@light-merlin-dark

Copy link
Copy Markdown
Contributor

Hey, good day or evening, everyone. I hope you are doing excellent.

It's my pleasure to contribute this PR, which makes Avatar draw its initials from letters, digits and emoji instead of whatever character a word happens to start with.

User impact

Any Avatar whose name contains punctuation at a word boundary renders that punctuation as an initial. A workspace named Northwind Workbench (automation) shows N(; “Ada” Lovelace shows “L; Ada Lovelace — shows A—; (Ada) shows (. Names like these come straight from user and organization data, so consumers cannot reasonably sanitize every caller. After this change those render NA, AL, AL and A.

Problem and solution fit

  • Why it occurs: getInitials splits on whitespace and takes the first grapheme of the first and last words, with no notion of which characters can stand for a word.
  • Why it harms the task: the initials plate exists to identify who or what the avatar represents at a glance; a bracket or quote identifies nothing.
  • Why that matters: it is the fallback shown whenever no photo loads, which is the common case for teams, bots and new accounts.

The fix skips leading punctuation within a word and drops words that contain no letter, digit or emoji. Everything else is unchanged: first and last word, grapheme-safe extraction via the existing firstCharacter helper, upper-casing.

Expected behavior and authority

Avatar.doc.mjs anatomy: initials are "letters extracted from the name". #4749 / #4750 established that emoji are legitimate initials (😀 Ada → 😀A); this change keeps that, so an emoji still counts alongside \p{L} and \p{N}.

Smallest restoration

  • initialCharacter(word): first match of [\p{L}\p{N}\p{Extended_Pictographic}\p{Regional_Indicator}], then firstCharacter from that index, so combining marks, keycaps, flags and ZWJ sequences stay whole.
  • getInitials maps words through it and filters empties before choosing first and last.
  • Supporting: a name made only of punctuation (- ()) now yields no initials. Rather than render an empty plate, it falls through to the default icon, the same way the existing whitespace-only case does. The accessible name still comes from name.
  • Anatomy row in Avatar.doc.mjs updated to describe the rule. The file was already failing Prettier before this change, so its formatting is untouched.

Evidence

  • Reproduction before the change: <Avatar name="Northwind Workbench (automation)" /> renders N(.
  • Result after the change: renders NA.
  • Representative unchanged paths: Alice → A, Mary-Jane Watson → MW, R2 D2 → RD, émile zola → ÉZ, and the existing emoji, flag and ZWJ tests (😀A, 🇬🇧A, 👨‍👩‍👧‍👦A).
  • Mutation-sensitive proof: 6 of the new cases fail against the previous getInitials (N(, “L, A—, (, A(, and the empty-plate case) and pass with this change.

Scope

  • One defect is restored.
  • Separable contradictory or unsettled tagalongs were removed or split.
  • No new public API, visual representation, default, or interaction model is hidden under the bug-fix label.
  • Public text and artifacts contain no internal Meta context.

Testing

  • pnpm exec vitest run packages/core/src/Avatar packages/core/src/utils/characters.test.ts: 165/165 pass.
  • pnpm check:changesets, pnpm check:sync, eslint packages/core/src/Avatar, tsc --noEmit in packages/core: clean. Pre-commit check:repo passed.

By Merlin (rbeckner.com) and his AI agent (Claude Code, Claude Opus 5.5, thinking on: low).

…ation

getInitials took the first character of the first and last whitespace
words, so a name such as "Northwind Workbench (automation)" rendered
"N(" and "“Ada” Lovelace" rendered "“L". Each word's initial is now its
first letter, digit or emoji (grapheme-safe, as before); words with none
are skipped, and a name made only of punctuation falls through to the
default icon instead of an empty plate.
@vercel

vercel Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Sep 28, 2026 4:59pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 28, 2026
@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge labels Sep 28, 2026
@astracat-bot

astracat-bot Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Sep 28, 2026, 5:35 PM UTC

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This change restores Avatar initials to what the component doc promises — letters extracted from the name. Initials now come from the first letter, digit, or emoji of the first and last usable words, so Northwind Workbench (automation) renders NA instead of N(, “Ada” Lovelace renders AL, and (Ada) renders A. Words with no usable character are skipped, and a punctuation-only name falls back to the existing default icon instead of an empty plate, with its accessible name unchanged.

No public API, prop, or default changes, and ordinary, digit, accented, emoji, flag, and ZWJ initials are unchanged. The new tests cover the punctuation cases and the icon fallback; I re-ran the Avatar and character-utility suites locally (165/165 passing), along with the changeset and sync checks and ESLint, all clean.

[Automated review]

@imdreamrunner
imdreamrunner enabled auto-merge (squash) September 28, 2026 21:51
@github-actions github-actions Bot removed the needs:code-review High-risk change (new package/component/API) — needs human code review before merge label Sep 28, 2026
@imdreamrunner
imdreamrunner merged commit 7ada42e into meta:main Sep 28, 2026
39 of 40 checks passed
cixzhang pushed a commit that referenced this pull request Oct 21, 2026
<!-- template: bug-fix.md -->

## User impact

An app that builds Astryx from source with the documented Next.js setup, but sets no browserslist or targets a browser without Unicode property escapes (such as Safari 11), fails `next build --webpack` with `Unknown property: L` (also `Zs`, `Letter`). The errors point at `Avatar.tsx`, `Markdown/parser.ts` and `Markdown/plugins/headingLinks.ts`, package source the app cannot change, and come from both the PostCSS pass and the JavaScript compile. Any import from the package root reaches them.

## Problem and solution fit

- Why it fails: with no targets, or old ones, `next/babel`'s preset-env rewrites every `\p{…}` regex literal with transform-unicode-property-regex. Next's bundled copy of that transform loads `regenerate-unicode-properties` at runtime, which Next does not ship, so it throws (Next 16.3.6 and 16.4.2 alike).
- Why it harms the task: the throw stops the whole build.
- Why that matters: the app cannot fix it in its own code, and the error names a Unicode property, not the missing target.

## Expected behavior and authority

This is a regression of a settled case. #5450 hit this failure in `NumberInput/numberParser.ts` and builds those expressions with `new RegExp(...)`; its comment records why, and notes that property escapes need no transform in any browser this package supports. #6698, #6911 and #7051 later added four new literals and reintroduced it.

## Smallest restoration

- The four literals become `new RegExp(...)` with the same pattern and flags, built once at module load as before.
- Each site's comment names the cause and when a literal is safe again: once Next's bundled Babel ships the Unicode data.
- A source-build test fails when a Core module writes a property escape as a regex literal.

## Evidence

- Reproduction before the change: a clean registry install of main's documented Next.js example (`apps/example-nextjs-source`, hoisted, browserslist removed). `next build --webpack` fails in the PostCSS pass (`Avatar.tsx: Unknown property: L`) and in the JavaScript compile (`Unknown property: L`, `Zs`, `Letter` from the three files).
- Result after the change: the same install, with this change applied to Core's source, compiles and prerenders, and all 226 rendered class names have a rule in the emitted CSS.
- Representative unchanged path: the Avatar and Markdown suites pass unchanged.
- Regression test or other mutation-sensitive proof: `unicodePropertyEscapes.source-build.test.mjs` fails on main listing the four literals, and passes here.

## Scope

- [x] One defect is restored.
- [x] Separable contradictory or unsettled tagalongs were removed or split.
- [x] No new public API, visual representation, default, or interaction model is hidden under the bug-fix label.
- [x] Public text and artifacts contain no internal Meta context.

## Testing

- `pnpm exec vitest run --project ui packages/core/src/Avatar packages/core/src/Markdown packages/core/src/unicodePropertyEscapes.source-build.test.mjs`: 50 files, 1,158 tests pass (the new test alone fails on main).
- `next build --webpack` on the clean install, no browserslist: fails on main in both passes; passes with this change (226 of 226 rendered classes have a rule).
- `pnpm -F @astryxdesign/core typecheck`, ESLint and Prettier on the touched files, `pnpm check:repo`, changeset coverage: pass.

This branch was successfully deployed

1 active deployment
Preview — 62bd5c7f Deployed Sep 28, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. community Authored by a community contributor (not on the eng/design team)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants