Skip to content

[cssom-1] Incorrect handling of media in Create a constructed CSSStyleSheet? #11778

@cdoublev

Description

@cdoublev

Step 12 of the procedure requires serializing a media query list from media when it is not a string:

  1. If the media attribute of options is a string, create a MediaList object from the string and assign it as sheet’s media. Otherwise, serialize a media query list from the attribute and then create a MediaList object from the resulting string and set it as sheet’s media.

I doubt that the procedure for serializing a media query list expects a MediaList (cf. CSSStyleSheetInit).

Besides, the media query list associated to the new MediaList should be updated whenever the attribute (of the owner node) is updated:

If this property is specified to an attribute of the owner node, the media must be set to the return value of invoking create a MediaList object steps for the value of that attribute. Whenever the attribute is set, changed or removed, the media’s mediaText attribute must be set to the new value of the attribute, or to null if the attribute is absent.

For example:

<style media="(width: 0px)" id="style">
  * { color: red }
</style>
<p>I become red after 1s</p>
<script>
  const sheet = document.styleSheets[0]
  sheet.media.mediaText // (width: 0px)
  setTimeout(() => {
    style.setAttribute('media', '(width > 0px)')
    style.getAttribute('media') // (width > 0px)
    sheet.media.mediaText // (width > 0px)
  }, 1000)
</script>

So I suspect that step 12 should parse a media query list from media when it is a string, create a MediaList object with it, and assign it as sheet's media. Otherwise, if it is a MediaList, it should create a new MediaList with the media query list associated to media.

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