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 <noreply@anthropic.com>
This commit is contained in:
+3
-2
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "lotus-chat",
|
"name": "lotus-chat",
|
||||||
"version": "4.12.1-lotus",
|
"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",
|
"main": "index.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"engines": {
|
"engines": {
|
||||||
@@ -18,7 +18,8 @@
|
|||||||
"typecheck": "tsc --noEmit",
|
"typecheck": "tsc --noEmit",
|
||||||
"prepare": "husky install",
|
"prepare": "husky install",
|
||||||
"commit": "git-cz",
|
"commit": "git-cz",
|
||||||
"semantic-release": "semantic-release"
|
"semantic-release": "semantic-release",
|
||||||
|
"postinstall": "node scripts/patch-folds.mjs"
|
||||||
},
|
},
|
||||||
"lint-staged": {
|
"lint-staged": {
|
||||||
"*.{ts,tsx,js,jsx}": "eslint",
|
"*.{ts,tsx,js,jsx}": "eslint",
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user