From c447abfd41b3ac023dc8fa4d0489485a1e424a40 Mon Sep 17 00:00:00 2001 From: Maksim Kostromin Date: Mon, 12 Oct 2026 20:38:53 -0400 Subject: [PATCH] fix(csv): 02-2.4 validate the shape of saved datasets loadPersistedDataSets returned any non-empty JSON array from localStorage, so a damaged or foreign record reached the table code and failed there (.map is not a function). It now restores only an array of { fileName: string, data: string[][] } and otherwise starts empty, the path an empty store already takes --- src/main.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main.tsx b/src/main.tsx index 3525b53..b95d96a 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -696,7 +696,11 @@ function loadPersistedDataSets(): DataSet[] | null { const raw = localStorage.getItem(LOCALSTORAGE_DATA_KEY); if (!raw) return null; const parsed = JSON.parse(raw); - if (Array.isArray(parsed) && parsed.length > 0) return parsed as DataSet[]; + // A damaged or foreign record (e.g. {"dataSets": "x"}) must not reach the table code: check the DataSet shape + const valid = Array.isArray(parsed) && parsed.length > 0 && parsed.every((d: any) => + d && typeof d.fileName === 'string' && Array.isArray(d.data) && d.data.every((row: unknown) => Array.isArray(row))); + if (valid) return parsed as DataSet[]; + if (parsed !== null) console.warn('[RememberData] Ignoring persisted datasets with an unexpected shape'); return null; } catch (err) { console.warn('[RememberData] Failed to load persisted datasets:', err);