fix: don't rebuild tab model on EDITORS_SELECTION event#317227
Open
yogeshwaran-c wants to merge 1 commit into
Open
fix: don't rebuild tab model on EDITORS_SELECTION event#317227yogeshwaran-c wants to merge 1 commit into
yogeshwaran-c wants to merge 1 commit into
Conversation
When the multi-select selection state of editors changes, the editor group model fires an EDITORS_SELECTION event. The switch in MainThreadEditorTabs._updateTabsModel did not handle this kind, so it fell through to the default branch and called _createTabsModel(), rebuilding the entire tab model. A full rebuild sends $acceptEditorTabModel to the extension host, which recreates every ExtHostEditorTabGroup and ExtHostEditorTab instance. Any vscode.Tab reference an extension is still holding becomes stale: _findExtHostTabFromApi compares apiObject by reference, so subsequent calls like tabGroups.close(tab) throw 'Tab close: Invalid tab not found!'. Reproduction (from issue): an extension stores the currently active tab, opens a webview in the same view column, awaits an async hop (e.g. webview.postMessage), then calls tabGroups.close on the stored tab. The webview open triggers EDITOR_OPEN followed by EDITORS_SELECTION; the latter caused the rebuild between the extension capturing the tab reference and using it. Multi-select state is workbench-internal and not exposed in the tabs API, so this event can be treated as a no-op (same as EDITOR_TRANSIENT which is also not surfaced through the API). Regression introduced by 88bc75f (Tabs Multi Select, microsoft#211712). Fixes microsoft#228270
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a tabs API regression where workbench-internal editor multi-selection changes caused the extension-host tab model to be rebuilt, invalidating existing vscode.Tab references held by extensions.
Changes:
- Treats
GroupModelChangeKind.EDITORS_SELECTIONas a no-op inMainThreadEditorTabs. - Prevents unnecessary full tab model rebuilds for selection state that is not exposed through the tabs API.
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.
Summary
Fixes #228270 —
vscode.window.tabGroups.close(tab)throwsTab close: Invalid tab not found!after an extension opens a webview in the same view column as the stored tab.Root cause
bpasero's bisect on the issue points at 88bc75f (Tabs Multi Select, #211712), which introduced a new
GroupModelChangeKind.EDITORS_SELECTIONevent that the editor group model fires whenever the selected editors change (e.g. as a side effect ofsetSelectiononEDITOR_OPENandEDITOR_ACTIVE).The switch in
MainThreadEditorTabs._updateTabsModeldoesn't have a case forEDITORS_SELECTION, so it falls through todefault, which calls_createTabsModel()and sends a full$acceptEditorTabModelto the extension host.ExtHostEditorTabs.$acceptEditorTabModelrebuilds everyExtHostEditorTabGroup/ExtHostEditorTabfrom scratch, so anyvscode.TabAPI object an extension is still holding becomes a stale reference._findExtHostTabFromApithen can't match the extension's tab viatab.apiObject === apiTaband_closeTabsthrowsTab close: Invalid tab not found!.The issue's repro is:
tabGroups.activeTabGroup.activeTab.createWebviewPanel(..., tab.group.viewColumn)→EDITOR_OPEN(handled) followed byEDITORS_SELECTION(falls intodefault→ full rebuild → tab reference invalidated).webview.postMessage), then callstabGroups.close(tab)→ throws.Fix
Handle
EDITORS_SELECTIONas a no-op in the switch. Multi-select is a workbench-internal concept and isn't exposed via the tabs API — the same treatment we already giveEDITOR_TRANSIENT. The handled events (EDITOR_OPEN,EDITOR_CLOSE,EDITOR_ACTIVE, etc.) already deliver the surface that's actually exposed throughvscode.window.tabGroups, so suppressing the rebuild has no observable effect on the API other than preserving reference identity.Test plan
main.Tab close: Invalid tab not found!in the debug console.onDidChangeTabsevent lost.ExtHostEditorTabssuite still passes (no changes to extHost side, model rebuild path is unchanged for events that should rebuild).Regression introduced by 88bc75f.