Code review comments on one notebook cell leak into other notebook cells as the Browser renderer reuses DOM which is not properly cleaned up #214585
Labels
insiders-released
Patch has been released in VS Code Insiders
notebook-commenting
Commenting support for notebooks
Milestone
This is an issue with the browser code, which happens for code review comments on notebook cells. I do not have a public repro, but I can describe line by line why this happens, and am happy to send a PR to fix it:
ListView
. ListView uses a cache to reuse widgets and DOM:vscode/src/vs/base/browser/ui/list/listView.ts
Line 905 in 6e6d380
CellComments
, aCellContentPart
, is reused, by callingrenderCell
/unrenderCell
:vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/markupCell.ts
Line 73 in 6facfe2
container
is passed in upon construction and held on to:vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellComments.ts
Lines 28 to 30 in 6facfe2
CommentThreadWidget
is constructed during initialization of aCellComments
, which is called on the firstrenderCell
, and then skipped for subsequent calls:vscode/src/vs/workbench/contrib/notebook/browser/view/cellParts/cellComments.ts
Lines 47 to 58 in 6facfe2
CommentThreadWidget
appends tocontainer
and installs some listeners:vscode/src/vs/workbench/contrib/comments/browser/commentThreadWidget.ts
Line 106 in 6facfe2
vscode/src/vs/workbench/contrib/comments/browser/commentThreadWidget.ts
Lines 263 to 267 in 6facfe2
unrenderCell()
, and the base classCellContentPart.unrenderCell()
removes listeners (that CellComents put into the corresponding DisposableStore), but does not unset_initialized
, clean up_commentThreadWidget
, or callCommentThreadWidget.dispose()
- they all leakonDidUpdateCommentThreads
fires, will_commentThreadWidget
be disposed (which as seen above does not remove the elements from the DOM - only the layout is reset to hide it, or replacedI think we need to do the following to fix this issue:
CommentThreadWidget
and its children (CommentThreadHeader) should remove the DOM elements they added tocontainer
when they are disposed(). That seems like good practice in general, and seems to be done at least in some other places in VSCode, e.g.vscode/src/vs/base/browser/ui/tree/abstractTree.ts
Lines 798 to 799 in 6125cc2
CellComments
should, instead of initializing only once, check if the ICellViewModel has changed in ondidRender
, and if so, run the same logic it runsonDidUpdateCommentThreads
, which will remove, created, or update the comment thread.I'll send a pull request to make this more concrete, happy to talk about other solutions to the problem, too.
@alexr00 @rebornix
The text was updated successfully, but these errors were encountered: