playground: reset on navigate (#11715)

pull/11724/head
Rich Harris 7 months ago committed by GitHub
parent 09addad9ae
commit 881040fb78
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -3,24 +3,26 @@
import '@sveltejs/site-kit/styles/index.css';
import Repl from '$lib/Repl.svelte';
import { onMount } from 'svelte';
import { default_files } from './defaults.js';
import { compress_and_encode_text, decode_and_decompress_text } from './gzip.js';
import { afterNavigate } from '$app/navigation';
/** @type {Repl} */
let repl;
let setting_hash = false;
let started = false;
let navigating = false;
onMount(change_from_hash);
afterNavigate(change_from_hash);
async function change_from_hash() {
navigating = true;
const hash = location.hash.slice(1);
if (!hash) {
repl.set({
files: default_files
files: default_files()
});
return;
@ -56,8 +58,8 @@
/** @param {CustomEvent<any>} e*/
async function change_from_editor(e) {
if (!started) {
started = true; // ignore initial change caused by the repl.set in change_from_hash
if (navigating) {
navigating = false;
return;
}
@ -76,7 +78,7 @@
</script>
<svelte:window
on:hashchange={(e) => {
on:hashchange={() => {
if (!setting_hash) {
change_from_hash();
}

@ -1,4 +1,4 @@
export const default_files = [
export const default_files = () => [
{
name: 'App',
type: 'svelte',

Loading…
Cancel
Save