Fixes the white flash for widget iframes & Make use of panel api (#882)

* Fix widget iframes flashing when loading

* Set the data-theme attribute for all panels
pull/887/head
MrMugame 2024-06-08 13:32:35 +02:00 committed by GitHub
parent ff923b8718
commit 892849c30b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 4 additions and 7 deletions

View File

@ -26,8 +26,6 @@ export async function updateMarkdownPreview() {
},
});
const customStyles = await editor.getUiOption("customStyles");
const darkMode = await clientStore.get("darkMode");
const theme = darkMode ? "dark" : "light";
await editor.showPanel(
"rhs",
2,
@ -40,11 +38,7 @@ export async function updateMarkdownPreview() {
<div id="root" class="sb-preview">${html}</div>
`,
`
document.documentElement.dataset.theme = ${JSON.stringify(theme)};
${js}
`,
js,
);
}

View File

@ -21,6 +21,7 @@ export function Panel({
type: "html",
html: config.html,
script: config.script,
theme: document.getElementsByTagName("html")[0].dataset.theme
});
}

View File

@ -52,10 +52,12 @@ export function prepareSandboxIFrame(): PreloadedIFrame {
// Empty page with current origin. Handled this differently before, but "dock apps" in Safari (PWA implementation) seem to have various restrictions
// This one works in all browsers, although it's probably less secure
iframe.src = "about:blank";
iframe.style.visibility = "hidden";
const ready = new Promise<void>((resolve) => {
iframe.onload = () => {
iframe.contentDocument!.write(panelHtml);
iframe.style.visibility = "visible";
// Now ready to use
resolve();
};