Skip to content

feat: use next/image for MDX images - #8595

Open
saidstack wants to merge 1 commit into
reactjs:mainfrom
saidstack:use-next-image-for-mdx
Open

feat: use next/image for MDX images#8595
saidstack wants to merge 1 commit into
reactjs:mainfrom
saidstack:use-next-image-for-mdx

Conversation

@saidstack

Copy link
Copy Markdown

Fixes #4382

What changed

Replaced the plain <img> in the MDX Image component with next/image,
so markdown images and raw <img> tags now get lazy-loading, async
decoding, and image optimization.

Changes

  • Added import NextImage from 'next/image' in src/components/MDX/MDXComponents.tsx
  • Updated the MDX Image component to render next/image instead of <img>

Open question

Markdown images usually don't specify width/height. I used a 700×400
fallback for dimension-less images. Is that acceptable, or is there a
preferred approach (e.g. fill + a sized container, or reading intrinsic
dimensions)?

That Fixes #4382 is what the template was asking for — it auto-links (and eventually auto-closes) the issue when the PR merges.

@github-actions

Copy link
Copy Markdown

Size changes

Details

📦 Next.js Bundle Analysis for react-dev

This analysis was generated by the Next.js Bundle Analysis action. 🤖

Five Pages Changed Size

The following pages changed size from the code in this PR compared to its base branch:

Page Size (compressed) First Load
/404 127.56 KB (🟡 +1 B) 242.71 KB
/500 127.57 KB (🟡 +1 B) 242.72 KB
/[[...markdownPath]] 130.01 KB (🟡 +1 B) 245.16 KB
/errors 127.81 KB (🟡 +1 B) 242.96 KB
/errors/[errorCode] 127.79 KB (🟡 +1 B) 242.94 KB
Details

Only the gzipped size is provided here based on an expert tip.

First Load is the size of the global bundle plus the bundle for the individual page. If a user were to show up to your website and land on a given page, the first load size represents the amount of javascript that user would need to download. If next/link is used, subsequent page loads would only need to download that page's bundle (the number in the "Size" column), since the global bundle has already been downloaded.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

Next to the size is how much the size has increased or decreased compared with the base branch of this PR. If this percentage has increased by 10% or more, there will be a red status indicator applied, indicating that special attention should be given to this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add next/image component as MDX component and convert img tags to Image component

1 participant