-
-
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
fix: ensure dynamic event handlers are wrapped in a derived #12563
Conversation
🦋 Changeset detectedLatest commit: cb728f0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
We probably only want to do this if there's a |
i.e. here... <script>
let count = $state(0);
const handlers = {
increment: () => count += 1
};
</script>
<button onclick={handlers.increment}>
clicks: {count}
</button> var button = root();
-var event_handler = $.derived(() => handlers.increment);
button.__click = function (...$$args) {
- return $.get(event_handler)?.apply(this, $$args);
+ return handlers.increment?.apply(this, $$args);
}; |
Ah yeah, I don't need that other change anymore. Good spot! |
We're still creating a derived for conditional/logical expressions, which we don't do in other scenarios. Worth avoiding? |
@Rich-Harris I can split it out so we only create dynamic deriveds for call expressions, but we still need to keep dynamic handlers. I guess we would also need to be more thorough as the conditional could contain a call expression. |
We have a mechanism for this that we use everywhere else we face the same problem — |
That's what I tried originally, unfortunately, it doesn't seem like it's available? It's not on the |
Ah figured it out! |
Addresses the issue mentioned in #12519 that is for Svelte 5. Fixes #12520.