File tree Expand file tree Collapse file tree 2 files changed +31
-12
lines changed
apps/svelte.dev/src/routes Expand file tree Collapse file tree 2 files changed +31
-12
lines changed Original file line number Diff line number Diff line change 99 import AppControls from ' ./AppControls.svelte' ;
1010 import { compress_and_encode_text , decode_and_decompress_text } from ' ./gzip.js' ;
1111 import { page } from ' $app/stores' ;
12+ import type { File } from ' editor' ;
1213
1314 let { data } = $props ();
1415
4546 set_files ();
4647 });
4748
49+ // TODO make this munging unnecessary
50+ function munge(data : any ): File {
51+ const basename = ` ${data .name }.${data .type } ` ;
52+
53+ return {
54+ type: ' file' ,
55+ name: basename ,
56+ basename ,
57+ contents: data .source ,
58+ text: true
59+ };
60+ }
61+
4862 async function set_files() {
4963 const hash = location .hash .slice (1 );
5064
5165 if (! hash ) {
5266 repl ?.set ({
5367 // TODO make this munging unnecessary
54- files: structuredClone (data .gist .components ).map ((file : any ) => {
55- const basename = ` ${file .name }.${file .type } ` ;
56-
57- return {
58- type: ' file' ,
59- name: basename ,
60- basename ,
61- contents: file .source ,
62- text: true
63- };
64- })
68+ files: structuredClone (data .gist .components ).map (munge )
6569 });
6670
6771 modified = false ;
6872 return ;
6973 }
7074
7175 try {
72- const files = JSON .parse (await decode_and_decompress_text (hash )).files ;
76+ let files = JSON .parse (await decode_and_decompress_text (hash )).files ;
77+
78+ if (files [0 ]?.source ) {
79+ files = files .map (munge );
80+ }
81+
7382 repl .set ({ files });
7483 } catch {
7584 alert (` Couldn't load the code from the URL. Make sure you copied the link correctly. ` );
Original file line number Diff line number Diff line change 1+ import { browser } from '$app/environment' ;
2+ import { redirect } from '@sveltejs/kit' ;
3+
4+ export function load ( ) {
5+ // redirect old svelte-5-preview.vercel.app playground links,
6+ // which all have a hash that starts with this pattern
7+ if ( browser && location . hash . startsWith ( '#H4sIA' ) ) {
8+ redirect ( 307 , `/playground/untitled${ location . hash } ` ) ;
9+ }
10+ }
You can’t perform that action at this time.
0 commit comments