Giter Site home page Giter Site logo

Comments (6)

WebReflection avatar WebReflection commented on May 23, 2024

which browser does that? there are at least 3 internal branches for attributes changes, I need to know where I can reproduce this. Thank you.

from document-register-element.

dmarcos avatar dmarcos commented on May 23, 2024

The native implementation of document.registerElement in Chrome latest version (47.0.2526.73 (64-bit)) doesn't call attributeChangedCallback if the attribute value doesn't change. Below a screenshot of my console after adding a console.log in the attributeChangedCallback method of my custom element: SetAttribute Log Screenshot
It makes sense to me that attributeChangedCallback is not called when the attribute doesn't change but I could not find what's the expected behavior anywhere in the spec: http://www.w3.org/TR/custom-elements/

from document-register-element.

dmarcos avatar dmarcos commented on May 23, 2024

In Firefox Latest Version that doesn't have a document.registerElement native implementation the polyfilll always calls attributeChangedCallback regardless if the attribute value has changed or not. This is the branch that is called:
https://github.com/WebReflection/document-register-element/blob/master/src/document-register-element.js#L542

from document-register-element.

WebReflection avatar WebReflection commented on May 23, 2024

That's the unclear bit to me. AFAIK MutationObserver also calls it more than once (can you please test your code in Safari?) and if specs are not clear, I don't want to blindly follow Chrome.

  • why are you reassigning the same attribute over and over?
  • what if you pass a boolean or number, would a comparison after casting to string work as well or if you have el.getAttribute('num') === "123" and you el.setAttribute('num', 123) it should trigger?
  • what does Chrome do in the latter case?

Thanks for your collaboration. FWIW I agree that triggering a change twice doesn't male much sense but I also belive is there for a reason: either Chrome was acting like that earlier and I wrongly took it as reference, or MutationObserver and DOMAttrModified were doing weird things and it has been normalized like that.

from document-register-element.

WebReflection avatar WebReflection commented on May 23, 2024

OK, you know what? I've fixed it for all browsers. There's no coercion check though, just remember that attributes are also strings ;-)

Version 0.5.2 fixed this.

from document-register-element.

dmarcos avatar dmarcos commented on May 23, 2024

Thanks. I think it's a good decision. I checked the document.registerElement native implementation in Firefox that is hidden behind a flag (dom.webcomponents.enabled) and it matches the Chrome behavior: attributeChangedCallback is not called if the attribute value doesn't change.

from document-register-element.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.