Closed arvgta closed 3 years ago
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.
Now seems to work!
Just for the sake of completeness - this approach has been discarded in the course of some testing...
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