Skip to content

Fix conditional name in avatar - #102

Merged
dcruzb merged 3 commits into
developfrom
feature/fix-conditional-name-in-avatar
Sep 9, 2026
Merged

Fix conditional name in avatar#102
dcruzb merged 3 commits into
developfrom
feature/fix-conditional-name-in-avatar

Conversation

@antoniomarcelob

Copy link
Copy Markdown
Contributor

No description provided.

@weltonfelix weltonfelix left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The null checks only works if those properties are empty strings.

Also, String.chartAt() always return a string. I.e. "".charAt(0) returns "", so "" ?? "-" will always return "".

Comment thread src/components/UserPopup/index.tsx Outdated
Comment thread src/lib-components/Navbar/index.tsx Outdated
Comment thread src/lib-components/Navbar/index.tsx Outdated

@weltonfelix weltonfelix left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Changes in review.

@antoniomarcelob
antoniomarcelob force-pushed the feature/fix-conditional-name-in-avatar branch from 7750953 to 1887516 Compare April 15, 2024 13:55
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

Address review feedback on the avatar fallbacks.

The alt on the UserPopup avatar still dereferenced user.name[0] on the
right-hand side of a ??, which is evaluated exactly when user.name is
nullish, throwing instead of falling back.

Derive displayName and avatarInitial once per component using ||, so
empty strings are handled alongside null and undefined, and restore the
username fallback that the previous version dropped.

Also replace the unconditional outline: none on the hamburger button
with a :focus:not(:focus-visible) rule, so the focus ring stays visible
for keyboard navigation.
@sonarqubecloud

sonarqubecloud Bot commented Sep 9, 2026

Copy link
Copy Markdown

@dcruzb dcruzb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approving after addressing the review feedback in f06c695.

The remaining crash was in the UserPopup avatar: alt={user.name ?? user.name[0] ?? ''} dereferenced user.name[0] on the right-hand side of a ??, which is evaluated precisely when user.name is nullish — so it threw in the exact case the fix was meant to handle.

Both components now derive the value once, using || so empty strings are covered alongside null/undefined:

const displayName = user.name || user.username || '';
const avatarInitial = displayName.charAt(0) || '-';

This also restores the username fallback that the previous revision dropped, which matters because Navbar populates username from preferred_username.

Additionally, the unconditional outline: none on the hamburger button was replaced with &:focus:not(:focus-visible), keeping the pointer-interaction behavior while preserving a visible focus ring for keyboard navigation.

Verified: tsc --noEmit clean and npm run build-lib succeeds.

@dcruzb
dcruzb merged commit 63ddfe4 into develop Sep 9, 2026
3 checks passed
@dcruzb
dcruzb deleted the feature/fix-conditional-name-in-avatar branch September 9, 2026 18:44
This was referenced Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants