Skip to content

Commit 61d661b

Browse files
committed
Fix: Avatar remounting issues
1 parent e4a4734 commit 61d661b

File tree

3 files changed

+11
-24
lines changed

3 files changed

+11
-24
lines changed

apps/web/components/chat/settings/info.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ export default function Info({
3131
<div className="flex flex-col gap-3 -mt-[4rem]">
3232
<div className="w-full flex flex-row justify-between items-end">
3333
<Avatar
34-
border="wide"
3534
size="xlarge"
35+
className="border-4 border-background"
3636
src={groupIcon.url([group.id], group.icon_hash)}
3737
fallback={group.name}
3838
/>

apps/web/pages/dm/[channel]/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Avatar } from "ui/components/avatar";
22
import { trpc } from "@/utils/trpc";
3-
import { useSession } from "next-auth/react";
43
import { useRouter } from "next/router";
54
import { skeleton } from "ui/components/skeleton";
65

packages/ui/components/avatar.tsx

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import * as AvatarBase from "@radix-ui/react-avatar";
2-
import { ReactNode, useMemo } from "react";
2+
import { useMemo } from "react";
33
import { tv, VariantProps } from "tailwind-variants";
44

55
const avatar = tv({
66
slots: {
7-
root: "relative inline-flex aspect-square",
7+
root: "relative inline-flex aspect-square overflow-hidden",
88
image: "h-full w-full object-cover",
9-
fallback: [
10-
"flex h-full w-full text-center items-center justify-center bg-brand-500 text-sm font-medium uppercase",
11-
"text-accent-50 dark:bg-brand-400",
12-
],
9+
fallback:
10+
"flex h-full w-full text-center items-center justify-center bg-primary text-primary-foreground text-sm font-medium uppercase",
1311
},
1412
variants: {
1513
size: {
@@ -36,18 +34,15 @@ const avatar = tv({
3634
},
3735
rounded: {
3836
full: {
39-
image: "rounded-full",
40-
fallback: "rounded-full",
37+
root: "rounded-full",
4138
},
4239
sm: {
43-
image: "rounded-lg",
44-
fallback: "rounded-lg",
40+
root: "rounded-lg",
4541
},
4642
},
4743
border: {
4844
wide: {
49-
image: "border-4 border-light-100 dark:border-dark-900",
50-
fallback: "border-4 border-light-100 dark:border-dark-900",
45+
root: "border-4 border-background",
5146
},
5247
},
5348
},
@@ -61,14 +56,12 @@ export type AvatarProps = {
6156
src?: string | null;
6257
fallback?: string;
6358
alt?: string;
64-
asImage?: ReactNode;
6559
className?: string;
6660
} & VariantProps<typeof avatar>;
6761

6862
export function Avatar({
6963
size,
7064
fallback,
71-
asImage,
7265
src,
7366
alt,
7467
border,
@@ -89,22 +82,17 @@ export function Avatar({
8982
return (
9083
<AvatarBase.Root
9184
{...props}
85+
key={src}
9286
className={styles.root({ className: props.className })}
9387
>
9488
{src != null && (
9589
<AvatarBase.Image
9690
alt={fallback ?? alt ?? "avatar"}
9791
src={src}
9892
className={styles.image()}
99-
asChild={asImage != null}
100-
>
101-
{asImage}
102-
</AvatarBase.Image>
93+
/>
10394
)}
104-
<AvatarBase.Fallback
105-
className={styles.fallback()}
106-
delayMs={src != null ? 200 : 0}
107-
>
95+
<AvatarBase.Fallback className={styles.fallback()} delayMs={0}>
10896
<p>{fallbackText}</p>
10997
</AvatarBase.Fallback>
11098
</AvatarBase.Root>

0 commit comments

Comments
 (0)