Skip to content

Commit 881040f

Browse files
authored
playground: reset on navigate (#11715)
1 parent 09addad commit 881040f

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

sites/svelte-5-preview/src/routes/+page.svelte

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,26 @@
33
import '@sveltejs/site-kit/styles/index.css';
44
55
import Repl from '$lib/Repl.svelte';
6-
import { onMount } from 'svelte';
76
import { default_files } from './defaults.js';
87
import { compress_and_encode_text, decode_and_decompress_text } from './gzip.js';
8+
import { afterNavigate } from '$app/navigation';
99
1010
/** @type {Repl} */
1111
let repl;
1212
1313
let setting_hash = false;
14-
let started = false;
14+
let navigating = false;
1515
16-
onMount(change_from_hash);
16+
afterNavigate(change_from_hash);
1717
1818
async function change_from_hash() {
19+
navigating = true;
20+
1921
const hash = location.hash.slice(1);
2022
2123
if (!hash) {
2224
repl.set({
23-
files: default_files
25+
files: default_files()
2426
});
2527
2628
return;
@@ -56,8 +58,8 @@
5658
5759
/** @param {CustomEvent<any>} e*/
5860
async function change_from_editor(e) {
59-
if (!started) {
60-
started = true; // ignore initial change caused by the repl.set in change_from_hash
61+
if (navigating) {
62+
navigating = false;
6163
return;
6264
}
6365
@@ -76,7 +78,7 @@
7678
</script>
7779

7880
<svelte:window
79-
on:hashchange={(e) => {
81+
on:hashchange={() => {
8082
if (!setting_hash) {
8183
change_from_hash();
8284
}

sites/svelte-5-preview/src/routes/defaults.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const default_files = [
1+
export const default_files = () => [
22
{
33
name: 'App',
44
type: 'svelte',

0 commit comments

Comments
 (0)