-
-
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
window.addEventListener overwritten by on: directive, :Window not working correctly #621
Comments
Oh, ha, that's interesting. It took me a bit to put this together. So the What I would suggest is to just use the |
@Conduitry is spot on — it's the I wonder if we should rename those helpers. On the one hand, it would prevent errors like this. On the other, it would make it harder to detect errors like this... |
Yeah, compiling as an iife solves the issue. Personally, I would prefer renaming the helpers, both to avoid overriding the global ones and to avoid confusion, but that's just my two cents :-) |
So I had this issue too with Electron, which internally uses some of these global functions. IIFE does solve the issue, but I feel like we should solve it within Svelte too. Maybe we could define addEventListener/removeEventListener as already used identifiers? |
This is not the first and not the last time this issue rises. |
rename addEventListener and removeEventListener
As of 1.22.3, the helpers are called |
with addListener or addEventListener => still crashes with same error :/ |
@blurymind I'm not sure why you'd still be seeing this issue - Can you give more details about how we can reproduce it? |
Hi, I came across the following situation:
I used a
<:Window />
component to listen to some events like this:Svelte generates the following code for the above:
This worked perfectly, until somewhere else in my application (in a different component) I added the following code:
This resulted in error in the (previously working)
:Window
component:The
on:
directive here resulted in the compiler adding the following javascript to the output. Both functions overwrite the default functions on the window object.The code generated from the
:Window
component calls addEventListeren with a string as first argument, hence the ...is not a function error.Is this a bug in the
:Window
component or am I doing something wrong here? I'm using svelte 1.22.1 with rollup (es format).The text was updated successfully, but these errors were encountered: