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

Support for multiple containers / components on page #3

Open
teosbb opened this issue Jun 8, 2021 · 10 comments
Open

Support for multiple containers / components on page #3

teosbb opened this issue Jun 8, 2021 · 10 comments

Comments

@teosbb
Copy link

teosbb commented Jun 8, 2021

When I add multiple containers/contained elements on the page the polyfill behaves strange.
Would be nice to have a example for multiple containers / unit tests.

Example 1 (normal website): we have one (global) container and two contained
Variant 1: https://stackblitz.com/edit/cqfill-multiple-containers?file=index.html
Variant 2: https://stackblitz.com/edit/cqfill-one-container-multiple-contained-media?file=style.css
it works as expected then.

Example 2 (Component based development): - we have two containers and two contained (basically if you develop isolated component based > webcomponents, angular,.... it's always this case):
https://stackblitz.com/edit/cqfill-multiple-containers-multiple-components?file=index.html

only the first will work because of the --css-container variable?

I think the postcss plugin should process it > make a central container or use multiple --css-container variables

@ghost
Copy link

ghost commented Jun 10, 2021

Your suggestion seems logical. I've been butting up against this as well.

Also want to thank everyone who is contributing to this project - this polyfill will help boost adoption of one of the most interesting new specs!

@jonathantneal
Copy link
Contributor

Thanks for the great reproduction. I was able to replicate it, while seeing that the issue was not present in my current testing demos. I’m going to spend more time looking into why this is and hopefully pushing a solution soon.

@jasikpark
Copy link
Contributor

Shouldn't it depend on what element the javascript adds the --css-contain variable on? Basically that's how it is scoped?

@jasikpark
Copy link
Contributor

Maybe the postcss function can produce css module style css variables? --css-contain-asdf;lkj

So that multiple containers can all track their container sizes?

@Blazsoul
Copy link

Blazsoul commented Oct 4, 2021

Do you got any workaround guys? it can really help me out

@jasikpark
Copy link
Contributor

It looks to me like

@media --css-container and (min-width: 800px) {
 ._titleLink_1ub1h_13 {
  grid-template-columns:1fr 2fr 1fr;
  grid-template-areas:"unofficial distractible scoreboard"
 }
}

is querying --css-container on :root and so when we have multiple containers on the same page, we have a race condition on which container's state is stored in that variable..

So something like --css-container-12354 and --css-container-ad;lkfj I think would be good for a per-container tracking of the container status.

@Blazsoul
Copy link

Blazsoul commented Nov 2, 2021

Absolutely, But i don't think this polyfill is being maintained anymore though.
I tried to have a look in the code and i assume that this line:

const hasContainerQueryPolyfill = mediaText.indexOf('@container') === 0 || mediaText.indexOf('--css-container') === 0

returns false for the rest of the containers.

@jasikpark
Copy link
Contributor

It looks like the polyfill needs to be updated for container names to support multiple containers now that the spec supports it!

@Blazsoul
Copy link

Blazsoul commented Nov 3, 2021

Indeed, thats definitely a deal breaker

@Blazsoul
Copy link

Pull request fix:
#14

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

No branches or pull requests

4 participants