Skip to content

Commit c145fbf

Browse files
committed
move logic into component
1 parent ff027d4 commit c145fbf

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed
Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { error } from '@sveltejs/kit';
22
import type { Examples } from '../api/examples/all.json/+server.js';
33

4-
export async function load({ fetch, params, url }) {
4+
export async function load({ fetch, params }) {
55
const examples_res = fetch('/playground/api/examples/all.json').then((r) => r.json());
66
const res = await fetch(`/playground/api/${params.id}.json`);
77

@@ -11,10 +11,6 @@ export async function load({ fetch, params, url }) {
1111

1212
const [gist, examples] = await Promise.all([res.json(), examples_res as Promise<Examples>]);
1313

14-
let version = url.searchParams.get('version') || 'latest';
15-
16-
let is_pr_or_commit_version = version.startsWith('pr-') || version.startsWith('commit-');
17-
1814
return {
1915
gist,
2016
examples: examples
@@ -25,8 +21,6 @@ export async function load({ fetch, params, url }) {
2521
title: example.title,
2622
slug: example.slug
2723
}))
28-
})),
29-
version: url.searchParams.get('version') || 'latest',
30-
is_pr_or_commit_version
24+
}))
3125
};
3226
}

apps/svelte.dev/src/routes/(authed)/playground/[id]/+page.svelte

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import type { Gist } from '$lib/db/types';
55
import { Repl } from '@sveltejs/repl';
66
import { theme } from '@sveltejs/site-kit/stores';
7-
import { onMount } from 'svelte';
87
import { mapbox_setup } from '../../../../config.js';
98
import AppControls from './AppControls.svelte';
109
import { compress_and_encode_text, decode_and_decompress_text } from './gzip.js';
@@ -18,15 +17,17 @@
1817
let repl = $state() as ReturnType<typeof Repl>;
1918
let name = $state(data.gist.name);
2019
let modified = $state(false);
21-
let version = data.version;
2220
let setting_hash: any = null;
2321
22+
let version = $page.url.searchParams.get('version') || 'latest';
23+
let is_pr_or_commit_version = version.startsWith('pr-') || version.startsWith('commit-');
24+
2425
// Hashed URLs are less safe (we can't delete malicious REPLs), therefore
2526
// don't allow links to escape the sandbox restrictions
2627
const can_escape = browser && !$page.url.hash;
2728
28-
onMount(() => {
29-
if (version !== 'local' && !data.is_pr_or_commit_version) {
29+
if (version !== 'local' && !is_pr_or_commit_version) {
30+
$effect(() => {
3031
fetch(`https://unpkg.com/svelte@${version}/package.json`)
3132
.then((r) => r.json())
3233
.then((pkg) => {
@@ -40,8 +41,8 @@
4041
replaceState(url, {});
4142
}
4243
});
43-
}
44-
});
44+
});
45+
}
4546
4647
afterNavigate(() => {
4748
name = data.gist.name;
@@ -151,7 +152,7 @@
151152
const svelteUrl =
152153
browser && version === 'local'
153154
? `${location.origin}/playground/local`
154-
: data.is_pr_or_commit_version
155+
: is_pr_or_commit_version
155156
? version
156157
: `https://unpkg.com/svelte@${version}`;
157158

packages/repl/src/lib/workers/bundler/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ self.addEventListener('message', async (event: MessageEvent<BundleMessageData>)
9393
const compiler =
9494
files?.get('/compiler/index.js')?.() ??
9595
(await fetch(`${svelte_url}/compiler/index.js`).then((r) => r.text()));
96-
console.log(compiler);
9796
(0, eval)(compiler + '\n//# sourceURL=compiler/index.js@' + version);
9897
}
9998

0 commit comments

Comments
 (0)