Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions apps/svelte.dev/src/routes/(authed)/playground/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -45,31 +46,39 @@
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;
return;
}

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.`);
Expand Down
10 changes: 10 additions & 0 deletions apps/svelte.dev/src/routes/+page.js
Original file line number Diff line number Diff line change
@@ -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}`);
}
}
Loading