From cd2e4ae9f9c067cd49095c051be99fdac9a82b42 Mon Sep 17 00:00:00 2001 From: ZProger Date: Thu, 10 Sep 2026 19:17:20 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20=D0=B7=D0=B0=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20crypto.randomUUID()=20=D0=BD=D0=B0=20fallback=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20HTTP=20=D0=B1=D0=B5=D0=B7=20TLS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit crypto.randomUUID() доступен только в secure context (HTTPS/localhost), из-за чего при открытии приложения по обычному HTTP падал TypeError при добавлении сплитов транзакции. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01769tkxLJooEWNjx3xc9aCv --- .../transactions/TransactionFormModal.tsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/transactions/TransactionFormModal.tsx b/frontend/src/components/transactions/TransactionFormModal.tsx index c5a0e9a..71d9695 100644 --- a/frontend/src/components/transactions/TransactionFormModal.tsx +++ b/frontend/src/components/transactions/TransactionFormModal.tsx @@ -41,8 +41,19 @@ interface SplitRowState { note: string; } +// crypto.randomUUID() only exists in secure contexts (HTTPS/localhost) — on plain +// HTTP (e.g. accessing the app by LAN IP) it's undefined and throws a TypeError. +// This key is only a local React list key, never sent to the backend, so a +// Math.random()-based fallback is fine when the Web Crypto API isn't available. +function generateRowKey(): string { + if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") { + return crypto.randomUUID(); + } + return `split-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`; +} + function emptySplitRow(): SplitRowState { - return { key: crypto.randomUUID(), category_id: "", amount: "", note: "" }; + return { key: generateRowKey(), category_id: "", amount: "", note: "" }; } // Cents, not floats — a plain Number sum of "0.10" + "0.20" style amounts can