Skip to content

Can't find spec support for setting importRule.styleSheet.parentStyleSheet to null after deleting that import rule #13612

@domenic

Description

@domenic

Browsers seem to set importRule.styleSheet.parentStyleSheet to null after removing the rule via CSSOM.

Test case
<!DOCTYPE html>
<title>Remove a CSS rule: @import styleSheet unlinking</title>
<style>
  @import url("data:text/css,.imported { color: red }");
  .local { color: green }
</style>
<pre id="out"></pre>
<script>
const out = document.getElementById("out");
function log(msg) { out.textContent += msg + "\n"; }

// Wait for @import to load
setTimeout(() => {
  const sheet = document.styleSheets[0];
  const importRule = sheet.cssRules[0];

  log("importRule.type = " + importRule.type + " (expecting 3 = IMPORT_RULE)");
  log("importRule.styleSheet = " + importRule.styleSheet);

  const importedSheet = importRule.styleSheet;
  if (!importedSheet) {
    log("(imported stylesheet not available, try opening via a local server)");
    return;
  }

  log("");
  log("=== Before deleteRule ===");
  log("importedSheet.parentStyleSheet = " + importedSheet.parentStyleSheet);
  log("importedSheet.ownerRule = " + importedSheet.ownerRule);

  sheet.deleteRule(0);

  log("");
  log("=== After deleteRule ===");
  log("importedSheet.parentStyleSheet = " + importedSheet.parentStyleSheet);
  log("importedSheet.ownerRule = " + importedSheet.ownerRule);
}, 1000);
</script>

However, the only place I can find that nulls out parent CSS style sheet is remove a CSS style sheet. And the only caller of that is some xsl-stylesheet thing.

In particular, remove a CSS rule does not call "remove a CSS style sheet" for @import rules. (It does null out the rule's parent CSS style sheet (something all CSS rules have), but not the rule's "associated CSS style sheet"'s parent CSS style sheet.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions