Fix tab indexing in close/reload/next/prev tab functions#2396
Open
lefevau wants to merge 3 commits into
Open
Conversation
Owner
|
So |
Author
|
It's not that it's missing, but rather it's wrong or maybe just stale. Doing some more digging I found: zen-browser/desktop#11210 Either way I made the requested changes to move the tab indexing into a |
hbt
added a commit
to hbt/Surfingkeys
that referenced
this pull request
May 31, 2026
…lookup Fixes 4 stale-snapshot usages where `tab.index` (captured from `sender.tab` at message-dispatch time) was used inside a `chrome.tabs.query` callback, by which time the tab may have been reordered. Changes: - Add `_getTabIndex(tabs, tabId)` helper that resolves live position by ID - `_nextTab`: replace `tab.index` with `_getTabIndex(tabs, tab.id)` for boundary check and `_fixTo` call; return early if tab not found - `_roundRepeatTabs`: same — replace `tab.index` with live lookup before `_roundBase` call - `previousTab`/`nextTab` switch-case (~line 783): move index arithmetic inside `chrome.tabs.query` callback; look up live index by tab ID instead of capturing stale `tab.index` before the async call - `tabURLAccessed` (~line 2231): add comment clarifying `sender.tab.index` is Chrome-fresh at message receipt (not a stale snapshot) — no fix needed Add scratch tests documenting the stale-index bug scenario: - `scratch-tab-stale-index.spec.ts` — covers `_nextTab` / `_roundRepeatTabs` - `scratch-tab-stale-index-prev-next.spec.ts` — covers the switch-case handler Relates to upstream brookhong#2396 (partial fix, only `_nextTab` and `_roundRepeatTabs`). #tab-navigation #async-race #stale-snapshot #fix #chrome-tabs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes issues with Zen (and potentially other browsers) where the index in the
tabsnapshot provided to these functions is stale, causing the wrong tabs to be targeted.Closes #2306