diff --git a/apps/svelte.dev/src/routes/(authed)/playground/[id]/+page.svelte b/apps/svelte.dev/src/routes/(authed)/playground/[id]/+page.svelte index 2e80eab043..39632951f1 100644 --- a/apps/svelte.dev/src/routes/(authed)/playground/[id]/+page.svelte +++ b/apps/svelte.dev/src/routes/(authed)/playground/[id]/+page.svelte @@ -9,6 +9,7 @@ import AppControls from './AppControls.svelte'; import { compress_and_encode_text, decode_and_decompress_text } from './gzip.js'; import { page } from '$app/stores'; + import type { File } from 'editor'; let { data } = $props(); @@ -45,23 +46,26 @@ set_files(); }); + // TODO make this munging unnecessary + function munge(data: any): File { + const basename = `${data.name}.${data.type}`; + + return { + type: 'file', + name: basename, + basename, + contents: data.source, + text: true + }; + } + async function set_files() { const hash = location.hash.slice(1); if (!hash) { repl?.set({ // TODO make this munging unnecessary - files: structuredClone(data.gist.components).map((file: any) => { - const basename = `${file.name}.${file.type}`; - - return { - type: 'file', - name: basename, - basename, - contents: file.source, - text: true - }; - }) + files: structuredClone(data.gist.components).map(munge) }); modified = false; @@ -69,7 +73,12 @@ } try { - const files = JSON.parse(await decode_and_decompress_text(hash)).files; + let files = JSON.parse(await decode_and_decompress_text(hash)).files; + + if (files[0]?.source) { + files = files.map(munge); + } + repl.set({ files }); } catch { alert(`Couldn't load the code from the URL. Make sure you copied the link correctly.`); diff --git a/apps/svelte.dev/src/routes/+page.js b/apps/svelte.dev/src/routes/+page.js new file mode 100644 index 0000000000..27cc788bbf --- /dev/null +++ b/apps/svelte.dev/src/routes/+page.js @@ -0,0 +1,10 @@ +import { browser } from '$app/environment'; +import { redirect } from '@sveltejs/kit'; + +export function load() { + // redirect old svelte-5-preview.vercel.app playground links, + // which all have a hash that starts with this pattern + if (browser && location.hash.startsWith('#H4sIA')) { + redirect(307, `/playground/untitled${location.hash}`); + } +}