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

Error in _injectChildStyle when shadowRoot is disabled in CustomElementApi #12630

Open
seperez-ncl opened this issue Dec 30, 2024 · 5 comments
Open
Labels
need more info Further information is requested

Comments

@seperez-ncl
Copy link

seperez-ncl commented Dec 30, 2024

Vue version

3.5.13

Link to minimal reproduction

codesandbox.io/p/live/442d0220-8af3-45b5-b2ed-2ab21cf088d8

Steps to reproduce

1- Create a Vue component with child component inside with scoped styles. using the Custom Element API.
2- Disable Shadow DOM.
3- Open the browser console and observe the shadowRoot error when _injectChildStyle runs.

What is expected?

When the shadowRoot option is disabled (or otherwise omitted) and child components have their own styles, Vue should inject (or refrain from injecting) those styles without throwing console errors.

What is actually happening?

Currently, when shadowRoot is disabled, the _injectChildStyle function attempts to apply child styles to a Shadow DOM. Since shadowRoot does not exist, a console error occurs indicating it cannot access shadowRoot or its methods.

System Info

No response

Any additional comments?

No response

@edison1105
Copy link
Member

edison1105 commented Dec 31, 2024

Please follow the issue requirement and provide a minimal runnable reproduction
cannot reproduce see Playground

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jan 4, 2025
@seperez-ncl
Copy link
Author

Hello @edison1105 ,

Thank you for looking into this. I understand that you were unable to reproduce the issue using the defineCustomElement function. However, in our case, we are extending the VueElement class directly in order to inject global styles into the web component something that should, in theory, work similarly to defineCustomElement but appears to behave differently in practice.

Here are more details:

  1. Extending VueElement:
  • We create a class that inherits from VueElement to have additional control when injecting global styles and setting up certain properties before the component is mounted.

  • This approach is necessary because we have shared style rules for multiple web components, which we need to inject dynamically.

  1. Expected Behavior (Similar to defineCustomElement):
  • We initially assumed that extending VueElement directly would be analogous to the internal process of defineCustomElement.

  • However, with our extended class, we encounter issues related to style injection or the component’s lifecycle—issues we do not see when using defineCustomElement.

If anyone has insight into potential internal differences between defineCustomElement and directly extending VueElement or knows of any additional hooks we might need to implement your advice would be greatly appreciated. Thank you very much for your time and assistance!

@edison1105
Copy link
Member

Please try to provide a minimal runnable reproduction for a further look.

@seperez-ncl
Copy link
Author

I was able to reproduce the issue, and it turns out it specifically occurs when the component used to register the custom element is compiled with the customElement property during the build process.
https://codesandbox.io/p/live/442d0220-8af3-45b5-b2ed-2ab21cf088d8
Screenshot 2025-01-08 at 10 07 52 AM

@edison1105
Copy link
Member

@seperez-ncl
the reproduction link shows page not found when opened
image

@edison1105 edison1105 added need more info Further information is requested and removed can't reproduce labels Jan 10, 2025
@edison1105 edison1105 reopened this Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need more info Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants