Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion packages/vinext/src/shims/image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,14 @@ function getFillStyle(
style?: React.CSSProperties,
backgroundStyle?: React.CSSProperties,
): React.CSSProperties {
// Next.js does not set an inline object-fit for fill images: the style is
// whatever the caller passes (or their CSS), so the legacy objectFit prop
// flows through style and anything else stays under stylesheet control.
return {
position: "absolute",
inset: 0,
width: "100%",
height: "100%",
objectFit: "cover",
...backgroundStyle,
...style,
};
Expand Down
24 changes: 24 additions & 0 deletions tests/shims.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24529,6 +24529,30 @@ describe("next/image component rendering", () => {
expect(html).not.toContain("height=");
});

it("fill images leave object-fit to the caller, matching Next.js", async () => {
const React = await import("react");
const { renderToStaticMarkup } = await import("react-dom/server");
const Image = (await import("../packages/vinext/src/shims/image.js")).default;

const html = renderToStaticMarkup(
React.createElement(Image, { src: "/logo.png", alt: "Logo", fill: true }),
);
expect(html).toContain("position:absolute");
// No inline object-fit: the value comes from the caller's style or CSS,
// exactly like next/image. A hardcoded cover crops non-cover images.
expect(html).not.toContain("object-fit");

const contained = renderToStaticMarkup(
React.createElement(Image, {
src: "/logo.png",
alt: "Logo",
fill: true,
style: { objectFit: "contain" },
}),
);
expect(contained).toContain("object-fit:contain");
});

it("renders priority image with fetchpriority=high and loading=eager", async () => {
const React = await import("react");
const { renderToStaticMarkup } = await import("react-dom/server");
Expand Down
Loading