ractivejs / ractive

Next-generation DOM manipulation
http://ractive.js.org
MIT License
5.94k stars 396 forks source link

node.setAttribute() calls before node._ractive is set #3272

Closed paulie4 closed 6 years ago

paulie4 commented 6 years ago

Description:

When Element.statics were added, there were some new calls to node.setAttribute() added BEFORE defineProperty(node, '_ractive', ...) was called. This is breaking our attributeChangedCallback() handler, since the handler tries to call Ractive.getContext(this) to get the parent Ractive, which is now failing.

Unless there's a good reason for it to be before the defineProperty(node, '_ractive', ...) call, the fix should be as easy as moving the following block of code to be after the defineProperty(node, '_ractive', ...) call (see src/view/items/Element.js):

    if (this.statics) {
      keys(this.statics).forEach(k => {
        node.setAttribute(k, this.statics[k]);
      });
    }

Versions affected:

Everything after this commit: special case handling for plain text attributes

Platforms affected:

Google Chrome and any other browser if a custom element polyfill is used

Reproduction:

playground example

evs-chris commented 6 years ago

Sorry it took a bit, but this will be fixed when the next round of releases are cut. Thanks for the report!