Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/shared/components/card/banner-card/banner-card.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { cn } from '@libs/cn';
import { useState } from 'react';
import BannerImg from '/images/card_banner_img.webp';

interface CardBannerProps {
Expand All @@ -9,13 +10,22 @@ interface CardBannerProps {
}

const BannerCard = ({ text, subText, onClick }: CardBannerProps) => {
const [imageLoaded, setImageLoaded] = useState(false);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

이미지 로드 실패 시 CTA가 영구히 숨겨질 수 있음 — onError/폴백 필요

현재는 onLoad에만 의존해 overlay가 표시됩니다. 네트워크 오류/404 등으로 이미지가 실패하면 안내 텍스트(CTA)가 영원히 노출되지 않습니다. 또한 subText가 없을 때도 빈 p가 렌더링됩니다. 아래처럼 실패 시에도 overlay를 열고, subText는 존재할 때만 렌더링하도록 보완해 주세요.

-  const [imageLoaded, setImageLoaded] = useState(false);
+  const [overlayReady, setOverlayReady] = useState(false);
@@
-      <img src={BannerImg} alt="홈배너" className="w-full" onLoad={() => setImageLoaded(true)} />
-      {imageLoaded && (
+      <img
+        src={BannerImg}
+        alt="홈배너"
+        className="w-full"
+        onLoad={() => setOverlayReady(true)}
+        onError={() => setOverlayReady(true)}
+      />
+      {overlayReady && (
         <div className="absolute inset-0 flex flex-col justify-center gap-[0.4rem] py-[2.2rem] pl-[2.4rem]">
-          <p className="cap_14_m text-gray-800">{subText}</p>
+          {subText && <p className="cap_14_m text-gray-800">{subText}</p>}
           <p className="subhead_18_sb text-gray-black">{text}</p>
         </div>
       )}

Also applies to: 17-23

🤖 Prompt for AI Agents
In src/shared/components/card/banner-card/banner-card.tsx around lines 13 (and
also lines 17-23), the component only sets imageLoaded via onLoad so a failed
image prevents the overlay/CTA from ever showing and an empty <p> renders when
subText is missing; add an onError handler on the img that also calls
setImageLoaded(true) (or set a separate imageError flag and derive "showOverlay"
from imageLoaded || imageError) so the overlay appears on load failure, and
change the JSX to render the subText <p> only when subText is truthy (i.e.,
conditionally render the element to avoid empty tags).


return (
<button type="button" className={cn('relative cursor-pointer text-left')} onClick={onClick}>
<img src={BannerImg} alt="홈배너" className="w-full" />
<div className="absolute inset-0 flex-col justify-center gap-[0.4rem] py-[2.2rem] pl-[2.4rem]">
<p className="cap_14_m text-gray-800">{subText}</p>
<p className="subhead_18_sb text-gray-black">{text}</p>
</div>
<img
src={BannerImg}
alt="홈배너"
className="min-h-[9.6rem] w-full"
onLoad={() => setImageLoaded(true)}
/>
{imageLoaded && (
<div className="absolute inset-0 flex flex-col justify-center gap-[0.4rem] py-[2.2rem] pl-[2.4rem]">
<p className="cap_14_m text-gray-800">{subText}</p>
<p className="subhead_18_sb text-gray-black">{text}</p>
</div>
)}
</button>
);
};
Expand Down