-
Notifications
You must be signed in to change notification settings - Fork 39
fix: add remark funmadocs #190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,9 +1,50 @@ | ||||||
| import Image from "next/image"; | ||||||
| import type { ImageProps } from "next/image"; | ||||||
| import defaultMdxComponents from "fumadocs-ui/mdx"; | ||||||
| import type { MDXComponents } from "mdx/types"; | ||||||
| import type { ComponentPropsWithoutRef } from "react"; | ||||||
|
|
||||||
| type MdxImageProps = ComponentPropsWithoutRef<"img"> & { | ||||||
| src?: ImageProps["src"]; | ||||||
| width?: number | string; | ||||||
| height?: number | string; | ||||||
| }; | ||||||
|
|
||||||
| function MdxImage({ src, alt = "", width, height, ...rest }: MdxImageProps) { | ||||||
| if (!src) { | ||||||
| return ( | ||||||
| <img | ||||||
| src={src as string} | ||||||
| alt={alt} | ||||||
| width={width} | ||||||
| height={height} | ||||||
| {...rest} | ||||||
| /> | ||||||
| ); | ||||||
| } | ||||||
| const numericWidth = typeof width === "string" ? Number(width) : width; | ||||||
| const numericHeight = typeof height === "string" ? Number(height) : height; | ||||||
|
|
||||||
| if (!Number.isFinite(numericWidth) || !Number.isFinite(numericHeight)) { | ||||||
| // fallback: 当 width/height 不是可解析数值时,直接使用原生 <img> | ||||||
| return <img src={src ?? ""} alt={alt ?? ""} {...rest} />; | ||||||
|
||||||
| return <img src={src ?? ""} alt={alt ?? ""} {...rest} />; | |
| return <img src={src ?? ""} alt={alt ?? ""} width={width} height={height} {...rest} />; |
Copilot
AI
Oct 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Next.js Image component requires both width and height to be defined numbers when using static imports or external URLs. If either numericWidth or numericHeight is undefined or NaN after conversion, this will cause a runtime error. Add validation to ensure both values are valid numbers before passing to the Image component.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic is inverted. When
srcis falsy, the code renders animgelement withsrc={src as string}, which will result in an empty or undefined src attribute. The condition should beif (!src)with an early return or error handling, not rendering an img with the falsy src value.