Skip to content

Commit 878d3b8

Browse files
authored
fix: prevent iframe from flashing when switching tutorial (sveltejs#268)
1 parent f8d4046 commit 878d3b8

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/routes/tutorial/[slug]/Output.svelte

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@
7474
function set_iframe_src(src) {
7575
if (!iframe) return; // HMR
7676
77+
// To prevent iframe flickering.
78+
// Set to `visible` by calling `set_iframe_visible` function
79+
// from iframe on:load or setTimeout
80+
iframe.style.visibility = 'hidden';
81+
setTimeout(set_iframe_visible, 1000);
82+
7783
// removing the iframe from the document allows us to
7884
// change the src without adding a history entry, which
7985
// would make back/forward traversal very annoying
@@ -82,6 +88,12 @@
8288
iframe.src = src;
8389
parentNode?.appendChild(iframe);
8490
}
91+
92+
function set_iframe_visible() {
93+
if (iframe.style.visibility === 'hidden') {
94+
iframe.style.visibility = 'visible';
95+
}
96+
}
8597
</script>
8698
8799
<svelte:window on:message={handle_message} />
@@ -105,7 +117,7 @@
105117
106118
<div class="content">
107119
{#if browser}
108-
<iframe bind:this={iframe} title="Output" />
120+
<iframe bind:this={iframe} title="Output" on:load={set_iframe_visible} />
109121
{/if}
110122
111123
{#if paused || loading || $error}

0 commit comments

Comments
 (0)