Skip to content

Commit e7799be

Browse files
committed
simplify iframe helper
1 parent 2d545e9 commit e7799be

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

pages/utils/iframe-wrapper.tsx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,15 @@ import { createRoot } from "react-dom/client";
77
import styles from "./iframe-wrapper.module.scss";
88

99
export function IframeWrapper({ id = "iframe", AppComponent }: { id?: string; AppComponent: React.ComponentType }) {
10-
const ref = useRef<HTMLDivElement>(null);
10+
const iframeRef = useRef<HTMLIFrameElement>(null);
1111

1212
useEffect(() => {
13-
const container = ref.current;
14-
if (!container) {
13+
const iframe = iframeRef.current;
14+
if (!iframe) {
1515
return;
1616
}
17-
const iframeEl = container.ownerDocument.createElement("iframe");
18-
iframeEl.className = styles["full-screen"];
19-
iframeEl.id = id;
20-
iframeEl.title = id;
21-
container.appendChild(iframeEl);
2217

23-
const iframeDocument = iframeEl.contentDocument!;
18+
const iframeDocument = iframe.contentDocument!;
2419
// Prevent iframe document instance from reload
2520
// https://bugzilla.mozilla.org/show_bug.cgi?id=543435
2621
iframeDocument.open();
@@ -38,11 +33,10 @@ export function IframeWrapper({ id = "iframe", AppComponent }: { id?: string; Ap
3833
return () => {
3934
syncClassesCleanup();
4035
root.unmount();
41-
container.removeChild(iframeEl);
4236
};
4337
}, [id, AppComponent]);
4438

45-
return <div ref={ref}></div>;
39+
return <iframe ref={iframeRef} id={id} title={id} className={styles["full-screen"]}></iframe>;
4640
}
4741

4842
function copyStyles(srcDoc: Document, targetDoc: Document) {

0 commit comments

Comments
 (0)