canjs / can-zone

A context for tracking asynchronous activity in JavaScript applications.
https://v4.canjs.com/doc/can-zone.html
MIT License
92 stars 4 forks source link

can-zone can not handle addEventListener #104

Closed pYr0x closed 7 years ago

pYr0x commented 7 years ago

there is a problem with done-autorender. the problem seems to be in steal-css where we using addEventListener to know when the css is injected. https://github.com/stealjs/steal-css/blob/master/css.js#L110-L112

matthewp commented 7 years ago

What should can-zone do with addEventListener? Wait for the event to occur?

justinbmeyer commented 7 years ago

Not generically. Perhaps some plugins can set this up, but hard to know which specific events should be waited on, and which shouldn't.

pYr0x commented 7 years ago

i dont know what we can do. if you remove the addEventListener on the steal-css plugin and use the polling onloadCss can-zone will not fail.

maybe register event listener through a proxy on can-zone

matthewp commented 7 years ago

I don't understand what you mean when you say can-zone will fail? Do you mean it will throw an error?

pYr0x commented 7 years ago

no, it will not resolve. while debugging, javascript will never reached this line https://github.com/donejs/autorender/blob/master/src/template.txt#L136 or that line https://github.com/donejs/autorender/blob/master/src/template.txt#L102

matthewp commented 7 years ago

Looked more into this. What's happening is that a setTimeout is created and then later gets cleared. Because clearTimeout is inside of the event handler, it is not deducted from the Zone's counter.

The fix is to make sure that event handlers are run within the Zone. It won't increment the counter, but it will just make sure that it is Zone wrapped. We do this already for MutationObserver. https://github.com/canjs/can-zone/blob/master/lib/tasks.js#L182

pYr0x commented 7 years ago

but that mean, that steal-css will depend on can-zone?

how can we wrap addEventListener ?

matthewp commented 7 years ago

steal-css doesn't depend on can-zone, done-autorender does. I'm working on a fix for this.

matthewp commented 7 years ago

This is fixed in can-zone 0.6.3, tested your app and its working now @pYr0x