fix: clear terminal drag-and-drop observer on detach (fixes #311164) - #332908
fix: clear terminal drag-and-drop observer on detach (fixes #311164)#332908Suryaansh Prithvijit Singh (Ultron09) wants to merge 3 commits into
Conversation
…#311164) Clears `TerminalInstance._dndObserver` when detaching from DOM container, and guards deferred `_initDragAndDrop` execution against detached/disposed container changes. Co-authored-by: Vlad Gerasimov <vlad@vlad.studio>
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: Anthony Kim (@anthonykim1)Matched files:
|
There was a problem hiding this comment.
Pull request overview
Fixes leaked terminal drag-and-drop observers when editor containers are reused.
Changes:
- Clears the observer when detaching.
- Guards deferred initialization against stale containers.
- Adds detach cleanup coverage.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
terminalInstance.ts |
Cleans up and guards drag-and-drop observers. |
terminalInstance.test.ts |
Tests observer cleanup during detach. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Added a unit test in |
|
I prepared stronger regression coverage that creates real I couldn't push to the contributor fork because maintainer edits are unavailable. Please cherry-pick b1b63b784ac into this branch. |
|
Replacing with #335945 which has better unit-tests. |
|
Thanks Dmitriy Vasyura (@dmitrivMS) for the review, approval, and for strengthening the regression coverage in #335945! Left a quick note on #335945 to please include |
Summary
Fixes #311164.
Supersedes #318756 with requested unit tests and race condition guards.
TerminalInstance._dndObserver(aMutableDisposable<IDisposable>holding the per-containerDragAndDropObserver) was set by_initDragAndDropbut never cleared bydetachFromElement. When aTerminalEditorpane reuses its container across tab switches (setInputcallsdetachFromElementon the old instance andattachToElementon the new one), newly-attached terminals stacked additionalDragAndDropObservers on top of leaked ones.When shift-dropping a file onto the active editor-area terminal, each previous instance's observer fired on the shared container and inserted the path.
Changes
this._dndObserver.clear()indetachFromElement()so drops on the old container no longer route to the detached terminal instance.setTimeoutinattachToElementwithif (this._store.isDisposed || this._container !== container) return;so a synchronous detach in the same tick does not re-attach a stale observer.terminalInstance.test.tsverifying thatdetachFromElementproperly clears the observer.Co-authored-by: Vlad Gerasimov vlad@vlad.studio