Skip to content

Commit

Permalink
fix(ui/lifecycle): keep root element during destroy (#810)
Browse files Browse the repository at this point in the history
  • Loading branch information
syfxlin committed Apr 2, 2024
1 parent b60cb58 commit de5e1b4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
4 changes: 3 additions & 1 deletion ui/artalk/src/artalk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ export default class Artalk {
/** Destroy instance of Artalk */
public destroy() {
this.ctx.trigger('unmounted')
this.ctx.$root.remove()
while (this.ctx.$root.firstChild) {
this.ctx.$root.removeChild(this.ctx.$root.firstChild)
}
}

/** Add an event listener */
Expand Down
7 changes: 2 additions & 5 deletions ui/artalk/tests/ui-api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,7 @@ describe('Artalk instance', () => {
artalk.destroy()

// detect if it is cleaned up
const selectors = [`#${ContainerID}`, '.atk-layer-wrap']
selectors.forEach(selector => {
const el = document.querySelector(selector)
expect(el).toBe(null)
})
expect(document.querySelector(`#${ContainerID}`)?.firstChild).toBe(null)
expect(document.querySelector('.atk-layer-wrap')).toBe(null)
})
})

0 comments on commit de5e1b4

Please sign in to comment.