无法在已托管影子树的主机上创建影子根
我正在 Shadow DOM 中渲染一个 React 应用程序(Widget)。所以我查看了当前加载小部件的 div id。
有了这些信息,我想像这样创建Shadow主机。
const host = document.querySelector('#widget-_hw');
const shadow = host.attachShadow({ mode: 'open' });
const renderIn = document.createElement('div');
但我收到这个错误。
Failed to execute 'attachShadow' on 'Element': Shadow root cannot be created on a host which already hosts a shadow tree
I'm rendering a react app(Widget) inside Shadow DOM. So I looked at the div id where the widget is getting loaded currently.
With this information, I want to create Shadow host like this.
const host = document.querySelector('#widget-_hw');
const shadow = host.attachShadow({ mode: 'open' });
const renderIn = document.createElement('div');
But I'm getting this error.
Failed to execute 'attachShadow' on 'Element': Shadow root cannot be created on a host which already hosts a shadow tree
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这对我有用。
This one worked for me.
它表示您无法将影子文档附加到此元素,因为它已经附加了一个文档。
在您的代码中设置一个断点并检查它是否不会被调用两次。
或者,检查
shadowRoot
属性。It's saying you can't attach a shadow document to this element because it already has a document attached.
In your code set a breakpoint and check that it's not getting call twice.
Alternatively, check the
shadowRoot
property.