From b58ba414582c1419973b7b74c2c433aff2ac6103 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BA=BB=E8=96=AF?= Date: Tue, 7 Apr 2026 10:56:02 +0100 Subject: [PATCH] fix: cap watermark dimensions to prevent RangeError on large files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit buildWatermark() calls Array.join() on a lines array whose size is derived from tile dimensions divided by wmFontSize. For files with very many lines the codeFontSize (and thus wmFontSize) approaches zero, making charsPerLine and lineCount astronomically large and blowing past JS's string length limit. Fix by: 1. Clamping wmFontSize to a minimum of 1.0 to handle pathologically large files. 2. Capping charsPerLine at 400 and lineCount at 150 — the watermark is purely decorative so this cap has no visible impact. --- web/src/renderer.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/web/src/renderer.js b/web/src/renderer.js index ad49884..55ae7e2 100644 --- a/web/src/renderer.js +++ b/web/src/renderer.js @@ -302,11 +302,12 @@ export class RepoRenderer { // Watermark — tiled path text, 45° rotated, slightly larger than code font if (!tile.watermark) { const codeFontSize = (d.h / d.lines) * 0.65; - const wmFontSize = codeFontSize * 2.5; + // Clamp wmFontSize to avoid degenerate tiny values on files with huge line counts + const wmFontSize = Math.max(codeFontSize * 2.5, 1.0); const wmLabel = `${this.repoName}/${d.path}`; - // Estimate how many repetitions to fill the area - const charsPerLine = Math.ceil(Math.max(d.w, d.h) * 1.5 / (wmFontSize * 0.5)); - const lineCount = Math.ceil(Math.max(d.w, d.h) * 1.5 / (wmFontSize * 1.5)); + // Estimate how many repetitions to fill the area; cap to prevent RangeError on massive tiles + const charsPerLine = Math.min(Math.ceil(Math.max(d.w, d.h) * 1.5 / (wmFontSize * 0.5)), 400); + const lineCount = Math.min(Math.ceil(Math.max(d.w, d.h) * 1.5 / (wmFontSize * 1.5)), 150); const wmContent = buildWatermark(wmLabel, charsPerLine, lineCount); const wm = new Text();