Skip to content

Commit 4ef1470

Browse files
fix: resolve AIWidget canvas trashing and DOM leaks on resize (#6663)
1 parent 09f0f4d commit 4ef1470

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

js/widgets/aiwidget.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,19 +1050,22 @@ function AIWidget() {
10501050
*/
10511051
this._scale = function () {
10521052
let width, height;
1053-
const canvas = document.getElementsByClassName("samplerCanvas");
10541053
const body = this.widgetWindow.getWidgetBody();
1055-
for (let i = canvas.length - 1; i >= 0; i--) {
1056-
body.removeChild(canvas[i]);
1054+
1055+
// Properly remove the entire previous interface container to avoid leaks
1056+
const containers = body.getElementsByClassName("ai-interface-container");
1057+
for (let i = containers.length - 1; i >= 0; i--) {
1058+
body.removeChild(containers[i]);
10571059
}
1060+
10581061
if (!this.widgetWindow.isMaximized()) {
10591062
width = SAMPLEWIDTH;
10601063
height = SAMPLEHEIGHT;
10611064
} else {
10621065
width = this.widgetWindow.getWidgetBody().getBoundingClientRect().width;
10631066
height = this.widgetWindow.getWidgetFrame().getBoundingClientRect().height - 70;
10641067
}
1065-
document.getElementsByTagName("canvas")[0].innerHTML = "";
1068+
10661069
this.makeCanvas(width, height, 0, true);
10671070
this.reconnectSynthsToAnalyser();
10681071
};
@@ -1081,6 +1084,7 @@ function AIWidget() {
10811084

10821085
// Create a container to center the elements
10831086
const container = document.createElement("div");
1087+
container.className = "ai-interface-container";
10841088
fragment.appendChild(container);
10851089

10861090
// Create a scrollable container for the textarea

0 commit comments

Comments
 (0)