diff --git a/src/routes/tutorial/[slug]/+page.svelte b/src/routes/tutorial/[slug]/+page.svelte index b73c99610..e34a1f7ac 100644 --- a/src/routes/tutorial/[slug]/+page.svelte +++ b/src/routes/tutorial/[slug]/+page.svelte @@ -107,7 +107,37 @@ return destroy; }); - afterNavigate(load_exercise); + afterNavigate(async () => { + try { + $files = Object.values(data.exercise.a); + $scope = data.exercise.scope; + + selected.set( + /** @type {import('$lib/types').FileStub} */ ( + $files.find((stub) => stub.name === data.exercise.focus) + ) + ); + + clearTimeout(timeout); + loading = true; + + reset_complete_states(); + + await reset_adapter($files); + + if (adapter && path !== data.exercise.path) { + path = data.exercise.path; + set_iframe_src(adapter.base + path); + } + + loading = false; + initial = false; + } catch (e) { + loading = false; + error = /** @type {Error} */ (e); + console.error(e); + } + }); /** * Loads the adapter initially or resets it. This method can throw. @@ -155,40 +185,14 @@ }, 10000); }); - if (reload_iframe || iframe.src !== adapter.base + data.exercise.path) { + if (reload_iframe) { await new Promise((fulfil) => setTimeout(fulfil, 200)); - set_iframe_src(adapter.base + data.exercise.path); + set_iframe_src(adapter.base + path); } return adapter; } - async function load_exercise() { - try { - $files = Object.values(data.exercise.a); - $scope = data.exercise.scope; - selected.set( - /** @type {import('$lib/types').FileStub} */ ( - $files.find((stub) => stub.name === data.exercise.focus) - ) - ); - - clearTimeout(timeout); - loading = true; - - reset_complete_states(); - - await reset_adapter($files); - - loading = false; - initial = false; - } catch (e) { - loading = false; - error = /** @type {Error} */ (e); - console.error(e); - } - } - /** * @param {CustomEvent} event */ @@ -418,16 +422,7 @@ {/if} {#if loading || error} - { - error = null; - load_exercise(); - }} - /> + {/if}