Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR optimizes the _refresh method in CommentThreadBody to prevent unnecessary resize events by caching the previous container dimensions and only firing the resize event when dimensions actually change.
- Adds dimension caching to avoid redundant resize events
- Updates the early return condition to check both zero dimensions and unchanged dimensions
| private _refresh() { | ||
| const dimensions = dom.getClientArea(this.container); | ||
| if (dimensions.height === 0 && dimensions.width === 0) { | ||
| if ((dimensions.height === 0 && dimensions.width === 0) || (this._containerClientArea && this._containerClientArea.height === dimensions.height && this._containerClientArea.width === dimensions.width)) { |
There was a problem hiding this comment.
The condition is overly complex and difficult to read. Consider using Dimension.equals() helper method which already exists in the codebase for dimension comparison. This would simplify the condition to: if ((dimensions.height === 0 && dimensions.width === 0) || Dimension.equals(this._containerClientArea, dimensions))
| if ((dimensions.height === 0 && dimensions.width === 0) || (this._containerClientArea && this._containerClientArea.height === dimensions.height && this._containerClientArea.width === dimensions.width)) { | |
| if ((dimensions.height === 0 && dimensions.width === 0) || dom.Dimension.equals(this._containerClientArea, dimensions)) { |
| }); | ||
| } | ||
|
|
||
| private _containerClientArea: dom.Dimension | null = null; |
There was a problem hiding this comment.
The field _containerClientArea is not cleaned up in the dispose() method. While not strictly required for primitive values, for consistency with the class's disposal pattern and to allow potential garbage collection, consider setting it to null in the dispose() method.
Fixes #274455