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
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.
Platform
OS: MacOS
Browser: Chrome
Version: 1.7.6
The text was updated successfully, but these errors were encountered:
Describe the bug
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.
Your Example Website or App
https://stackblitz.com/edit/solidjs-iframe-issue?file=src%2FApp.tsx
Steps to Reproduce the Bug or Issue
Render an iframe with children in a Portal. Inspect any children rendered in the Portal. They are instances of
window.Node
instead ofcontentDocument.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.
Platform
The text was updated successfully, but these errors were encountered: