Skip to content

Commit c6243bc

Browse files
authored
Merge pull request #2642 from sammarshallou/MOBILE-3607
MOBILE-3607 Site plugins: CSS should be included in reliable order
2 parents bf4afaa + 098c7a1 commit c6243bc

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/core/siteplugins/providers/helper.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,21 @@ export class CoreSitePluginsHelperProvider {
439439
styleEl.setAttribute('id', 'siteplugin-' + uniqueName);
440440
styleEl.innerHTML = cssCode;
441441

442-
document.head.appendChild(styleEl);
442+
// To ensure consistency, insert in alphabetical order among other site plugin styles.
443+
let lowestGreater = null;
444+
Array.from(document.head.querySelectorAll('style')).forEach((other) => {
445+
if (/^siteplugin-/.test(other.id) && other.id > styleEl.id) {
446+
if (lowestGreater === null || other.id < lowestGreater.id) {
447+
lowestGreater = other;
448+
}
449+
}
450+
});
451+
452+
if (lowestGreater) {
453+
document.head.insertBefore(styleEl, lowestGreater);
454+
} else {
455+
document.head.appendChild(styleEl);
456+
}
443457

444458
// Styles have been loaded, now treat the CSS.
445459
this.filepoolProvider.treatCSSCode(siteId, fileUrl, cssCode, CoreSitePluginsProvider.COMPONENT, uniqueName, version)

0 commit comments

Comments
 (0)