Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
axelcostaspena opened this issue Aug 6, 2024 · 0 comments

Comments

@axelcostaspena
Copy link

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

  • Have class without public property .el, and register it:
class MyComponent {
    #htmlElement;

    constructor(el) {
        this.#htmlElement = el;
    }
}

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 ()
at destroy.js:17:27
at Array.forEach ()
at destroy.js:15:22

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant