Skip to content

Commit 4057bfc

Browse files
Remove set_iframe_src and loaded to prevent app-hiding during reload
1 parent 8b0e8ee commit 4057bfc

File tree

1 file changed

+8
-29
lines changed

1 file changed

+8
-29
lines changed

Diff for: src/routes/tutorial/[slug]/+page.svelte

+8-29
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,13 @@
107107
}
108108
109109
onMount(() => {
110-
function on_iframe_load() {
111-
iframe.classList.add('loaded');
112-
}
113110
function destroy() {
114-
iframe.removeEventListener('load', on_iframe_load);
115111
if (adapter) {
116112
adapter.destroy();
117113
}
118114
}
119115
120116
document.addEventListener('pagehide', destroy);
121-
iframe.addEventListener('load', on_iframe_load);
122117
return destroy;
123118
});
124119
@@ -143,7 +138,7 @@
143138
144139
if (adapter && path !== data.exercise.path) {
145140
path = data.exercise.path;
146-
set_iframe_src(adapter.base + path);
141+
iframe.src = adapter.base + path;
147142
}
148143
149144
loading = false;
@@ -171,7 +166,7 @@
171166
status = s;
172167
});
173168
174-
set_iframe_src(adapter.base + path);
169+
iframe.src = adapter.base + path;
175170
}
176171
177172
await new Promise((fulfil, reject) => {
@@ -190,7 +185,7 @@
190185
if (!called && adapter) {
191186
// Updating the iframe too soon sometimes results in a blank screen,
192187
// so we try again after a short delay if we haven't heard back
193-
set_iframe_src(adapter.base + path);
188+
iframe.src = adapter.base + path;
194189
}
195190
}, 5000);
196191
@@ -203,7 +198,7 @@
203198
204199
if (reload_iframe) {
205200
await new Promise((fulfil) => setTimeout(fulfil, 200));
206-
set_iframe_src(adapter.base + path);
201+
iframe.src = adapter.base + path;
207202
}
208203
209204
return adapter;
@@ -230,7 +225,7 @@
230225
clearTimeout(reload_timeout);
231226
reload_timeout = setTimeout(() => {
232227
if (adapter) {
233-
set_iframe_src(adapter.base + path);
228+
iframe.src = adapter.base + path;
234229
}
235230
}, 1000);
236231
}
@@ -287,7 +282,7 @@
287282
288283
// we lost contact, refresh the page
289284
loading = true;
290-
set_iframe_src(adapter.base + path);
285+
iframe.src = adapter.base + path;
291286
loading = false;
292287
}, 1000);
293288
} else if (e.data.type === 'ping-pause') {
@@ -316,24 +311,12 @@
316311
return code.replace(/\s+/g, ' ').trim();
317312
}
318313
319-
/** @param {string} src */
320-
function set_iframe_src(src) {
321-
// removing the iframe from the document allows us to
322-
// change the src without adding a history entry, which
323-
// would make back/forward traversal very annoying
324-
const parentNode = /** @type {HTMLElement} */ (iframe.parentNode);
325-
iframe.classList.remove('loaded');
326-
parentNode?.removeChild(iframe);
327-
iframe.src = src;
328-
parentNode?.appendChild(iframe);
329-
}
330-
331314
/** @param {string} path */
332315
function route_to(path) {
333316
if (adapter) {
334317
const url = new URL(path, adapter.base);
335318
path = url.pathname + url.search + url.hash;
336-
set_iframe_src(adapter.base + path);
319+
iframe.src = adapter.base + path;
337320
}
338321
}
339322
@@ -468,7 +451,7 @@
468451
{loading}
469452
on:refresh={() => {
470453
if (adapter) {
471-
set_iframe_src(adapter.base + path);
454+
iframe.src = adapter.base + path;
472455
}
473456
}}
474457
on:change={(e) => nav_to(e.detail.value)}
@@ -556,10 +539,6 @@
556539
background: var(--sk-back-2);
557540
}
558541
559-
iframe:not(.loaded) {
560-
display: none;
561-
}
562-
563542
.editor-container {
564543
position: relative;
565544
background-color: var(--sk-back-3);

0 commit comments

Comments
 (0)