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

[bug] Every skate element gains property getters/setters of all other skate element. #1560

Open
trusktr opened this issue Feb 28, 2019 · 3 comments

Comments

@trusktr
Copy link
Contributor

trusktr commented Feb 28, 2019

Bug report

Delete this section if this is a feature request.

  • Skate version: v5.2.4
  • Affected browsers (and versions): all

Current behaviour

After defining multiple classes with withUpdate, every instance of all classes will have the combination of all property getters/setters from every class in the application.

Expected behaviour

Each element instance should only have the property getters/setters of the props defined by it's class, not those of any other class.

more details

The reason this happens is because there's an _observedAttributes array on the WithUpdate class. This array is shared with all class constructor instances that inherit from WithUpdate.

The problem is similar to placing an array as a prototype property, and having all instances push/pop to/from it.

The solution is to create one array per constructor that inherits from WithUpdate. We can do that by placing the following line at the top of the static get observedAttributes getter:

    static get observedAttributes(): Array<string> {
      if (!('_observedAttributes' in this)) this._observedAttributes = [] // THIS LINE
      defineProps(this, WithUpdate);
      return this._observedAttributes.concat(super.observedAttributes || []);
    }

It causes a new array to be created per class instance, instead of using the shared array defined by static _observedAttributes = [];.

@trusktr
Copy link
Contributor Author

trusktr commented Mar 2, 2019

Uh oh, I just noticed that this applies with _attributeToAttributeMap and _attributeToPropertyMap too! Each new subclass will clobber other subclass definitions if they have the same attribute names.

It doesn't look like these problems exist in the latest master any more.

@trusktr
Copy link
Contributor Author

trusktr commented Mar 3, 2019

I found the skate-5.2.4 commit and made a branch with the same name so that I could make a PR with the fixes: #1561

@treshugart
Copy link
Member

It doesn't look like these problems exist in the latest master any more.

Can you confirm? If so can we close this?

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

No branches or pull requests

2 participants