{"success":true,"name":"use-placeholder-then-swap-pattern-for-smooth-image-appearanc","description":"An image area looks blank or jumps while the real image loads","category":"ai-brimind","path":"ai-brimind/use-placeholder-then-swap-pattern-for-smooth-image-appearanc/SKILL.md","file":"SKILL.md","content":"---\nname: use-placeholder-then-swap-pattern-for-smooth-image-appearanc\ndescription: \"An image area looks blank or jumps while the real image loads\"\n---\n\n# Use Placeholder-Then-Swap Pattern for Smooth Image Appearance\n\n## When to use\nProject is a web frontend, and you are about to handle the moment between 'image requested' and 'image displayed' (cards, avatars, galleries, heroes).\n\n## Example request\nblank white box then sudden photo → missing loading state; a skeleton or blurred mini version should occupy the slot — image pops in harshly → the swap has no transition; a CSS opacity fade on the load event is the standard smoothing mechanism — placeholder shows but real image never replaces it → the swap must listen to the image's onload/onerror, not a timer — broken image icon appears on failure → error state is part of the same pattern; show a fallback image, don't leave the browser default\n\n## Instructions\nYou are a frontend developer who treats image loading as a small state machine, not a single tag. Before coding, identify the three states every image slot has: loading, loaded, and error — and confirm each one has a defined visual. Implement the pattern in this order: (1) reserve the slot with fixed dimensions or aspect-ratio so the layout never moves, (2) render the placeholder in that slot — a skeleton shimmer, a solid tone, or a tiny blurred preview (LQIP) if you have one, (3) load the real image and detect completion with the image's actual onload event (never a setTimeout guess), (4) swap by fading the real image in with a short CSS opacity transition (~200-300ms), keeping the placeholder underneath until the fade finishes, (5) on onerror, show a fallback visual instead of the broken-image icon. Before writing a custom component, check for an existing mechanism: framework image components (next/image has placeholder='blur' built in), or an established library — your custom code should be thin glue, not a rebuilt system. If you're unsure whether a blurred preview source exists in the project, ask before inventing one. Only ship when you've verified all three states visually, and explain that the smoothness comes from handling real load events and reserved space — the root mechanics — not from animation alone.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #921\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}