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

Question: Web Component support #1

Open
lazka opened this issue May 18, 2021 · 3 comments
Open

Question: Web Component support #1

lazka opened this issue May 18, 2021 · 3 comments

Comments

@lazka
Copy link

lazka commented May 18, 2021

Hey, I tried to get this to work with lit, but failed: https://codepen.io/lazka/pen/ExWgrYb

I was wondering if I'm missing something or if this isn't supported?

@nardbagel
Copy link

nardbagel commented May 25, 2021

Hmmm. could be that you are importing the polyfill in the global scope, but the styles declared in the web-component are rendered in the component's shadow dom, and the script can't polyfill what it can't see. The fix I am guessing is to import the script inside the web-component so the polyfill can see the css in the component's shadow dom. I am new to web-components and container queries, but stuff like this has bitten me in the past, so I'd guess this is the culprit.

@lazka
Copy link
Author

lazka commented May 25, 2021

hm, I'm not sure what you mean. I'm explicitly passing the shadow root to the polyfill.

@stickeegreg
Copy link

stickeegreg commented Nov 3, 2021

I had the same problem with it not working in a Web Component.

I believe the problem is the way it builds the selector in getElementSelectorText.
It uses :root and traverses up the element's parents, but the traversal stops at the top of the shadow DOM, whereas :root refers to the root element of the host page, so the selector won't match anything.

I couldn't find an equivalent to :root that would match the web component's root node, so for now I've replace getElementSelectorText with this, and it seems to work so far:

elementId = 0,
getElementSelectorText = (element) => {
    if (!element.dataset.cqfillId) {
        element.dataset.cqfillId = ++elementId;
    }

    return `[data-cqfill-id="${element.dataset.cqfillId}"]`;
},

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

3 participants