From 9ebe9410aa1a63b35bbfc1816e1268b65fb871c5 Mon Sep 17 00:00:00 2001 From: Lotus Bot Date: Thu, 21 May 2026 19:26:52 -0400 Subject: [PATCH] fix: guard Icon src against non-function values to prevent crash Add defensive check in folds Icon component so that if src is ever undefined or non-function (root cause unknown, possibly data-dependent), the SVG renders empty rather than throwing and crashing the whole app. Also adds postinstall script to re-apply the patch after npm install. Co-Authored-By: Claude Sonnet 4.6 --- package.json | 5 +++-- scripts/patch-folds.mjs | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 scripts/patch-folds.mjs diff --git a/package.json b/package.json index afdd17537..80b4bb556 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "lotus-chat", "version": "4.12.1-lotus", - "description": "Lotus Chat — Matrix client for Lotus Guild", + "description": "Lotus Chat \u2014 Matrix client for Lotus Guild", "main": "index.js", "type": "module", "engines": { @@ -18,7 +18,8 @@ "typecheck": "tsc --noEmit", "prepare": "husky install", "commit": "git-cz", - "semantic-release": "semantic-release" + "semantic-release": "semantic-release", + "postinstall": "node scripts/patch-folds.mjs" }, "lint-staged": { "*.{ts,tsx,js,jsx}": "eslint", diff --git a/scripts/patch-folds.mjs b/scripts/patch-folds.mjs new file mode 100644 index 000000000..19132afb1 --- /dev/null +++ b/scripts/patch-folds.mjs @@ -0,0 +1,26 @@ +import { readFileSync, writeFileSync } from 'fs'; +import { fileURLToPath } from 'url'; +import { join, dirname } from 'path'; + +const __dirname = dirname(fileURLToPath(import.meta.url)); +const foldsPath = join(__dirname, '../node_modules/folds/dist/index.js'); + +try { + let content = readFileSync(foldsPath, 'utf8'); + + // Defensive guard: if src is not a function, render null instead of crashing + const original = 'children: src(filled)'; + const patched = 'children: typeof src === "function" ? src(filled) : null'; + + if (content.includes(patched)) { + console.log('folds patch already applied.'); + } else if (content.includes(original)) { + content = content.replace(original, patched); + writeFileSync(foldsPath, content, 'utf8'); + console.log('Applied defensive Icon src guard to folds.'); + } else { + console.warn('Warning: folds Icon patch target not found - may need updating.'); + } +} catch (e) { + console.warn('Warning: Could not patch folds:', e.message); +}