(component: ComponentType
): void {
// The registration contract IS the assertion: the host states that its
// component handles the props this shim forwards (`next/image` does). One
// narrow assertion here, instead of `any` on the slot and on this
// signature, which erased the type for every caller.
impl = component as RegisteredImage;
}
const Image = forwardRef. Drops Next-only props and reduces
// `StaticImageData` src to a string.
const {
src,
alt,
width,
height,
fill,
sizes: _sizes,
quality: _quality,
priority: _priority,
placeholder: _placeholder,
blurDataURL: _blurDataURL,
unoptimized: _unoptimized,
onLoadingComplete,
loader: _loader,
style,
...rest
} = props;
const srcStr = typeof src === 'string' ? src : src?.src;
// Mirrors the real `next/image` fill style EXACTLY, which means no
// `objectFit`: Next sets position/inset/size and leaves object-fit to the
// caller's className. This shim used to force `objectFit: 'cover'`, and
// because an inline style beats a class, every `fill` + `object-contain`
// call site (blog-card, entity-portrait-card, onboarding-guide-card,
// program-card, og-link-preview, parallax-image-showcase, product-release-card)
// silently rendered CROPPED on non-Next hosts and contained on Next ones —
// the one divergence a shim must never have. All 20 `fill` call sites in this
// library pass an explicit object-fit class, so nothing relied on the default.
const finalStyle = fill
? {
position: 'absolute' as const,
inset: 0,
width: '100%',
height: '100%',
...style,
}
: style;
return (
onLoadingComplete(e.currentTarget) : undefined}
{...rest}
/>
);
});
export default Image;