Join GitHub today
Modules executing in reverse post-order #6261
Module execution of ES modules is based on post-order execution up the graph (with circular deduping).
The Edge behaviour is incorrectly implementing a reverse post-order execution.
The simple example of this is the following:
<script>order=</script> <script type="module"> import '/a.js'; import '/b.js'; console.log(order); </script>
where edge will execute
The fix should be simple (one loop can just be reversed somewhere), but this is a really important bug to fix as many projects will write code like the following:
import 'polyfill'; import 'stuff-that-needs-polyfill';
and without these guaranatees those code paths break down.
I would highly recommend marking this as an urgent priority.
The scenario here might be a little more complex actually. For example, the following code executes dependencies in indeterminate order:
when the ordering always should be
On the other hand, the following always executes in the correct order:
It seems to me like request timings or otherwise are possibly being allowed to affect execution order.
@fatcerberus yes there is.
@guybedford the module load order was wrong in versions 1.8 and 1.9 of CC it should have been fixed for 1.10 by this PR of mine and I believe that the most recent version of Edge should be using 1.10 or even 1.11 #5238
The issue with indeterminate order sounds to me like a problem with Edge not CC based on my knowledge of the CC code base but as an external contributor to CC I’ve not seen any of the Edge code so can’t say for sure.
Taking another look at this - I'm wrong above. CC module load order remains wrong in the latest version. I fixed one error with my previous PR (execution of the list of modules backwards) but there were two errors.
The list of child modules is being stored internally in an internal data structure type called a BaseDictionary - which uses Key, Value pairs and is sorted based on the keys - in this case the specifiers, so execution order is dependent on the specifier - the test case I added before had conveniently alphabetical module names so appeared to work.
I've opened a PR that should fix this remaining issue. I'm sorry that I was wrong above.