Skip to content
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

Prevent tree-shaking CSS selectors for dynamic attributes #3212

Merged
merged 1 commit into from
Sep 10, 2019

Conversation

westonruter
Copy link
Member

@westonruter westonruter commented Sep 9, 2019

This fixes an issue reported on the support forum:

I’m only trying to style an expanded menu inside of a sidebar. I’m using standard AMP elements, including amp-accordion. The inline style that gets added by the plugin is automatically removing the styles that would allow this, for example:

section.menu-section[expanded] {
    background: green;
}

The plugin isn’t stripping out any other content.

In #1959 (and #2017, #2642, #2710) tree shaking for CSS selectors was made aware of the class names for AMP components which can be dynamically added/removed from a page. Even though the selector with such a class name may not exist at the initial time of rendering the page, the selector may very well apply later. The same logic needed to be extended to attributes which are added/removed to AMP components. In particular:

  • amp-sidebar: The open attribute is dynamically added when the sidebar is opened.
  • amp-accordion: The expanded attribute is added when a section is opened by the user.
  • amp-live-list: The data-tombstone attribute can appear in an amp-live-list's contents during the life of a page.

@westonruter westonruter added this to the v1.3 milestone Sep 9, 2019
@googlebot googlebot added the cla: yes Signed the Google CLA label Sep 9, 2019
@westonruter westonruter merged commit 94cc51d into develop Sep 10, 2019
@westonruter westonruter deleted the add/dynamic-component-attribute-tree-shaking branch September 10, 2019 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Signed the Google CLA CSS Sanitizers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants