@@ -5,8 +5,10 @@ import State from "../core/State.js";
55import { container } from "../core/Container.js" ;
66import {
77 cleanupDisconnectedComponents ,
8+ destroyNodeDeep ,
89 getOjsChildren ,
910} from "../utils/helpers.js" ;
11+ import DOM from "../utils/DOM.js" ;
1012
1113/**
1214 * Base Component Class
@@ -145,7 +147,7 @@ export default class Component {
145147 getDeclaredListeners ( ) {
146148 if ( this . __ojsRegistered ) {
147149 console . warn (
148- `Component "component:${ this . id } " is already registered. Skipping duplicate registration.`
150+ `Component "component:${ this . id } " is already registered. Skipping duplicate registration.` ,
149151 ) ;
150152 return ;
151153 }
@@ -200,12 +202,22 @@ export default class Component {
200202 * Deletes all the component's markup from the DOM
201203 */
202204 unmount ( ) {
205+
206+ /**
207+ * Clean up the dom based on the developer's logic.
208+ */
209+ this . cleanUp ( ) ;
210+
211+ /**
212+ * @var {NodeList<HTMLElement>} all
213+ */
203214 let all = this . markup ( ) ;
204215
205216 for ( let elem of all ) {
217+ destroyNodeDeep ( elem ) ;
206218 elem . remove ( ) ;
207219 }
208-
220+
209221 this . releaseMemory ( ) ;
210222 this . unmounted = true ;
211223
@@ -249,7 +261,7 @@ export default class Component {
249261 if ( ! parent ) parent = h . dom ;
250262
251263 return parent . querySelectorAll (
252- `ojs-${ this . kebab ( this . name ) } [uid="${ this . id } "]`
264+ `ojs-${ this . kebab ( this . name ) } [uid="${ this . id } "]` ,
253265 ) ;
254266 }
255267
@@ -272,7 +284,6 @@ export default class Component {
272284 releaseMemory ( ) {
273285 container . resolve ( "repository" ) . removeComponent ( this . id ) ;
274286 container . resolve ( "repository" ) . removeComponentArgs ( this . id ) ;
275- this . cleanUp ( ) ;
276287
277288 this . emitter . clear ( ) ;
278289
@@ -403,7 +414,7 @@ export default class Component {
403414 h . dom . querySelectorAll (
404415 `ojs-${ this . kebab ( this . name ) } [uid="${
405416 this . id
406- } "][s-${ stateId } ="${ stateId } "]`
417+ } "][s-${ stateId } ="${ stateId } "]`,
407418 ) ?? [ ] ;
408419
409420 current . forEach ( ( e ) => {
@@ -491,7 +502,7 @@ export default class Component {
491502 const rendered = h [ `ojs-${ this . kebab ( this . name ) } ` ] (
492503 attr ,
493504 markup ,
494- cAttributes
505+ cAttributes ,
495506 ) ;
496507
497508 if ( reconcileParent && parent ) {
0 commit comments