From 485a527bf63385cada456c7fac84ce4b70688e75 Mon Sep 17 00:00:00 2001 From: Claude Dev Date: Mon, 23 Mar 2026 22:17:15 +0100 Subject: [PATCH] Tutorial: Race-Condition bei Neustart behoben - start(forceRestart) awaited jetzt API.resetTutorialState() - _startInternal awaited API.saveTutorialState(step 0) - stop() ueberspringt State-Save wenn _isRestarting flag gesetzt - start() kann jetzt auch bei laufendem Tutorial Restart ausfuehren --- src/static/js/tutorial.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/static/js/tutorial.js b/src/static/js/tutorial.js index ae8cc51..68d49b8 100644 --- a/src/static/js/tutorial.js +++ b/src/static/js/tutorial.js @@ -1217,6 +1217,11 @@ const Tutorial = { // Lifecycle // ----------------------------------------------------------------------- async start(forceRestart) { + // Bei Restart: laufendes Tutorial erst sauber beenden + if (this._isActive && forceRestart) { + this._isRestarting = true; + this.stop(); + } if (this._isActive) return; // Chat schliessen falls offen @@ -1233,7 +1238,7 @@ const Tutorial = { } if (forceRestart) { - try { API.resetTutorialState(); } catch(e) {} + try { await API.resetTutorialState(); } catch(e) {} } this._startInternal(forceRestart ? 0 : null); }, @@ -1260,15 +1265,16 @@ const Tutorial = { }); }, - _startInternal(resumeStep) { + async _startInternal(resumeStep) { this._isActive = true; this._highestStep = -1; this._currentStep = -1; // Server-State auf Anfang setzen wenn Neustart if (!resumeStep || resumeStep === 0) { - API.saveTutorialState({ current_step: 0, completed: false }).catch(function() {}); + try { await API.saveTutorialState({ current_step: 0, completed: false }); } catch(e) {} } + this._isRestarting = false; // Overlay einblenden + Klicks blockieren this._els.overlay.classList.add('active'); @@ -1344,8 +1350,10 @@ const Tutorial = { this._resizeHandler = null; } - // Fortschritt serverseitig speichern - if (this._lastExitedStep >= 0 && this._lastExitedStep < this._steps.length - 1) { + // Fortschritt serverseitig speichern (nicht bei Restart) + if (this._isRestarting) { + // Restart - State wird von start() zurueckgesetzt + } else if (this._lastExitedStep >= 0 && this._lastExitedStep < this._steps.length - 1) { // Mittendrin abgebrochen — Schritt speichern API.saveTutorialState({ current_step: this._lastExitedStep }).catch(function() {}); } else {