Skip to content

Commit

Permalink
fix: [#1527] Fixes problem where it is not possible to observe again …
Browse files Browse the repository at this point in the history
…after disconnecting in MutationObserver (#1525)
  • Loading branch information
capricorn86 authored Aug 31, 2024
1 parent 07a424a commit 20b520a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 8 additions & 2 deletions packages/happy-dom/src/mutation-observer/MutationObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ export default class MutationObserver {
* Disconnects.
*/
public disconnect(): void {
this.#destroyed = true;

if (this.#listeners.length === 0) {
return;
}
Expand Down Expand Up @@ -166,4 +164,12 @@ export default class MutationObserver {
}
return records;
}

/**
*
*/
public [PropertySymbol.destroy](): void {
this.#destroyed = true;
this.disconnect();
}
}
4 changes: 3 additions & 1 deletion packages/happy-dom/src/window/BrowserWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1462,7 +1462,9 @@ export default class BrowserWindow extends EventTarget implements INodeJSGlobal
const mutationObservers = this[PropertySymbol.mutationObservers];

for (const mutationObserver of mutationObservers) {
mutationObserver.disconnect();
if (mutationObserver[PropertySymbol.destroy]) {
mutationObserver[PropertySymbol.destroy]();
}
}

this[PropertySymbol.mutationObservers] = [];
Expand Down

0 comments on commit 20b520a

Please sign in to comment.