fix(sync): harden terminal state races

This commit is contained in:
Timo
2026-09-01 03:34:01 +02:00
parent 77e7d0c103
commit bc5d1a0ea6
5 changed files with 55 additions and 10 deletions
+9 -5
View File
@@ -1185,11 +1185,9 @@ async function clearTargetSelectionForLifecycle({
}
resetUserSelectionState();
const cleanupTasks = [clearPendingTarget()];
if (previousTabId !== null) {
cleanupTasks.push(deactivateTargetTab(previousTabId, previousContentTarget));
}
await Promise.all(cleanupTasks);
// Persist the terminal selection state before any frame messaging or host
// permission cleanup can yield. A worker stop or a concurrent new target
// must never resurrect the selection this lifecycle transition removed.
await chrome.storage.session.set({
currentTabId,
currentTabTitle,
@@ -1203,6 +1201,12 @@ async function clearTargetSelectionForLifecycle({
selectionErrorTabId: null,
selectionErrorMessage: null
});
const cleanupTasks = [clearPendingTarget()];
if (previousTabId !== null) {
cleanupTasks.push(deactivateTargetTab(previousTabId, previousContentTarget));
}
await Promise.all(cleanupTasks);
updateBadgeStatus();
chrome.runtime.sendMessage({ type: 'TARGET_TAB_CLEARED', tabId: clearedTabId }).catch(() => {});
return true;