You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm confused by the behaviour of properties managed by the @attr decorator during click listener callbacks. Setting one of these properties during the connectedCallback() is immediately reflected when calling the getter for it, but this is not the case in click listeners.
Here's my component definition:
import{controller,attr}from'@github/catalyst'
@controllerclassTestComponentElementextendsHTMLElement{
@attrtestProp: stringconnectedCallback(){this.innerHTML=`hello`this.setAttribute('data-action','click:test-component#wasClicked')console.log(this.testProp)// prints 'undefined' as expectedthis.testProp='A'console.log(this.testProp)// prints 'A' as expectedthis.testProp='B'console.log(this.testProp)// prints 'B' as expected}// this is called when clicking the elementwasClicked(_evt){console.log(this.testProp)// prints 'B' as expected (set to this at end of connectedCallback())this.testProp='C'console.log(this.testProp)// prints 'B' - not expectedthis.testProp='D'console.log(this.testProp)// prints 'B' - not expectedsetTimeout(()=>{console.log(this.testProp)// prints 'D'},0)}}exportdefaultTestComponentElement
Closed this issue because I think there's something weird with my setup. I now cannot reproduce it =\
Probably! Me and @keithamus looked at this and couldn't reproduce either. We added a test to validate in a874af9. Feel free to re-open with more info if you get it.
Thanks for the bug report, hopefully you get this sorted in your app!
I'm confused by the behaviour of properties managed by the
@attr
decorator during click listener callbacks. Setting one of these properties during theconnectedCallback()
is immediately reflected when calling the getter for it, but this is not the case in click listeners.Here's my component definition:
the html is like this:
I see here that the injected setter for the
@attr
decorator is async, and that it's notawait
ed hereRemoving that
async
and theawait Promise.resolve()
here makes this unexpected behaviour go away (but breaks a load of other stuff in a real project).Is this behaviour expected? Thanks
The text was updated successfully, but these errors were encountered: