You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
EDIT: Not necessary to adopt this approach because there were no timing problems after all...
**Old code:**
letiFn=function(a,b,c=false){if((this===document||this===window)&&a=="DOMContentLoaded")setTimeout(b);elsethis.ael(a,b,c);};// if "DOMContentLoaded" - execute function, else - add event listenerEventTarget.prototype.ael=EventTarget.prototype.addEventListener;// store original methodEventTarget.prototype.addEventListener=iFn;// start intercepting event listener addition
...works fine but can cause timing issues because of the setTimeout(b) bit, that executes the handler on the fly, instead of waiting for the DOMContentLoaded event itself.
Therefore, I have attempted to replace the setTimeout(b) bit with a snippet, that attempts to inject:
once: true
into all calls of addEventListener with type DOMContentLoaded.
In this new scenario, the DOMContentLoaded event is fired programmatically by Ajaxify itself beforehand.
New code: (in this file, which is active in the testcase below)
The bug was identified: the firing of the event was happening before the registration of the handler had finished.
Solved by adding a setTimeout() with minimal delay (0 milliseconds) to the firing of the event.
EDIT: Not necessary to adopt this approach because there were no timing problems after all...
**Old code:**
...works fine but can cause timing issues because of the
setTimeout(b)
bit, that executes the handler on the fly, instead of waiting for theDOMContentLoaded
event itself.Therefore, I have attempted to replace the
setTimeout(b)
bit with a snippet, that attempts to inject:once: true
into all calls of
addEventListener
with typeDOMContentLoaded
.In this new scenario, the
DOMContentLoaded
event is fired programmatically by Ajaxify itself beforehand.New code: (in this file, which is active in the testcase below)
...which works fine, but for some reason, the pass right after initial load does not work - as can be seen here at the moment:
and
(The
DOMContentLoaded
event is fired successfully, but the handler is not called in that case only)How to reproduce the bug in more detail:
DCL triggered
" followed by "Ajaxify loaded...
" (as expected on initial load - no problem)DCL triggered
" is not shown in the console (not as expected)DCL triggered
" is shown in the console (as expected)So the bug is on step 4) above
Please note also:
DOMContentLoaded
works as expected - also on step 4) aboveDCL triggered
" indicates, when the respective handler function was executed, not the firing of the event(Link for my own purposes: ) Erase any salient handlers
The text was updated successfully, but these errors were encountered: