RESOLVED WORKSFORME198665
Race condition makes ESM modules to evaluate twice
https://bugs.webkit.org/show_bug.cgi?id=198665
Summary Race condition makes ESM modules to evaluate twice
Manu Mtz-Almeida
Reported 2019-06-07 10:11:38 PDT
Created attachment 371592 [details] Repo case Looks like there is a race condition when loading ESM modules in Safari, that leads the same module. When using dynamic import(), the same ES module is evaludated more than once. Here's the simplest repo case that reproduces it: https://github.com/manucorporat/webkit-esm-bug - Server the repo with a HTTP server - Open the Safari dev tools, - Reload several times until you can see several "load" console logs HTML ``` <body> <script type="module"> import "/build/index.js"; </script> </body> ``` index.js ``` let a = 0; console.log('load', a++); function hello() { import('./chunk.js') } hello(); ``` chunk.js ``` import "./index.js"; ``` EXPECTED BEHAVIOUR: Same as Chrome, or Firefox. The `index.js` module should be evaluated only once. This is causing crashes in a production website: https://stenciljs.com/ And most likely any users of Stenciljs in iOS
Attachments
Repo case (20.80 KB, application/zip)
2019-06-07 10:11 PDT, Manu Mtz-Almeida
no flags
Radar WebKit Bug Importer
Comment 1 2019-06-07 13:30:17 PDT
Manu Mtz-Almeida
Comment 2 2019-06-07 14:42:13 PDT
After some extra debugging I found it's also related with some external extension slowing down the page: https://itunes.apple.com/es/app/adguard-for-safari/id1440147259?l=en&mt=12 In any case, seems like there is a race condition that leads to the same ESM module being loaded twice, breaking some websites.
Fabian
Comment 3 2022-02-03 02:19:28 PST
I am wondering if this issue breaks using stencil js applications in Safari. They work fine after a reload. I have posted a reference to this issue in the issue board: https://github.com/ionic-team/stencil/issues/2774#issuecomment-1028829579 Any help is appreciated!
Yusuke Suzuki
Comment 4 2022-02-03 02:23:55 PST
Hmm, I tried it but I cannot reproduce this issue.
Yusuke Suzuki
Comment 5 2022-02-03 02:29:28 PST
Hmm, yeah, I tried many times with the offered repro case, but so far, I cannot reproduce it. Is it possible that this is related to installed extensions? Can you reproduce it without enabling extensions?
Fabian
Comment 6 2022-02-03 02:32:53 PST
Same for me, I cannot reproduce in Safar 15.3 (17612.4.9.1.5) (Monterey 12.2)
Yusuke Suzuki
Comment 7 2022-02-03 15:33:30 PST
OK, closing this since I cannot reproduce this. I wonder if it is related to the installed extensions. Please feel free to paste a new repro case etc. if you find :)
Note You need to log in before you can comment on or make changes to this bug.