Hacker News new | ask | show | jobs
by interlocutor 2561 days ago
There is also robustness. Today you can't take a React component from one application and drop it in another React application and expect it to just work. You may need to also copy CSS classes, make sure the class names are unique, remove any conflicting ids, global variables and so on. Thanks to Shadow DOM, web components are much more robust. You can just drop a web component in an existing application and expect it to just work, regardless of what framework (Angular, React etc) it is using.
2 comments

How is it better than using, say, iframes and postMessage? Is shadow DOM more efficient? Can Web Components work across domains?

I want to have Shadow DOM that encapsulates trust, so the enclosing parent javascript cannot access its contents!!

https://www.w3.org/Bugs/Public/show_bug.cgi?id=20144

Except you can, just use styled-components. If you don’t have any other deps except styling, it works quite nicely.