From 7564f23ef1f72e3aae095802ced0dd84b0aae500 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 28 May 2026 22:19:56 +0200 Subject: [PATCH] fix: use allObjects._words to restore objectAssignments on EditPairForm load Replace async word search with synchronous lookup via allObjects._words, which is already populated. Eliminates race conditions and fetch failures. Co-Authored-By: Claude Sonnet 4.6 --- src/pages/ContentCreation.jsx | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/pages/ContentCreation.jsx b/src/pages/ContentCreation.jsx index 43f9140..797c101 100644 --- a/src/pages/ContentCreation.jsx +++ b/src/pages/ContentCreation.jsx @@ -531,19 +531,18 @@ function EditPairForm({ pair, allObjects, onSaved, onCancel, onDeleted }) { } } - // Directly look up word IDs for each extracted label and set objectAssignments + // Look up word IDs via allObjects._words (already loaded, no fetch needed) if (Object.keys(labelToObjId).length) { const assignments = {}; - await Promise.all(Object.entries(labelToObjId).map(async ([label, objId]) => { - try { - const words = await apiFetch(`/words?search=${encodeURIComponent(label)}&limit=5`); - const word = Array.isArray(words) && words.find(w => - (w.titel_de || '').toLowerCase() === label || - (w.titel_en || '').toLowerCase() === label - ); - if (word) assignments[word.id] = objId; - } catch { /* ignore */ } - })); + Object.entries(labelToObjId).forEach(([label, objId]) => { + const obj = (allObjects || []).find(o => o.id === objId); + const word = (obj?._words || []).find(w => + (w.titel_de || '').toLowerCase() === label || + (w.titel_en || '').toLowerCase() === label || + (w.titel_sv || '').toLowerCase() === label + ); + if (word) assignments[word.id] = objId; + }); if (Object.keys(assignments).length) setObjectAssignments(assignments); } } catch (e) { console.error(e); }