-
Notifications
You must be signed in to change notification settings - Fork 405
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
event listener does not update when the variable used in template with onevent is updated #5014
Comments
This is a limitation of the current LWC template compiler. One workaround is that you can use an object with a property rather than a plain function: <template>
<button onclick={handler.onClick}></button>
</template> export default class extends LightningElement {
handler = {
onClick: () => { console.log('foo') }
}
connectedCallback() {
this.handler.onClick = () => { console.log('bar') } // this will be used
}
} |
BTW the current behavior has some performance benefits, namely that we can bind/cache the event listener once rather than re-evaluating it. So fixing this may incur a performance cost. |
The example provided here works because the |
Description
when a field is used in template as event handler and later assigned a new value , old value is still used to handle the event.
Steps to Reproduce
https://stackblitz.com/edit/salesforce-lwc-davchu?file=src%2Fmodules%2Fx%2Fcounter%2Fcounter.js
Expected Results
New value of
mainHandler
must be calledActual Results
Old value of
mainHandler
is calledBrowsers Affected
tested in Chrome : Version 131.0.6778.87 (Official Build) (arm64),
probably in all
Version
Possible Solution
Additional context/Screenshots
Add any other context about the problem here. If applicable, add screenshots to help explain.
The text was updated successfully, but these errors were encountered: