From 156c76baae2a8b4ca3cda690c7080a1cfe8cd266 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 13 May 2026 09:30:22 +0000 Subject: [PATCH] Fix crash: state initialized before CFG is loaded state.baseCurrency was set to CFG['currency-base'] at declaration time, but CFG is only populated after await loadConfig(). Reading a property of undefined throws synchronously, crashing the script before init() runs. Move the assignment to after loadConfig() resolves in init(). https://claude.ai/code/session_014uUwDBtG5y5FuWcy5zqVD1 --- index.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 878726a..7deea82 100644 --- a/index.html +++ b/index.html @@ -140,7 +140,7 @@ async function loadConfig() { } // ========== STATE ========== -const state = { staff: '', periodFrom: '', periodTo: '', baseCurrency: CFG['currency-base'], fxRateMemory: {}, items: [], _grandTotal: 0 }; +const state = { staff: '', periodFrom: '', periodTo: '', baseCurrency: '', fxRateMemory: {}, items: [], _grandTotal: 0 }; function newItem() { return { id: uid(), name: '', lines: [newLine()], _subtotal: 0 }; } function newLine() { @@ -848,6 +848,7 @@ async function onGenerate() { async function init() { try { await loadConfig(); + state.baseCurrency = CFG['currency-base']; state.items.push(newItem()); render(); } catch (e) {