Skip to content

Commit

Permalink
Fix internal cleanup in core (#466)
Browse files Browse the repository at this point in the history
* check if destroy exists before invoking

* rm logs

* add changeset
  • Loading branch information
edolix authored Mar 21, 2022
1 parent a803638 commit 1944348
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/seven-zebras-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@signalwire/core': patch
---

[internal] Fix to avoid issues when invoking `.destroy` on cleanup.
11 changes: 10 additions & 1 deletion packages/core/src/BaseComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,16 @@ export class BaseComponent<
const eventCount = this.listenerCount(internalEvent)

if (instance && (force || eventCount <= 1)) {
instance.destroy()
/**
* Make sure to not invoke destroy on "self"
* and that `instance.destroy` is defined.
*/
if (
instance.__uuid !== this.__uuid &&
typeof instance.destroy === 'function'
) {
instance.destroy()
}
return this._eventsTransformsCache.delete(internalEvent)
}

Expand Down

0 comments on commit 1944348

Please sign in to comment.