From b94f4869de9e7b2d8c470aac970a762a34c68788 Mon Sep 17 00:00:00 2001 From: Luiz Gustavo Date: Thu, 21 May 2026 16:40:51 -0300 Subject: [PATCH] fix: render image description when chunk has no bbox (no broken crop) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 29 image chunks have an empty bbox {}, and `fm.bbox ?? default` doesn't catch an empty object, so the crop URL got w=undefined → /api/crop 400 → broken-image icon. Now validate bbox (w/h > 0); without it, render the image's textual description instead of requesting an impossible crop. Co-Authored-By: Claude Opus 4.7 --- web/components/doc-renderer-v2.tsx | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/web/components/doc-renderer-v2.tsx b/web/components/doc-renderer-v2.tsx index c31b176..54af0e2 100644 --- a/web/components/doc-renderer-v2.tsx +++ b/web/components/doc-renderer-v2.tsx @@ -141,6 +141,33 @@ function ChunkCard({ // Image chunks: render crop inline if (fm.type === "image" || fm.image_type) { + const hasValidBbox = + bbox && + typeof bbox.w === "number" && typeof bbox.h === "number" && + typeof bbox.x === "number" && typeof bbox.y === "number" && + bbox.w > 0 && bbox.h > 0; + + // No crop coordinates → don't request a broken crop (400). Render the + // image's textual description so the content is still surfaced. + if (!hasValidBbox) { + const descEn = fm.image_description_en || content_en; + const descPt = fm.image_description_pt_br || content_pt; + if (!descEn && !descPt) return null; + return ( +
+ {anchor} +
+
+ 🖼 {fm.chunk_id} · p{fm.page} + {fm.image_type ? ` · ${fm.image_type}` : ""} · descrição (sem recorte) +
+ {showEn && descEn &&

EN: {descEn}

} + {showPt && descPt &&

PT-BR: {descPt}

} +
+
+ ); + } + const cropUrl = `/api/crop?doc=${encodeURIComponent(docId)}` + `&page=${fm.page}&x=${bbox.x}&y=${bbox.y}&w=${bbox.w}&h=${bbox.h}&w_px=800`;