Skip to content

Commit

Permalink
fix: images without width/height (#589)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasio authored Aug 29, 2023
1 parent e2f8f4b commit de501ff
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/lucky-bears-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@headstartwp/core": patch
"@headstartwp/next": patch
---

Fix an issue for images without width or height
6 changes: 4 additions & 2 deletions packages/core/src/react/blocks/ImageBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export function ImageBlock({
}

const { src, alt, width: imgNodeWidth, height: imgNodeHeight } = imgNode.attribs;
const imageWidth = width ?? imgNodeWidth;
const imageHeight = height ?? imgNodeHeight;

return (
<Component
Expand All @@ -50,8 +52,8 @@ export function ImageBlock({
src={src}
alt={alt}
attributes={blockAttributes}
width={width || Number(imgNodeWidth)}
height={height || Number(imgNodeHeight)}
width={imageWidth ? Number(imageWidth) : undefined}
height={imageHeight ? Number(imageHeight) : undefined}
style={style}
>
{children}
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/components/ImageComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export function ImageComponent({ src, alt, width, height, children, style, loade
}

if (!width || !height) {
<Image src={src} alt={alt || ''} fill style={style} loader={loader} />;
return <Image src={src} alt={alt || ''} fill style={style} loader={loader} />;
}

return (
Expand Down

1 comment on commit de501ff

@vercel
Copy link

@vercel vercel bot commented on de501ff Aug 29, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.