Skip to content

[cssom] Missing step to set parentStyleSheet #6945

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cdoublev opened this issue Jan 13, 2022 · 1 comment
Closed

[cssom] Missing step to set parentStyleSheet #6945

cdoublev opened this issue Jan 13, 2022 · 1 comment

Comments

@cdoublev
Copy link
Collaborator

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.

@cdoublev
Copy link
Collaborator Author

There was a typo in my code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant