-
-
Notifications
You must be signed in to change notification settings - Fork 515
webpack-typescript: DOMContentLoaded triggered twice #564
Comments
Odd. I'll add it to my ToDo list. |
Thanks for looking into it. |
This shouldn't be happening in the 1.0.0 anymore. |
I've just tried this with Aurelia 1.0 but an old skeleton. The problem is still there. |
Doesn't happen with the 1.0.0 skeleton. 👍 btw. it would be nice if |
Unfortunately it still is an issue in my opinion, but maybe @Thanood has a different approach. |
@JoschaMetze what do you mean by saying:
@Thanood |
Sorry for not stating that more clearly, I meant that the DOMContentLoaded event isn't triggered twice (as was the original implementation from @Thanood, see the last line of his log), so the bug is resolved for the DOMContentLoaded event. But unfortunately not for the document.ready()-event which is used quite regularly in materialize-css. |
document.ready cannot fire twice, so instead my guess is that the code is imported twice in your case, and thus the handler is executed twice. This can be caused by materialize-css being listed in the entry point and then being required again in some package, causing the handler to be set twice. Generally, import side effects are not recommended (with ES2015 modules startup should always be explicit, e.g. wrapped in a function), so this also seems like a bug in the way materialize-css initializes itself. |
I will have to try this but when this is true:
then @JoschaMetze did you try with dropdown? Because there is a known issue about dropdown options since the recent Materialize release 0.97.7: Dogfalo/materialize#3417 (comment) regarding tsconfig: sorry for being off-topic. I'll check if this is a bug in |
Well, actually it "fires" twice (the SO post has a different context), since it behaves like a promise - and that is because it uses a deferred. That doesn't change much, though. So I suppose either you have two Let's continue trying to find a solution here: Thanks.. 😄 |
It's a deferred, but the passed in method should only fire once if it was set only once. |
I may be wrong... $( document ).ready(function() { console.log('document.ready 1'); });
$( document ).ready(function() { console.log('document.ready 2'); }); |
@Thanood does it still log anything when you remove this line: https://github.com/Thanood/webpack-domready-issue/blob/master/skeleton-typescript-webpack/src/main.ts#L4 ? |
Of course not and it certainly is not a good way of doing this (in a module env), but it simulates how materialize works. There may be other libraries, afaik even Bootstrap attaches event handlers that way. But that's not the point, really. I just wanted to show (or more verify) that Let me make this clear: Listening to I think you are right. Either the library is imported twice or @JoschaMetze is running into that dropdown issue. At least that is the current state of this problem. If I'm wrong and there is another issue with Aurelia/webpack, I'll report back. But for now I suppose it's related to imports or Materialize bugs. |
Hi,
one of our users found a problem with the
document.ready
event triggered a second time and after some components have been attached. See the issue here for full context and console logs: aurelia-ui-toolkits/aurelia-materialize-bridge#200In the above mentioned issue, we're using Materialize which initializes itself on
$(document).ready()
or theDOMContentLoaded
event. Because this is triggered twice, Materialize is initialized twice which leads to a couple of problems with its controls.This only happens with the webpack skeleton. If you do the same in a "non-webpack" skeleton it behaves like expected. The DOMContentLoaded event is fired only once.
I've uploaded a reproduction here: https://github.com/Thanood/webpack-domready-issue
There are two skeletons in that repo: typescript and typescript-webpack. Both contain the same modifications:
attached()
handler, logging to the consoleThis is the log that's being generated when using the webpack version:
With the non-webpack version the last line
document.ready import
is missing, as expected. 😄Ping @JoschaMetze who found this.
The text was updated successfully, but these errors were encountered: