diff --git a/site/src/routes/repl/[id]/_components/AppControls/index.svelte b/site/src/routes/repl/[id]/_components/AppControls/index.svelte index c2e5684944..43f7b28cc8 100644 --- a/site/src/routes/repl/[id]/_components/AppControls/index.svelte +++ b/site/src/routes/repl/[id]/_components/AppControls/index.svelte @@ -86,6 +86,8 @@ if (saving) return; if (!canSave) { + // Save to local storage + localStorage.setItem("repl_content", JSON.stringify(repl.toJSON())) fork(true); return; } diff --git a/site/src/routes/repl/[id]/index.svelte b/site/src/routes/repl/[id]/index.svelte index 945678ba33..1eaf333c6d 100644 --- a/site/src/routes/repl/[id]/index.svelte +++ b/site/src/routes/repl/[id]/index.svelte @@ -47,6 +47,17 @@ return; } + const local_repl_content = localStorage.getItem("repl_content") + + // Check if user is not logged in and has local data + if (id == 'hello-world' && local_repl_content && !$session.user) { + setTimeout(() => { + repl.set(JSON.parse(local_repl_content)) + }, 300) // Wait for repl var (it's undefined when this function gets called) + // TODO: Fix this possible race condition + return + } + // TODO handle `relaxed` logic fetch(`repl/${id}.json`).then(r => { if (r.ok) {