Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

web: a reply's picture opens whole on a click

lmliheng408dbf8c7ad1
diff --git a/changelog/unreleased/2026-10-29-prose-image-lightbox.md b/changelog/unreleased/2026-10-29-prose-image-lightbox.md
new file mode 100644
index 00000000..89a5836a
--- /dev/null
+++ b/changelog/unreleased/2026-10-29-prose-image-lightbox.md
@@ -0,0 +1,43 @@
+# A reply's picture opens whole when you click it
+
+- **Date:** 2026-10-29
+- **Type:** feature
+- **Scope:** `web`, `ui`
+- **Breaking:** no
+
+[中文](2026-10-29-prose-image-lightbox.zh.md)
+
+Since a reply's picture started rendering at all (last round), it rendered fitted to the reading
+column: a 2000px screenshot came out a few hundred pixels wide, and the only way to read it was to
+find the file in the Files panel. Inside a conversation a picture is now a click away from its own
+size — the click opens it in the lightbox the file previewer and attachments already use, and
+Escape (or a click on the backdrop) closes it.
+
+Nothing else changes. Every other Markdown surface — a README, the handbook, the Memory view, a
+file preview — still renders a still picture, and so does a conversation's picture that the author
+wrapped in a link: there the click belongs to the link.
+
+## Details
+
+- `packages/ui/src/components/content/prose/prose.tsx`: `ProseImagesProvider` gained `zoomable`
+ (default off), and the `img` adapter renders a `ZoomableImage` when it is on. Two cases stay a
+ plain `<img>`: an empty src (nothing to enlarge) and a picture inside a link — a button nested in
+ an anchor fires both handlers, so a click would open a tab and an overlay at once. `MdLink` now
+ tells its children they sit inside a link (`ProseInLinkContext`), so the adapter knows without a
+ DOM query.
+- `packages/ui/src/components/overlays/lightbox/lightbox.tsx`: `ZoomableImage` forwards the rest of
+ the `<img>` attributes it is given (a Markdown picture's `title`, `width`, `height`) to the
+ thumbnail; the lightbox itself still shows the file at its own size, so it takes only src and alt.
+- `packages/web/src/features/chat/workspace-refs.tsx`: the conversation turns `zoomable` on for its
+ whole transcript, whatever a src resolved to — the resolver decides where a picture is fetched
+ from, not whether the reader may enlarge it.
+- Tests: `packages/ui/test/prose.test.ts` (the adapter: on, off, empty src, inside a link),
+ `packages/ui/test/lightbox.test.ts` (the thumbnail keeps the caller's attributes),
+ `packages/web/test/md.test.ts` (through the real pipeline: a conversation's picture is a button,
+ any other surface's is not).
+
+## Compatibility
+
+- No API, on-disk or protocol change. A picture outside a conversation is the same `<img>` it was;
+ inside one it gains a wrapper button, and the markup a Markdown picture renders in a link is
+ unchanged.
diff --git a/changelog/unreleased/2026-10-29-prose-image-lightbox.zh.md b/changelog/unreleased/2026-10-29-prose-image-lightbox.zh.md
new file mode 100644
index 00000000..56370f56
--- /dev/null
+++ b/changelog/unreleased/2026-10-29-prose-image-lightbox.zh.md
@@ -0,0 +1,36 @@
+# 回复里的图片点一下就看全图
+
+- **日期:** 2026-10-29
+- **类型:** feature
+- **范围:** `web`、`ui`
+- **破坏性:** 无
+
+[English](2026-10-29-prose-image-lightbox.md)
+
+自从上一轮回复里的图片能显示出来,它一直是按阅读栏宽度缩着显示的:一张 2000px 的截图出来只有几
+百像素宽,想看清只能去文件面板里找那个文件。现在会话里的图片点一下就按自己的尺寸打开 —— 用的是
+文件预览与附件早就在用的那个 lightbox,按 Esc(或点背景)关掉。
+
+其余都不变。会话之外的每一处 Markdown 界面 —— README、手册、记忆视图、文件预览 —— 仍然是静止的
+一张图;会话里**被作者用链接包住的图片**也一样:那一下点击归链接。
+
+## 细节
+
+- `packages/ui/src/components/content/prose/prose.tsx`:`ProseImagesProvider` 多了 `zoomable`
+ (默认关),打开时 `img` 适配器渲染成 `ZoomableImage`。两种情形仍是普通 `<img>`:空 src(没有
+ 东西可放大),以及被链接包住的图片 —— 按钮嵌在 `<a>` 里两个处理器都会触发,点一下会同时开一个
+ 标签页和一层覆盖。`MdLink` 现在告诉自己的子节点「你在链接里」(`ProseInLinkContext`),适配器
+ 因此不必去查 DOM。
+- `packages/ui/src/components/overlays/lightbox/lightbox.tsx`:`ZoomableImage` 把调用方给的其余
+ `<img>` 属性(Markdown 图片的 `title`、`width`、`height`)转发给缩略图;lightbox 本身按文件原尺寸
+ 显示,仍然只收 src 与 alt。
+- `packages/web/src/features/chat/workspace-refs.tsx`:会话给整条对话打开 `zoomable`,与 src 解析成
+ 什么无关 —— 解析器决定图片从哪取,不决定读者能不能放大。
+- 测试:`packages/ui/test/prose.test.ts`(适配器:开、关、空 src、在链接里)、
+ `packages/ui/test/lightbox.test.ts`(缩略图保留调用方的属性)、`packages/web/test/md.test.ts`
+ (真管线:会话里的图片是按钮,别的界面不是)。
+
+## 兼容
+
+- 接口、磁盘格式、线上协议都没变。会话之外的图片仍是原来那个 `<img>`;会话里的图片多了一层按钮,
+ 而被链接包住的图片渲染出的标记与以前一模一样。
diff --git a/packages/ui/src/components/content/prose/prose.tsx b/packages/ui/src/components/content/prose/prose.tsx
index 1c900882..c892b14c 100644
--- a/packages/ui/src/components/content/prose/prose.tsx
+++ b/packages/ui/src/components/content/prose/prose.tsx
@@ -25,6 +25,11 @@
* Links open in a new tab unless a `ProseLinksProvider` above decides otherwise — the Web App's
* conversation sends a link to a Workspace file to its Files panel that way.
*
+ * A picture is a plain `<img>` — unless a `ProseImagesProvider` above turns `zoomable` on, which is
+ * what a conversation does: there a click opens the picture in the lightbox, because a 2000px
+ * screenshot fitted to the reading column is too small to read and there was no way to see it whole
+ * short of the Files panel. Every other surface keeps the still picture a README expects.
+ *
* Two optional props open the renderer to a surface with its own nodes — the channel message body,
* which keeps `@mentions` as chips — without a second copy of the pipeline drifting from this one.
* They only ever ADD to the shared stage and to the maps below; nothing a surface passes can take
@@ -35,6 +40,7 @@ import type { ComponentPropsWithoutRef, MouseEvent, ReactElement, ReactNode } fr
import ReactMarkdown from "react-markdown";
import type { Components, ExtraProps, Options } from "react-markdown";
import { CodeBlock } from "../code-block/code-block";
+import { ZoomableImage } from "../../overlays/lightbox/lightbox";
import { NO_REHYPE_PLUGINS, REHYPE_PLUGINS, REMARK_PLUGINS } from "./markdown-plugins";
import "katex/dist/katex.min.css";
import "./prose.css";
@@ -113,6 +119,15 @@ export type ProseImageResolver = (src: string, alt: string) => { src: string } |
const ProseImagesContext = createContext<ProseImageResolver | null>(null);
+/** Whether a click on a picture below opens it in the lightbox; off unless a provider turns it on. */
+const ProseImageZoomContext = createContext(false);
+
+/**
+ * Whether the picture below sits inside a link. `MdLink` sets it for its own children, so it is
+ * always `false` unless a link put it there; a consumer only reads it.
+ */
+const ProseInLinkContext = createContext(false);
+
/**
* Hands the Markdown below an image resolver; `null` restores the default, the src as written.
*
@@ -121,15 +136,26 @@ const ProseImagesContext = createContext<ProseImageResolver | null>(null);
* do. It exists because a relative src in a reply names a file of the Session's Workspace, which
* the browser resolves against the App's own origin — a broken image. The surface that knows how
* to serve a Workspace file says so here; every other Markdown surface renders untouched.
+ *
+ * `zoomable` is independent of the resolver: it says the pictures below are read at their own size
+ * (a conversation, where a reply's screenshot is the subject), not decoration (a README's badge,
+ * where a click opening an overlay would only get in the way). Off by default, and it is a plain
+ * boolean, so a surface that leaves it out pays nothing.
*/
export function ProseImagesProvider({
resolve,
+ zoomable = false,
children,
}: {
resolve: ProseImageResolver | null;
+ zoomable?: boolean;
children?: ReactNode;
}): ReactElement {
- return <ProseImagesContext.Provider value={resolve}>{children}</ProseImagesContext.Provider>;
+ return (
+ <ProseImageZoomContext.Provider value={zoomable}>
+ <ProseImagesContext.Provider value={resolve}>{children}</ProseImagesContext.Provider>
+ </ProseImageZoomContext.Provider>
+ );
}
/**
@@ -140,6 +166,9 @@ export function ProseImagesProvider({
* sits after the spread so it always wins. A link title (`[text](url "title")`) becomes the shared
* tooltip's text rather than a native `title`, like every other hover hint. Long-URL wrapping is
* CSS (`.md-body a` in prose.css).
+ *
+ * The children are wrapped in {@link ProseInLinkContext}: a picture the author made into a link
+ * (`[![shot](shot.png)](…)`) belongs to the link, and the image adapter below has to know that.
*/
function MdLink({
node: _node,
@@ -151,7 +180,7 @@ function MdLink({
const behavior = resolve === null ? PROSE_NEW_TAB : resolve(anchorProps.href);
return (
<a {...anchorProps} data-tooltip={title} {...behavior}>
- {children}
+ <ProseInLinkContext.Provider value>{children}</ProseInLinkContext.Provider>
</a>
);
}
@@ -165,6 +194,15 @@ function MdLink({
* page itself. Everything else react-markdown supplies (width, height, title, ...) is forwarded;
* only its non-DOM `node` prop is stripped. Sizing is CSS (`.md-body img` in prose.css), so an
* oversized picture fits the reading column instead of widening the transcript.
+ *
+ * With `zoomable` above, the picture becomes a {@link ZoomableImage} and a click opens it whole —
+ * which is the difference between seeing that a screenshot is a screenshot and reading what is in
+ * it. Two cases keep the still `<img>`: an empty src, where there is nothing to enlarge (the
+ * lightbox would open on the browser's broken-image placeholder), and a picture the author wrapped
+ * in a link (`[![shot](shot.png)](…)`) — there the click is the link's, and a button in an anchor
+ * would fire both (measured: the button's own handler, then the anchor's navigation), so the
+ * picture would open a tab and an overlay at once. An author who made the picture a link meant the
+ * link.
*/
function MdImage({
node: _node,
@@ -173,9 +211,14 @@ function MdImage({
...imageProps
}: ComponentPropsWithoutRef<"img"> & ExtraProps) {
const resolve = useContext(ProseImagesContext);
+ const zoomable = useContext(ProseImageZoomContext);
+ const inLink = useContext(ProseInLinkContext);
const written = typeof src === "string" ? src : "";
const resolved = written === "" ? null : (resolve?.(written, alt ?? "") ?? null);
const href = resolved?.src ?? written;
+ if (zoomable && !inLink && href !== "") {
+ return <ZoomableImage src={href} alt={alt ?? ""} lazy {...imageProps} />;
+ }
return (
<img {...imageProps} {...(href === "" ? {} : { src: href })} alt={alt ?? ""} loading="lazy" />
);
diff --git a/packages/ui/src/components/overlays/lightbox/lightbox.tsx b/packages/ui/src/components/overlays/lightbox/lightbox.tsx
index 2a2a7e2f..50633fa4 100644
--- a/packages/ui/src/components/overlays/lightbox/lightbox.tsx
+++ b/packages/ui/src/components/overlays/lightbox/lightbox.tsx
@@ -10,6 +10,7 @@
* inside a dialog closes alone and leaves the dialog up.
*/
import { useState } from "react";
+import type { ComponentPropsWithoutRef } from "react";
import { createPortal } from "react-dom";
import { useUiStrings } from "../../../strings";
import { CloseIcon } from "../../icons/marks/marks";
@@ -66,6 +67,7 @@ export function ZoomableImage({
className,
closeLabel,
lazy = false,
+ ...imgProps
}: {
src: string;
alt: string;
@@ -75,12 +77,21 @@ export function ZoomableImage({
closeLabel?: string;
/** Fetch the thumbnail only as it nears the viewport (a long list of fetched images, e.g. a transcript's). */
lazy?: boolean;
-}) {
+} & Omit<ComponentPropsWithoutRef<"img">, "src" | "alt" | "className" | "loading">) {
const [open, setOpen] = useState(false);
return (
<>
<button type="button" className="block cursor-zoom-in" onClick={() => setOpen(true)}>
- <img src={src} alt={alt} className={className} loading={lazy ? "lazy" : undefined} />
+ {/* Everything else the caller's img already had — a Markdown picture's title, width and
+ height — belongs to the thumbnail: those are how it fits the text it sits in. The
+ lightbox shows the file at its own size and takes only src and alt. */}
+ <img
+ {...imgProps}
+ src={src}
+ alt={alt}
+ className={className}
+ loading={lazy ? "lazy" : undefined}
+ />
</button>
<Lightbox
open={open}
diff --git a/packages/ui/test/lightbox.test.ts b/packages/ui/test/lightbox.test.ts
index 40c8dc59..cb44a8c2 100644
--- a/packages/ui/test/lightbox.test.ts
+++ b/packages/ui/test/lightbox.test.ts
@@ -37,6 +37,22 @@ describe("ZoomableImage", () => {
'<button type="button" class="block cursor-zoom-in"><img src="/a.png" alt="Chart" class="h-20"/></button>',
);
});
+
+ it("carries the caller's other picture attributes to the thumbnail, not to the lightbox", () => {
+ const html = renderStatic(
+ createElement(ZoomableImage, {
+ src: "/a.png",
+ alt: "Chart",
+ title: "预览",
+ width: 320,
+ lazy: true,
+ }),
+ );
+ const thumbnail = html.match(/<img\b[^>]*>/)?.[0] ?? "";
+ expect(thumbnail).toContain('title="预览"');
+ expect(thumbnail).toContain('width="320"');
+ expect(thumbnail).toContain('loading="lazy"');
+ });
});
describe("Lightbox", () => {
diff --git a/packages/ui/test/prose.test.ts b/packages/ui/test/prose.test.ts
index 03144da2..a8b9112e 100644
--- a/packages/ui/test/prose.test.ts
+++ b/packages/ui/test/prose.test.ts
@@ -1,7 +1,8 @@
/**
* Prose and Md: Markdown in its reading box, the three densities, the link default and the
- * resolver that overrides it, the image adapter and the resolver that points a src elsewhere,
- * fenced code routed into CodeBlock, and the stylesheet the box reads.
+ * resolver that overrides it, the image adapter and the resolver that points a src elsewhere (and
+ * the zoom a conversation asks for), fenced code routed into CodeBlock, and the stylesheet the box
+ * reads.
* How the pipeline typesets math is prose-math.test.ts; where a bare URL ends is
* remark-autolink-boundary.test.ts.
*/
@@ -130,6 +131,81 @@ describe("Md images", () => {
expect(tags?.[0]).toContain('alt="a"');
expect(tags?.[0]).not.toContain("src=");
});
+
+ it("stay a bare picture on a surface that does not ask for zoom", () => {
+ const html = renderStatic(
+ createElement(ProseImagesProvider, {
+ resolve: null,
+ children: createElement(Md, { text: "![截图](a.png)" }),
+ }),
+ );
+ // A README's badge is decoration: a click on it must keep doing whatever the page around it does.
+ expect(html).toContain('<img src="a.png" alt="截图" loading="lazy"/>');
+ expect(html).not.toContain("<button");
+ });
+
+ it("become a button over the lightbox when the provider is zoomable", () => {
+ const html = renderStatic(
+ createElement(ProseImagesProvider, {
+ resolve: null,
+ zoomable: true,
+ children: createElement(Md, { text: "![截图](a.png)" }),
+ }),
+ );
+ expect(html).toContain('<button type="button" class="block cursor-zoom-in">');
+ expect(html).toContain('<img src="a.png" alt="截图" loading="lazy"/>');
+ // Nothing is portalled over the page until the picture is clicked.
+ expect(html.match(/<img\b/g)).toHaveLength(1);
+ });
+
+ it("zoom the src the resolver chose, not the one the Markdown wrote", () => {
+ const html = renderStatic(
+ createElement(ProseImagesProvider, {
+ resolve: () => ({ src: "/files/a.png" }),
+ zoomable: true,
+ children: createElement(Md, { text: "![截图](a.png)" }),
+ }),
+ );
+ expect(imageSrcs(html)).toEqual(["/files/a.png"]);
+ });
+
+ it("keep a picture with nothing to enlarge a bare picture even when zoomable", () => {
+ const html = renderStatic(
+ createElement(ProseImagesProvider, {
+ resolve: null,
+ zoomable: true,
+ children: createElement(Md, { text: "![a]()" }),
+ }),
+ );
+ expect(html).not.toContain("<button");
+ expect(html).not.toContain("src=");
+ });
+
+ it("leave a picture the author wrapped in a link to that link", () => {
+ const html = renderStatic(
+ createElement(ProseImagesProvider, {
+ resolve: null,
+ zoomable: true,
+ children: createElement(Md, { text: "[![截图](a.png)](https://x.dev/page)" }),
+ }),
+ );
+ // A button in an anchor fires both handlers (the picture would open a tab and an overlay at
+ // once), so the link keeps the click it was given.
+ expect(html).not.toContain("<button");
+ expect(anchors(html)[0]).toContain('href="https://x.dev/page"');
+ expect(html).toContain('<img src="a.png" alt="截图"');
+ });
+
+ it("zoom a picture that sits beside a link, not one inside it", () => {
+ const html = renderStatic(
+ createElement(ProseImagesProvider, {
+ resolve: null,
+ zoomable: true,
+ children: createElement(Md, { text: "[doc](https://x.dev) ![截图](a.png)" }),
+ }),
+ );
+ expect(html).toContain('<button type="button" class="block cursor-zoom-in">');
+ });
});
describe("Md code", () => {
diff --git a/packages/web/src/features/chat/workspace-refs.tsx b/packages/web/src/features/chat/workspace-refs.tsx
index 93118cfe..51c9fee4 100644
--- a/packages/web/src/features/chat/workspace-refs.tsx
+++ b/packages/web/src/features/chat/workspace-refs.tsx
@@ -11,6 +11,10 @@
* Both resolvers are memoized on their inputs and the two enter/leave together: a context change
* re-renders every link and image in the transcript, memoized message bodies included, so
* `onOpenFile` and `fileUrl` have to be stable callbacks.
+ *
+ * `zoomable` is unconditional: in a conversation a picture is something to look at, so a click
+ * opens it whole whatever its src resolved to — the resolver decides where the picture is fetched
+ * from, not whether the reader may enlarge it.
*/
import { useMemo } from "react";
import type { ReactNode } from "react";
@@ -52,7 +56,9 @@ export function WorkspaceRefsProvider({
);
return (
<ProseLinksProvider resolve={resolveLink}>
- <ProseImagesProvider resolve={resolveImage}>{children}</ProseImagesProvider>
+ <ProseImagesProvider resolve={resolveImage} zoomable>
+ {children}
+ </ProseImagesProvider>
</ProseLinksProvider>
);
}
diff --git a/packages/web/test/md.test.ts b/packages/web/test/md.test.ts
index 70a9db99..f6c9bc3c 100644
--- a/packages/web/test/md.test.ts
+++ b/packages/web/test/md.test.ts
@@ -12,7 +12,8 @@
* renders; Shiki only loads in an effect, which static markup never runs);
* - an image whose src names a Workspace file is fetched from that Session's file route, while an
* external or unresolvable src keeps the one the Markdown wrote. How a src is sorted is
- * reply-image.test.ts.
+ * reply-image.test.ts. Inside a conversation the picture is a button over the lightbox; anywhere
+ * else it stays a still <img>.
*/
import { describe, expect, it, vi } from "vitest";
import { createElement } from "react";
@@ -216,6 +217,15 @@ describe("Md images", () => {
]);
}
});
+
+ it("is clickable in a conversation and still on any other surface", () => {
+ const inConversation = renderInConversation("![预览](shots/cat.png)");
+ expect(inConversation).toContain('<button type="button" class="block cursor-zoom-in">');
+ expect(inConversation).toContain('alt="预览"');
+ // Outside one — a handbook page, the Memory view, a file preview — the picture stays an <img>,
+ // so nothing a README or a document lays out turns into a button.
+ expect(render("![预览](shots/cat.png)")).not.toContain("<button");
+ });
});
describe("Md code blocks", () => {