-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
tests: event-handler-dynamic: add no-op handler #4088
Conversation
Fix exceptions thrown by test.
I think this is hiding a bug, although perhaps just one in jsdom. If a null/falsy event handler is attached to an element, is the intent that triggering the event have no effect @tanhauhau ? It looks like that's what's happening, and it's only jsdom that doesn't like that. |
Well, it errors on this part of Svelte generated code:
The linters for VSCode don't pick up the possible undefined variable reference since it does get set to something in a function. I mean we're not gcc-level AST verifying here. I guess we could make the case for outputting something like this:
Here's a repl to play around with: |
Minimal reproduction case for the exception: Going back to 3.12.1, it also does what you'd expect even with the I believe this is the bug you're worried it will mask. |
Thinking about this on the way home, this can still be merged since the real focus of the test case is the dynamic handler assignment. I'll make another failing test case for the falsey handler when i come up with a patch for it. |
I agree with @Conduitry that this is masking the actual bug. When the event handler is dynamic, instead of listen/unlisten to new event handler every time whenever it has changed, we listen to a static proxy event handler that will call the actual dynamic event handler. i think i missed out the case where dynamic handler could be and this may pose another issue that I just thought of, what if the dynamic event handler uses event modifier like <script>
let dynamicClick;
function divClick() {
console.log('div clicked')
}
</script>
<div on:click={divClick}>
<button on:click|stopPropagation={dynamicClick}>
dynamic button
</button>
</div> |
Yes I reached the same conclusion; however, a test case should only test one thing. In this test we are making sure assignment works correctly. I've opened an issue for underlying bug, but we need another for modifiers as you said. I feel like fixing the other situations is going to take a bit of time. It would be nice to clear the logs of these exceptions for now so that we aren't distracted by known issues. |
Closing in favor of a real fix to the root cause. |
Fixes #4087