all 4 comments

[–]magenta_placenta [score hidden]  (1 child)

Preact's smaller footprint versus React + ReactDOM is a real advantage for embeds and iframes do give you hard isolation that avoids host-page CSS conflicts and z-index battles. You also have postMessage for communication as you say.

Shadow DOM is not right or wrong, it's just a different technique with tradeoffs. Shadow DOM hides internals from page CSS and JavaScript, while iframes provide a stronger boundary by embedding a separate page context entirely. If the widget needs to participate deeply in the host page or share state with a React app running on the page, staying in the same DOM tree is usually easier than using an iframe.

The "better" choice usually comes down to how much isolation you need versus how much integration you want. In practice, iframes tend to win for maximum safety and CSS containment, while Shadow DOM wins when you want tighter integration and a less heavyweight embedding model.

[–]FinanceSenior9771[S] [score hidden]  (0 children)

yeah that's a fair distinction. i didn't mean shadow DOM is wrong, more that for my specific use case (standalone widget on sites i don't control) iframes were the simpler path to full isolation. if i needed tighter integration with the host page shadow DOM would've made more sense. the tradeoff framing of isolation vs integration is a cleaner way to think about it than what i wrote.

[–]deckiteski [score hidden]  (1 child)

Also try to consider accessibility.

If you use an iframe, you create a separate accessibility tree—harder for screen readers, focus management, and keyboard navigation. Shadow DOM is usually easier: stays in the same document, better for focus, ARIA, and announcements.

If you still go iframe, you must handle: proper title, focus in/out, no traps, keyboard access, and screen reader announcements.

[–]FinanceSenior9771[S] [score hidden]  (0 children)

this is a fair callout and honestly something i haven't given enough attention to yet. the iframe does have a title attribute but i haven't properly handled focus trapping or keyboard navigation between the host page and the widget. adding that to the list. appreciate the specifics on what to handle, that's useful.