This is caused by a bug in jQuery.Callbacks:
> cb = $.Callbacks() > cb.add(function () { console.log('one'); cb.add( function () { console.log('two' ); } ); } ); > cb.fire() one two
What happens is:
- execute() is called for module A
- This calls addEmbeddedCSS( cssA, cbA ) where cssA is the CSS for module A, and cbA is a callback that is added to the CSS callback list
- From a timeout, addEmbeddedCSS() flushes its buffer and fires the callback list, so cbA is called
- cbA executes module A's JS
- cbA calls handlePending(), which notices that module B (which depends on A) is now runnable
- execute() is called for module B
- This calls addEmbeddedCSS( cssB, cbB ) , and adds cbB to the CSS callback list
- Once this stack rolls back up, we end up back in callbacks.fire(), which notices the newly added cbB callback and calls it immediately
- cbB executes modules B's JS
- From a timeout, addEmbeddedCSS() adds module B's CSS