Skip to content

Attrs initialization without @attr decorator #207

Open
@kristoforsalmin

Description

@kristoforsalmin

Hi there 😄

After upgrading from v1.1.4 to v1.3.2, I noticed that my attributes were no longer shadowed by initializeAttrs(). I started digging and stumbled upon this piece of logic introduced in #191:

if (initialized.has(instance)) return

It prevents initializeAttrs() from doing anything the second time around, thus skipping the manual initialization of attributes. Also, it seems like this change was one of the main things addressed by the above-mentioned PR.

So, what would be the correct way now to initialize the attributes without the @attr decorator?

Thanks!


Example

<script>
  class InfoMessage extends HTMLElement {
    open = true

    connectedCallback() {
      initializeAttrs(this, ['open'])
    }
  }

  controller(InfoMessage)
</script>

<info-message data-open="false"></info-message>
  1. controller(InfoMessage) wraps original connectedCallback() and calls:

initializeAttrs(instance)

  1. InfoMessage is marked as initialized (attrs.ts):

initialized.add(instance)

  1. The original connectedCallback() is executed, but initializeAttrs() would hit that early-return condition.
  2. this.open is stuck in its default state (true) 😔

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions