fix: prevent tab group add/remove infinite loop when dragging tabs

When a user drags a tab into the playwriter group, connectTab() sets
its state to 'connecting'. syncTabGroup() previously only kept
'connected' tabs in the group, so it would immediately ungroup the
'connecting' tab. This ungroup fired chrome.tabs.onUpdated, which
called disconnectTab(). When the original connectTab() resolved, it
re-added the tab, triggering onUpdated again — creating an infinite
add/remove/add/remove loop.

Fix: include 'connecting' tabs in syncTabGroup's group membership
filter. This way syncTabGroup won't fight the user's intent by
removing tabs that are still being set up. Error-state tabs are
still correctly excluded from the group.
This commit is contained in:
Tommy D. Rossi
2026-02-06 15:39:35 +01:00
parent d6adb460d5
commit 78734bf1e8
+4 -3
View File
@@ -683,10 +683,11 @@ export function sendMessage(message: any): void {
async function syncTabGroup(): Promise<void> {
try {
// Only tabs with state 'connected' are in the group.
// Tabs in 'connecting' or 'error' state are removed from the group.
// Tabs in 'connected' or 'connecting' state belong in the group.
// Including 'connecting' prevents a loop where syncTabGroup removes a tab the user
// just dragged in (still connecting), which triggers onUpdated → disconnect → reconnect.
const connectedTabIds = Array.from(store.getState().tabs.entries())
.filter(([_, info]) => info.state === 'connected')
.filter(([_, info]) => info.state === 'connected' || info.state === 'connecting')
.map(([tabId]) => tabId)
// Always query by title - no cached ID that can go stale