Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

fix(snapshot): downscale oversized grid exports

t8y272d72a15b77f
diff --git a/apps/desktop/src/lib/codeSnapshot/__tests__/codeSnapshot.spec.ts b/apps/desktop/src/lib/codeSnapshot/__tests__/codeSnapshot.spec.ts
index 1b6914b3df..2c581fc58d 100644
--- a/apps/desktop/src/lib/codeSnapshot/__tests__/codeSnapshot.spec.ts
+++ b/apps/desktop/src/lib/codeSnapshot/__tests__/codeSnapshot.spec.ts
@@ -302,11 +302,23 @@ describe("renderCodeSnapshotHtml", () => {
}
});
- it("rejects snapshots that exceed the safe rendering budget at 1x", async () => {
- toPng.mockClear();
+ it("downscales snapshots whose source width exceeds the canvas edge limit", async () => {
+ toPng.mockResolvedValue("data:image/png;base64,test");
+ vi.stubGlobal("window", { devicePixelRatio: 1 });
+ try {
+ await snapshotElementToPng({ offsetWidth: 18_788, offsetHeight: 152, scrollWidth: 18_788, scrollHeight: 152 } as HTMLElement);
- await expect(snapshotElementToPng({ offsetWidth: 20_000, offsetHeight: 100, scrollWidth: 20_000, scrollHeight: 100 } as HTMLElement)).rejects.toThrow("Snapshot is too large to export safely (20000 × 100px)");
- expect(toPng).not.toHaveBeenCalled();
+ expect(toPng).toHaveBeenLastCalledWith(
+ expect.anything(),
+ expect.objectContaining({
+ width: 18_788,
+ height: 152,
+ scale: 16_384 / 18_788,
+ }),
+ );
+ } finally {
+ vi.unstubAllGlobals();
+ }
});
it("propagates a failed native save instead of reporting a browser download", async () => {
diff --git a/apps/desktop/src/lib/codeSnapshot/codeSnapshot.ts b/apps/desktop/src/lib/codeSnapshot/codeSnapshot.ts
index 61257320ba..d9a0b64475 100644
--- a/apps/desktop/src/lib/codeSnapshot/codeSnapshot.ts
+++ b/apps/desktop/src/lib/codeSnapshot/codeSnapshot.ts
@@ -346,11 +346,10 @@ export async function snapshotElementToPng(element: HTMLElement): Promise<string
const width = Math.max(element.offsetWidth, element.scrollWidth);
const height = Math.max(element.offsetHeight, element.scrollHeight);
const basePixels = width * height;
- if (width > MAX_EXPORT_CANVAS_EDGE || height > MAX_EXPORT_CANVAS_EDGE || basePixels > MAX_EXPORT_CANVAS_PIXELS) {
- throw new Error(`Snapshot is too large to export safely (${width} × ${height}px). Reduce the code size and try again.`);
- }
-
const targetScale = Math.min(MAX_EXPORT_PIXEL_RATIO, Math.max(1, typeof window === "undefined" ? 1 : window.devicePixelRatio || 1));
+ // Keep the output canvas within browser limits without rejecting a larger
+ // source layout. Wide grids can still be captured safely by rasterizing the
+ // full DOM at a reduced scale.
const scale = Math.min(targetScale, MAX_EXPORT_CANVAS_EDGE / width, MAX_EXPORT_CANVAS_EDGE / height, Math.sqrt(MAX_EXPORT_CANVAS_PIXELS / basePixels));
const useLegacyLineNumberFallback = legacyWebViewExportFallbackEnabled();
return domtoimage.toPng(element, {