Skip to content

CSS Parser does not preserve styles used inside templates script[type=text/plain] #4276

@grapheon

Description

@grapheon

Bug Description

The plugin implements the removal of unused CSS rules on the page. This works well for all page content, including <template type="amp-mustache">...</template>, but does not work with <script type="text/plain" template="amp-mustache">...</script>.

Expected Behaviour

Preserve CSS rules for elements inside <script type="text/plain" template="amp-mustache">...</script>.

Steps to reproduce

  1. Add code to AMP page:
<style>
    h2.one { color: green }
    h2.two { color: red }
</style>
<template type="amp-mustache">
    <h2 class="one">One</h2>
</template>
<script type="text/plain" template="amp-mustache">
    <h2 class="two">Two</h2>
</script>
  1. View the resulting source code for an AMP page.
  2. See content <style amp-custom>...</style> in page head where there is a rule h2.one{color:green} but there is no rule h2.two{color:red}.

Additional context

  • WordPress version: 5.3.2
  • Plugin version: 1.4.2
  • AMP plugin template mode: Website; Standard; Serve all templates as AMP regardless of what is being queried.
  • PHP version: 7.3.11

Acceptance criteria

Implementation brief

QA testing instructions

Demo

Changelog entry

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't workingCSSQA passedHas passed QA and is done

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions