Skip to content

[cssom] Missing step to set parentStyleSheet #6945

Closed
@cdoublev

Description

@cdoublev

In Chrome/Firefox, a CSSStyleRule added to CSSStyleSheet.cssRules by using CSSStyleSheet.insertRule(), will not have a parentStyleSheet:

The parentStyleSheet attribute must return the parent CSS style sheet.

Note: The only circumstance where null is returned when a rule has been removed.

Should it be ...or when a rule has been inserted?

Below is how I read an undefined parentStyleSheet for this new rule.

<style>
  div { color: red }
</style>
<script>
  const { styleSheets: [styleSheet] } = document
  const { cssRules } = styleSheet
  const [{ parentStyleSheet }] = cssRules
  console.log(styleSheet === parentStyleSheet)
  styleSheet.insertRule('p { color: red }')
  console.log(cssRules.length)
  const [, { parentStyleSheet2 }] = cssRules
  console.log((styleSheet === parentStyleSheet2) || parentStyleSheet2) // undefined
</script>

parent CSS style sheet: a reference to a parent CSS style sheet or null. This item is initialized to reference an associated style sheet when the rule is created. It can be changed to null.

It may be missing either in parse a CSS rule or insert CSS rule. I'm curious to learn the answer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions