Skip to content

Commit eb934eb

Browse files
fix: 이미지 변경 시 새로 렌더링 되도록 수정 (#126)
* fix: 이미지 변경 시 새로 렌더링 되도록 수정 * chore: fix lint errors * refactor: improve image fallback handling * fix: replace right type annotation instead of any --------- Co-authored-by: Jeongmin Lee <clcl6084@gmail.com>
1 parent b339195 commit eb934eb

File tree

4 files changed

+24
-28
lines changed

4 files changed

+24
-28
lines changed

.script/gSheet.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ function processPeopleData(peoplesRow, config) {
188188
const row = it['_rawData'];
189189

190190
const thumbnailId = (row[12] ?? '').match(/\/d\/(.*?)\/view/)?.[1] ?? '';
191-
const key = row[0] ?? Math.random().toString(36).substring(2, 15);
191+
const key = row[0] || Math.random().toString(36).substring(2, 15);
192192
const period = row[4];
193193

194194
periodsMap[period].push({

src/components/molecules/GlowArea/index.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use client';
22

3-
import { PropsWithChildren } from 'react';
3+
import { CSSProperties, PropsWithChildren } from 'react';
44

5-
import { AnimatePresence, motion } from 'framer-motion';
5+
import { AnimatePresence, motion, TargetAndTransition } from 'framer-motion';
66

77
import useElementSize from '@/hook/useElementSize';
88
import { createSVGMask } from '@/libs/utils/svg';
@@ -21,7 +21,9 @@ function GlowArea({ rx, children }: PropsWithChildren<GlowAreaProps>) {
2121
<div style={{ position: 'relative' }}>
2222
<motion.div
2323
className={styles.border}
24-
animate={{ '--border-angle': ['0turn', '1turn'] } as any}
24+
animate={
25+
{ '--border-angle': ['0turn', '1turn'] } as TargetAndTransition
26+
}
2527
transition={{
2628
repeat: Infinity,
2729
duration: 6,
@@ -33,7 +35,7 @@ function GlowArea({ rx, children }: PropsWithChildren<GlowAreaProps>) {
3335
'--area-width': `${width}px`,
3436
'--area-height': `${height}px`,
3537
'--svg-mask': `url(${createSVGMask(width + 1, height + 1, rx)})`,
36-
} as any
38+
} as CSSProperties
3739
}
3840
></motion.div>
3941
<div className={styles.area} ref={ref}>

src/components/molecules/Image/index.tsx

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import React, { CSSProperties, ReactNode, useCallback } from 'react';
1+
'use client';
2+
3+
import { CSSProperties, ReactNode, useCallback } from 'react';
24

35
import NextImage, { ImageProps as NextImageProps } from 'next/image';
46

@@ -49,36 +51,28 @@ function Image({
4951
[fill, width, height, className],
5052
);
5153

52-
if (!src) {
53-
return (
54-
<>
55-
{renderFillImage(
56-
<NextImage
57-
src={'/assets/empty_image.png'}
58-
className={defaultClassName}
59-
alt="기본 이미지"
60-
fill={fill}
61-
sizes={defaultSizes}
62-
width={fill ? undefined : width}
63-
height={fill ? undefined : height}
64-
{...rest}
65-
/>,
66-
)}
67-
</>
68-
);
69-
}
54+
const fallbackImageSource = '/assets/empty_image.png';
55+
const imageSrc = src || fallbackImageSource;
56+
const imageAlt = alt || 'Siper Image';
7057

7158
return (
7259
<>
7360
{renderFillImage(
7461
<NextImage
75-
src={src}
76-
alt={alt}
62+
key={imageSrc}
63+
src={imageSrc}
64+
alt={imageAlt}
7765
className={defaultClassName}
7866
fill={fill}
7967
sizes={defaultSizes}
8068
width={fill ? undefined : width}
8169
height={fill ? undefined : height}
70+
onError={(e) => {
71+
const target = e.target as HTMLImageElement;
72+
if (target.src !== fallbackImageSource) {
73+
target.src = fallbackImageSource;
74+
}
75+
}}
8276
{...rest}
8377
/>,
8478
)}

src/libs/utils/tick.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ export const debounce = <T extends (...args: unknown[]) => unknown>(
55
let timer: ReturnType<typeof setTimeout>;
66

77
return (...args: Parameters<T>): ReturnType<T> => {
8-
let result: any;
8+
let result;
99
if (timer) {
1010
clearTimeout(timer);
1111
}
1212
timer = setTimeout(() => {
1313
result = func(...args);
1414
}, delay);
15-
return result;
15+
return result as ReturnType<T>;
1616
};
1717
};
1818

0 commit comments

Comments
 (0)