You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DOM elements in iframe portal are instantiated from top Window.Node instead of the iframe Window.Node #2358
I'm trying to render SolidJS components inside of an iframe using a Portal. The rendering works, but it seems the DOM elements get created from the parent document instead of the iframe document.
import{createSignal,Show,typeComponent}from'solid-js';importstylesfrom'./App.module.css';import{Portal}from'solid-js/web';constIFrame=()=>{// Track the iframe contentDocumentconst[iframeDocument,setIframeDocument]=createSignal<Document|null>(null);// Signal to track resultsconst[stats,setStats]=createSignal<{fromTop?: boolean;fromiFrame?: boolean;}>({});// Track the iframe contentDocument in a signal once it has loadedconstonLoad=(e: Event)=>{const{ contentDocument }=e.targetasHTMLIFrameElement;setIframeDocument(contentDocument);};constdivRef=(ref: HTMLDivElement)=>{setStats({// I don't want this to be truefromTop: refinstanceofwindow.Node,// I want this to be truefromiFrame: refinstanceofiframeDocument()!.defaultView!.Node,});};return(<iframesrcdoc={`<!DOCTYPE html>`}onLoad={onLoad}><Showwhen={iframeDocument()?.body}><Portalmount={iframeDocument()?.body}><divref={divRef}>Thisdiv is insideaniframe.IwanttheDOMelementtobeinstanticatedfromtheiframedocument,butitseemstobeinstantiatedfromtheparentdocument.</div><br/><div>Instantiatedfromparent: {String(stats().fromTop)}<br/>Instantiatedfromiframe: {String(stats().fromiFrame)}</div></Portal></Show></iframe>);};constApp: Component=()=>{return(<divclass={styles.App}><IFrame/></div>);};exportdefaultApp;
Render an iframe with children in a Portal. Inspect any children rendered in the Portal. They are instances of window.Node instead of contentDocument.defaultView.Node
Expected behavior
I would expect there to be a way to render child elements in an iframe that would use the contentDocument for creating DOM elements.
Yeah this is an interesting one because all the methods are tied to the document. This has reprocussions for iFrames but requires some more thought on how we can do this since JSX can be created anywhere so there is no owner document/context etc.. You could be creating the elements before the iframe even exists yet.
Activity
ryansolid commentedon Apr 30, 2025
Yeah this is an interesting one because all the methods are tied to the document. This has reprocussions for iFrames but requires some more thought on how we can do this since JSX can be created anywhere so there is no owner document/context etc.. You could be creating the elements before the iframe even exists yet.
ryansolid commentedon Oct 13, 2026
Generated by Claude Code