Netcentric / component-loader

Apache License 2.0
1 stars 1 forks source link

Destroying instances throws runtime error if they don't expose `.el` #7

Open axelcostaspena opened 2 months ago

axelcostaspena commented 2 months ago

Expected Behaviour

All features of NC component loader can be used with any component class if the class provides a constructor. OR If the classes registered to the component loader should meet any public interface, that requirement would be documented.

Actual Behaviour

If an observed instance is destroyed, and the component class doesn't expose the HTMLElement as .el, a runtime error throws: image image

Reproduce Scenario (including but not limited to)

Steps to Reproduce

register({ MyComponent });


* observe() some part of the DOM
* insert an HTML element with data-nc='MyComponent' inside the observed 
* remove the MyComponent HTML element from the DOM

#### Platform and Version
Reproduced in Chrome 126.
NC component loader 0.2.6 (validated it also happens with v1).

#### Sample Code that illustrates the problem
https://jsfiddle.net/tg3cLar2/

#### Logs taken while reproducing problem
Uncaught TypeError: Cannot read properties of undefined (reading 'uuid')
    at destroy.js:18:43
    at Array.forEach (<anonymous>)
    at destroy.js:17:27
    at Array.forEach (<anonymous>)
    at destroy.js:15:22