Skip to content

Commit 89136b6

Browse files
authored
fix: preserve studio prompt across login via session storage (#2705)
* fix:preserve studio prompt across login via session storage * remove not imprttant var
1 parent 4d637e3 commit 89136b6

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

src/routes/+layout.svelte

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,28 @@
3838
}
3939
}
4040
41+
async function syncStudioPrompt() {
42+
if (!browser || resolvedProfile.id !== ProfileMode.STUDIO) return;
43+
44+
const currentUrl = new URL(window.location.href);
45+
const promptParam = currentUrl.searchParams.get('prompt');
46+
47+
if (promptParam) {
48+
sessionStorage.setItem('studioPrompt', promptParam);
49+
return;
50+
}
51+
52+
const storedPrompt = sessionStorage.getItem('studioPrompt');
53+
if (!storedPrompt) return;
54+
55+
currentUrl.searchParams.set('prompt', storedPrompt);
56+
await goto(currentUrl.toString(), { replaceState: true, noScroll: true });
57+
sessionStorage.removeItem('studioPrompt');
58+
}
59+
4160
onMount(async () => {
4261
updateViewport();
62+
await syncStudioPrompt();
4363
// handle sources
4464
if (isCloud) {
4565
const urlParams = page.url.searchParams;
@@ -116,6 +136,7 @@
116136
});
117137
118138
afterNavigate((navigation) => {
139+
syncStudioPrompt();
119140
if (navigation.type !== 'enter' && navigation.from?.route?.id !== navigation.to.route.id) {
120141
trackPageView(navigation.to.route.id);
121142
}

0 commit comments

Comments
 (0)