diff --git a/dom/base/ShadowRoot.cpp b/dom/base/ShadowRoot.cpp index 92d5a2f2a9..d432c96e41 100644 --- a/dom/base/ShadowRoot.cpp +++ b/dom/base/ShadowRoot.cpp @@ -279,6 +279,13 @@ ShadowRoot::InsertSheet(StyleSheet* aSheet, } nsINode* sheetOwningNode = SheetAt(i)->GetOwnerNode(); + + if (!sheetOwningNode) { + // Keep moving; all sheets with a sheetOwner come after all + // sheets without an owning Node + continue; + } + if (nsContentUtils::PositionIsBefore(aLinkingContent, sheetOwningNode)) { InsertSheetAt(i, *aSheet); mProtoBinding->InsertStyleSheetAt(i, aSheet);