-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Svelte 5: Higher order dynamic event handlers are not reactive #12520
Comments
Note that Rich is also working on a related PR (#12553). |
Sorry to be a pain, but this breaks: <script>
let saySomething = $state(name => {
console.log('creating "Hello" handler for ' + name);
return { handler: () => alert('Hello ' + name) };
});
function change() {
saySomething = name => {
console.log('creating "Bye" handler for ' + name);
return { handler: () => alert('Bye ' + name) };
}
}
</script>
<button onclick={saySomething('Tama').handler}>Tama</button>
<button onclick={saySomething('Pochi').handler}>Pochi</button>
<br>
<button onclick={change}>Change Function</button>
<pre>{saySomething.toString()}</pre> I suspect there needs to be a more general expression resolution that can handle any combination of function calls and property accesses. |
Was this in relation to my PR or this PR? |
It apparently has been broken before the last PR, just did not test this particular scenario until the other issue was resolved. |
So this PR broke this use-case? |
Thanks. That makes sense now. |
@trueadm Just one more thing... |
Describe the bug
Changing an event handler function does not always work as expected when the handler is provided by a higher order function (in terms of the function returning another function).
Noticed this when looking into an issue around dynamic handlers with Svelte 3/4 that does not happen in Svelte 5.
Reproduction
REPL
Dynamic handlers that are not higher order work.
Wrapping the button makes this work (with spread and without).
Longer reproduction to help guard against reintroducing #12519 - the log statements should only happen on handler change:
REPL
Logs
No response
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: