1
- import * as RadixAvatar from '@radix-ui/react-avatar' ;
2
1
import classNames from 'classnames' ;
3
- import type { ComponentPropsWithoutRef , ElementRef } from 'react' ;
2
+ import Image from 'next/image' ;
3
+ import type { HTMLAttributes } from 'react' ;
4
4
import { forwardRef } from 'react' ;
5
5
6
6
import Link from '@/components/Link' ;
@@ -16,37 +16,45 @@ export type AvatarProps = {
16
16
url ?: string ;
17
17
} ;
18
18
19
+ // @TODO : We temporarily removed the Avatar Radix UI primitive, since it was causing flashing
20
+ // during initial load and not being able to render nicely when images are already cached.
21
+ // @see https://github.com/radix-ui/primitives/pull/3008
19
22
const Avatar = forwardRef <
20
- ElementRef < typeof RadixAvatar . Root > ,
21
- ComponentPropsWithoutRef < typeof RadixAvatar . Root > & AvatarProps
23
+ HTMLSpanElement ,
24
+ HTMLAttributes < HTMLSpanElement > & AvatarProps
22
25
> ( ( { image, nickname, name, fallback, url, size = 'small' , ...props } , ref ) => {
23
26
const Wrapper = url ? Link : 'div' ;
24
27
25
28
return (
26
- < RadixAvatar . Root
29
+ < span
27
30
{ ...props }
28
- className = { classNames ( styles . avatar , styles [ size ] , props . className ) }
29
31
ref = { ref }
32
+ className = { classNames ( styles . avatar , styles [ size ] , props . className ) }
30
33
>
31
34
< Wrapper
32
35
href = { url || undefined }
33
36
target = { url ? '_blank' : undefined }
34
37
className = { styles . wrapper }
35
38
>
36
- < RadixAvatar . Image
37
- loading = "lazy"
38
- src = { image }
39
- alt = { name || nickname }
40
- className = { styles . item }
41
- />
42
- < RadixAvatar . Fallback
43
- delayMs = { 500 }
44
- className = { classNames ( styles . item , styles [ size ] ) }
45
- >
46
- { fallback }
47
- </ RadixAvatar . Fallback >
39
+ { image && (
40
+ < Image
41
+ width = { 40 }
42
+ height = { 40 }
43
+ loading = "lazy"
44
+ decoding = "async"
45
+ src = { image }
46
+ alt = { name || nickname }
47
+ className = { styles . item }
48
+ />
49
+ ) }
50
+
51
+ { ! image && (
52
+ < span className = { classNames ( styles . item , styles [ size ] ) } >
53
+ { fallback }
54
+ </ span >
55
+ ) }
48
56
</ Wrapper >
49
- </ RadixAvatar . Root >
57
+ </ span >
50
58
) ;
51
59
} ) ;
52
60
0 commit comments