wasabee-project / Wasabee-IITC

ENL DrawTools and Op Management
Apache License 2.0
30 stars 21 forks source link

New zones are created with a name that is an integer instead of a string #373

Closed cody-somerville closed 1 year ago

cody-somerville commented 1 year ago

By default all new zones are created with a name that is an integer instead of a string.

  addZone() {
    const ids = new Set<number>();
    for (const z of this.zones) {
      ids.add(z.id);
    }
    const newid = Math.max(...ids) + 1;
    this.zones.push(new WasabeeZone({ id: newid, name: newid }));
    ...

Type persists across store/rehydration in indexeddb. If zone name is edited, will then correctly be a string.

This results in tooltip not displaying for zones until the name is modified. You get a traceback such as:

Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.
    at NewClass._updateContent (<anonymous>:12954:11)
    at NewClass.update (<anonymous>:12856:10)
    at NewClass._prepareOpen (<anonymous>:12936:11)
    at NewClass.openTooltip (<anonymous>:13778:40)
    at NewClass._openTooltip (<anonymous>:13829:10)
    at NewClass.fire (<anonymous>:3800:13)
    at NewClass._fireDOMEvent (<anonymous>:7606:17)
    at NewClass._fireEvent (<anonymous>:15791:15)
    at NewClass._handleMouseHover (<anonymous>:15777:12)
    at NewClass._onMouseMove (<anonymous>:15743:10)

This is due to an explicit branch on type in L.DivOverlay:

    _updateContent: function () {
        if (!this._content) { return; }

        var node = this._contentNode;
        var content = (typeof this._content === 'function') ? this._content(this._source || this) : this._content;

        if (typeof content === 'string') {
            node.innerHTML = content;
        } else {
            while (node.hasChildNodes()) {
                node.removeChild(node.firstChild);
            }
            node.appendChild(content);
        }
        ...

There may be other consequences / bugs as well. Filing this issue to track and to raise awareness.

le-jeu commented 1 year ago

Thank you for diving into the code to spot the origin of the bug. Would you like to fix this one into a future PR ?

le-jeu commented 1 year ago

fixed by ca609ea0884a055f6262d67c5f985246f0228e15