Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(Avatar): avoid remount by removing tooltip render fork (#4359)

Cindy Zhang41fe6b4fcd2a
diff --git a/.changeset/avatar-tooltip-remount.md b/.changeset/avatar-tooltip-remount.md
new file mode 100644
index 0000000000..46bb695e26
--- /dev/null
+++ b/.changeset/avatar-tooltip-remount.md
@@ -0,0 +1,6 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] Avatar: avoid remounting the avatar subtree when the name tooltip toggles — render the tooltip as a conditional sibling instead of forking the return so the avatar keeps its position in the React tree (and its image-load state) across tooltip changes.
+@cixzhang
diff --git a/packages/core/src/Avatar/Avatar.tsx b/packages/core/src/Avatar/Avatar.tsx
index 887b53944a..f73db9c7e0 100644
--- a/packages/core/src/Avatar/Avatar.tsx
+++ b/packages/core/src/Avatar/Avatar.tsx
@@ -604,17 +604,14 @@ export function Avatar({
<AvatarSizeContext value={numericSize}>{rootElement}</AvatarSizeContext>
);
- if (!showTooltip) {
- return avatarElement;
- }
-
- // Render the tooltip as a sibling (no wrapper DOM) — the hook's ref is already
- // attached to the root via `rootRef` above. `trimmedTooltip` is guaranteed
- // non-empty here.
+ // Always return the same structure so the avatar keeps its position in the
+ // React tree regardless of the tooltip flag — toggling it must not remount
+ // the avatar subtree (and lose image-load state). The tooltip is a sibling
+ // (no wrapper DOM); the hook's ref is already on the root via `rootRef`.
return (
<>
{avatarElement}
- {tooltipHook.renderTooltip(trimmedTooltip)}
+ {showTooltip ? tooltipHook.renderTooltip(trimmedTooltip) : null}
</>
);
}