Skip to content

🐛 fix: clamp rendered image max width to the container - #232

Merged
Innei merged 1 commit into
masterfrom
fix/image-max-width-overflow
Oct 18, 2026
Merged

Innei merged 1 commit into
masterfrom
fix/image-max-width-overflow

Conversation

@arvinxx

@arvinxx arvinxx commented Oct 18, 2026

Copy link
Copy Markdown
Member

问题

分享页 / 只读渲染里,宽图在手机上是按原始宽度铺开并溢出容器被裁掉的(例:https://app.lobehub.com/share/page/pQeCjA1GZcYLbtSt 底部的图表)。

根因

Image 节点会持久化一个 maxWidth,默认值是编辑器里的哨兵值 4200。headless renderer 把它直接写成了内联样式:

if (maxWidth) style.maxWidth = maxWidth; // -> max-width: 4200px

内联样式优先级高于任何 CSS(包括 lobe-ui Markdown 里的 img { max-width: 100% }),所以图片永远按自身宽度渲染,窄视口下溢出被裁。编辑态的 LazyImage 其实已经用 calc(min(Npx, 100%)) 处理过,只有渲染器这条路径漏了。

修改

src/renderer/renderers/image.tsx 的 renderImage / renderBlockImage 改为:

if (maxWidth) style.maxWidth = `min(${maxWidth}px, 100%)`;

保留持久化宽度(桌面端仍按原尺寸上限渲染),同时不允许超过容器宽度。哨兵值 4200 天然退化成 100%,无需特判。

测试

补充两条回归断言(image / block-image),验证输出为 max-width:min(4200px, 100%)。pnpm vitest run src/renderer/__tests__/LexicalRenderer.test.tsx 20 passed。

The image node persists a maxWidth (4200 is the default sentinel used by the
editor). The headless renderer wrote it straight into an inline
max-width:4200px, which overrides any width constraint from CSS, so wide images
(and the shared page content around them) overflow and get clipped on narrow
viewports such as mobile browsers.

Use min(<maxWidth>px, 100%) instead, matching what LazyImage already does in the
edit view.
@lobe-tsukumo

lobe-tsukumo Bot commented Oct 18, 2026

Copy link
Copy Markdown

👍 @arvinxx

Thank you for raising your pull request and contributing to our Community.
Please make sure you have followed our contributing guidelines. We will review it as soon as possible.
If you encounter any problems, please feel free to connect with us.

非常感谢您提出拉取请求并为我们的社区做出贡献,请确保您已经遵循了我们的贡献指南,我们会尽快审查它。
如果您遇到任何问题,请随时与我们联系。

@vercel

vercel Bot commented Oct 18, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
lobe-editor Building Building Preview Oct 18, 2026 9:44am UTC

Request Review

@pkg-pr-new

pkg-pr-new Bot commented Oct 18, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@lobehub/editor@232

commit: 04225fe

@Innei
Innei merged commit fbd76b7 into master Oct 18, 2026
5 of 6 checks passed
@lobe-tsukumo

lobe-tsukumo Bot commented Oct 18, 2026

Copy link
Copy Markdown

❤️ Great PR @arvinxx ❤️

The growth of project is inseparable from user feedback and contribution, thanks for your contribution!

项目的成长离不开用户反馈和贡献,感谢您的贡献!

@Innei
Innei deleted the fix/image-max-width-overflow branch October 18, 2026 10:05
lobe-tsukumo Bot pushed a commit that referenced this pull request Oct 18, 2026
### [Version&nbsp;5.0.2](v5.0.1...v5.0.2)
<sup>Released on **2026-10-18**</sup>

#### 🐛 Bug Fixes

- **misc**: Clamp rendered image max width to the container.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### What's fixed

* **misc**: Clamp rendered image max width to the container, closes [#232](#232) ([fbd76b7](fbd76b7))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>
@lobe-tsukumo

lobe-tsukumo Bot commented Oct 18, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 5.0.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

This branch was successfully deployed

1 active deployment
Preview — 04225feb Deployed Oct 18, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants