lit-element icon indicating copy to clipboard operation
lit-element copied to clipboard

Property value incorrectly if using both of static properties() and @property decorator

Open gogermany opened this issue 5 years ago • 2 comments

Description

Lit-Element handle properties value incorrectly if using both of static properties() and @property decorator for create element extends from abstract class.

I think this problem is related with

  • abstract class no need to use @customElement
  • use static properties() in abstract class
  • use @property in child class

Live Demo

https://stackblitz.com/edit/lit-element-properties-problem?file=my-element.ts

Steps to Reproduce by using TypeScript

  1. Create abstract class BaseElement
// not define element @customElement because this is abstract class
abstract class BaseElement extends LitElement {

  public foo = false;
  
  // (I don't use  @property because I have to import properties from share properties)
  static get properties() {
    return { 
      foo: { type: Boolean, reflect: true }
    };
  }

  render(){
    return html`<p>${this.foo}</p>`;
  }
}

  1. Create MyElement
@customElement('my-element')
export class MyElement extends BaseElement {
  /**
   * Create new property with @property
   * Using this make a problem with static properties().
   * Remove this property and reload by click refresh button to get correct value
   */
  @property() bar = 'bar';
}
  1. Use element and set foo attribute is true
<my-element foo></my-element>

Expected Results

foo property value and element render should be true

Actual Results

foo property value and element render is false

Browsers Affected

  • [x] Chrome
  • [x] Firefox
  • [x] Edge
  • [x] Safari 13
  • [x] IE 11

Versions

  • lit-element: v2.2.1
  • webcomponents: v2.4.1

gogermany avatar Feb 04 '20 09:02 gogermany

+1

gregorymachon avatar Feb 06 '20 10:02 gregorymachon

Status: This has been fixed in the lit-next branch, but is still an open bug on master (lit-element 2.x).

kevinpschaaf avatar Dec 02 '20 00:12 kevinpschaaf