Please note this question is about the yet-to-be-released Magento 2, which I'm still trying to get to grips with.
Each module contributes to each layout handle separately. For example, the
default handle is made up of these files:
app/code/Magento/Catalog/view/base/layout/default.xml app/code/Magento/Bundle/view/frontend/layout/default.xml app/code/Magento/CatalogSearch/view/frontend/layout/default.xml app/code/Magento/Catalog/view/frontend/layout/default.xml app/code/Magento/Checkout/view/frontend/layout/default.xml app/code/Magento/Cms/view/frontend/layout/default.xml app/code/Magento/Contact/view/frontend/layout/default.xml app/code/Magento/Customer/view/frontend/layout/default.xml app/code/Magento/Directory/view/frontend/layout/default.xml app/code/Magento/GoogleAnalytics/view/frontend/layout/default.xml app/code/Magento/Newsletter/view/frontend/layout/default.xml app/code/Magento/PageCache/view/frontend/layout/default.xml app/code/Magento/Reports/view/frontend/layout/default.xml app/code/Magento/Rss/view/frontend/layout/default.xml app/code/Magento/Sales/view/frontend/layout/default.xml app/code/Magento/Theme/view/frontend/layout/default.xml app/code/Magento/Weee/view/frontend/layout/default.xml app/code/Magento/Widget/view/frontend/layout/default.xml app/code/Magento/Wishlist/view/frontend/layout/default.xml
base files come first followed by
frontend files, followed by a number of themes. I would like to know which order those in
frontend are used. I think
Magento/Theme/... must be first because many others make references to it's blocks, be it adding, moving or removing.
I considered they might be following dependency order but that isn't adequate because there are many circular dependencies. For example,
Magento_Customer depends on
Magento_Theme as you would expect, but
Magento_Theme also depends on
Magento_Customer. If the wrong order is followed then important customer blocks would not be shown.
By setting breakpoints I've worked out the files are not loaded in any particular order, they are just dumped into a merged DOM to be dealt with later. But I cannot tell what happens to the merged data afterwards, is it some kind of magic?