Skip to content

Commit 2e80457

Browse files
committed
fix: 没处理 “转失败(NaN)” 的情况;加上 Number.isFinite() 判断后,就兜底
1 parent ea15354 commit 2e80457

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

mdx-components.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,18 @@ function MdxImage({ src, alt = "", width, height, ...rest }: MdxImageProps) {
2222
/>
2323
);
2424
}
25-
2625
const numericWidth = typeof width === "string" ? Number(width) : width;
2726
const numericHeight = typeof height === "string" ? Number(height) : height;
2827

28+
if (!Number.isFinite(numericWidth) || !Number.isFinite(numericHeight)) {
29+
// fallback: 当 width/height 不是可解析数值时,直接使用原生 <img>
30+
return <img src={src ?? ""} alt={alt ?? ""} {...rest} />;
31+
}
32+
2933
return (
3034
<Image
31-
src={src}
32-
alt={alt}
35+
src={src ?? ""}
36+
alt={alt ?? ""}
3337
width={numericWidth}
3438
height={numericHeight}
3539
{...rest}

0 commit comments

Comments
 (0)