container-query-polyfill icon indicating copy to clipboard operation
container-query-polyfill copied to clipboard

Error parsing stylesheets where media query contains classname that contains the string 'container-'

Open jakob-metro opened this issue 3 years ago • 7 comments

Given the following stylesheet:

@media (max-width: 500px) {
    .container {

    }
    .container_foobar {

    }
}

This gets parsed fine, without error, but the following cases

@media (max-width: 500px) {
    .container- {

    }
    .container-foobar {

    }
}

Causes the following error
chrome_GzAqzOeIvz

As you can see, this only happens if the stylesheet contains a class name that contains the string container-, within a media query

It seems to be trying to emulate a container query for the class container-* by selecting @media (max-width: 500px) { which is not a valid dom selector. It does not fail if the class exists outside of a media query, nor does it fail if the hyphen is absent in the class name.

A point of clarification, I don't want any emulation of container queries on the above styles There seems to be a conflict with the above styles where the polyfill thinks it needs to find an element to emulate cq.

Tested in Chrome 96.0.4664.45 (Official Build) (64-bit)

jakob-metro avatar Nov 29 '21 21:11 jakob-metro

Yeah you are right, a string match matches here that technically shouldn’t. I’ll have a think on how to solve this.

surma avatar Dec 02 '21 15:12 surma

I'm also running into this issue trying to implement this using USWDS .

mherchel avatar Jan 27 '22 17:01 mherchel

@surma Any updates on this? We have a large code base with many "container" classes and this issue is currently preventing us from using the library.

aKzenT avatar Feb 03 '22 10:02 aKzenT

Yeah you are right, a string match matches here that technically shouldn’t. I’ll have a think on how to solve this.

I took a look and I think this is the line being referenced: https://github.com/GoogleChromeLabs/container-query-polyfill/blob/main/src/engine.ts#L291

It is a bit awkward since the whole block is being searched. Without constructing an AST it is hard to determine if this is a part of a selector or a rule.

Maybe the simplest option for now would be to add a way to disable the "content-" syntax?

jakehamilton avatar Feb 13 '22 04:02 jakehamilton

I am facing the same issue right now, is there any solution to this?

ZhengRui avatar Feb 23 '22 04:02 ZhengRui

I am facing the same issue too, in a project using Angular's Material Design project because there is a CSS rule named "mat-checkbox-inner-container"

naarl avatar Mar 22 '22 11:03 naarl

@surma do you see the pr #33 that solve this issue?

RodrigoTomeES avatar May 02 '22 15:05 RodrigoTomeES

This is fixed in the newest version (currently in alpha). If you have any further issues, please feel free to open a new issue.

Thank you!

devknoll avatar Aug 16 '22 16:08 devknoll