Skip to content

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

@axelcostaspena

Description

@axelcostaspena

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions