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
To account for event handlers changing at runtime, handlers that come from props or variables that are reassigned are not used directly as event handlers. Instead, their invocation is wrapped in a new function, which can be wrong if a function call is used to get the handler. See:
(Not sure if something can/should be done about this at this point, it primarily would be good, if the problem is not re-introduced in Svelte 5.)
Reproduction
<script>
let makeHandler =null; // could also come from a propmakeHandler= () => {console.log('Creating handler');return () =>alert('hello'); };
</script>
<buttonon:click={makeHandler()}>Click</button>
Describe the bug
To account for event handlers changing at runtime, handlers that come from props or variables that are reassigned are not used directly as event handlers. Instead, their invocation is wrapped in a new function, which can be wrong if a function call is used to get the handler. See:
(Not sure if something can/should be done about this at this point, it primarily would be good, if the problem is not re-introduced in Svelte 5.)
Reproduction
REPL
"Creating handler" should only be logged once, but the function is executed on every click.
Logs
No response
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: