From ef51c43032d295714700e622a0fc7d8175a486dd Mon Sep 17 00:00:00 2001 From: Ulas Date: Wed, 1 Apr 2026 10:11:24 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20meals=20drag=20&=20drop=20crash=20?= =?UTF-8?q?=E2=80=94=20destructure=20dragging=20before=20cleanup()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit cleanup() set dragging = null, then onUp accessed dragging.slot, .mealId, .sourceDate, .sourceType on the now-null reference. Fix: destructure all needed values before calling cleanup(). Co-Authored-By: Claude Sonnet 4.6 --- public/pages/meals.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/public/pages/meals.js b/public/pages/meals.js index 54e9883..6d3ec1e 100644 --- a/public/pages/meals.js +++ b/public/pages/meals.js @@ -349,20 +349,21 @@ function wireDragDrop(grid) { async function onUp(ev) { if (!dragging) return; - cleanup(); + const { mealId, sourceDate, sourceType, slot: sourceSlot } = dragging; + cleanup(); // setzt dragging = null — Werte daher vorher destrukturieren if (ghost) ghost.style.display = 'none'; const el = document.elementFromPoint(ev.clientX, ev.clientY); if (ghost) ghost.style.display = ''; const targetSlot = el?.closest('.meal-slot'); - if (targetSlot && targetSlot !== dragging.slot) { + if (targetSlot && targetSlot !== sourceSlot) { const targetDate = targetSlot.dataset.date; const targetType = targetSlot.dataset.type; const targetMealId = targetSlot.dataset.mealId ? parseInt(targetSlot.dataset.mealId, 10) : null; _suppressNextClick = true; setTimeout(() => { _suppressNextClick = false; }, 300); - await moveMeal(dragging.mealId, dragging.sourceDate, dragging.sourceType, targetDate, targetType, targetMealId); + await moveMeal(mealId, sourceDate, sourceType, targetDate, targetType, targetMealId); } }