Skip to content

Commit 39d154b

Browse files
committed
Landing: derive deep-link redirect from the router url, not a window.location snapshot
1 parent d2f0864 commit 39d154b

1 file changed

Lines changed: 20 additions & 7 deletions

File tree

src/routes/+page.svelte

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { onMount } from 'svelte';
33
import { base } from '$app/paths';
44
import { goto } from '$app/navigation';
5+
import { page } from '$app/state';
56
import FlowCanvas from '$lib/components/FlowCanvas.svelte';
67
import Icon from '$lib/components/icons/Icon.svelte';
78
import Tooltip, { tooltip } from '$lib/components/Tooltip.svelte';
@@ -21,12 +22,17 @@
2122
// full query string (which also preserves theme/fancyloading). The
2223
// landing never renders in that case. A bare ?theme= stays here: the
2324
// theme store reads and persists it on any route.
24-
const redirecting =
25-
typeof window !== 'undefined' &&
26-
(() => {
27-
const params = new URLSearchParams(window.location.search);
28-
return params.has('model') || params.has('modelgh') || params.has('backend');
29-
})();
25+
//
26+
// Derived from the ROUTER url, not a window.location snapshot: during a
27+
// client-side navigation from /editor back to the landing, the component
28+
// initializes before the history entry updates, so window.location still
29+
// held the editor's query (?model=... from an example deep link). That
30+
// made `redirecting` spuriously true, rendered the landing empty, and
31+
// bounced the user straight back to the editor: the Home button appeared
32+
// to set the URL without ever navigating.
33+
const redirecting = $derived(
34+
['model', 'modelgh', 'backend'].some((k) => page.url.searchParams.has(k))
35+
);
3036
3137
const editorHref = `${base}/editor`;
3238
@@ -76,9 +82,16 @@
7682
recentFiles = await listRecentFiles();
7783
}
7884
85+
// Forward deep links to the editor, reacting to the url (a plain onMount
86+
// redirect would act on the stale pre-navigation query, see above).
87+
$effect(() => {
88+
if (redirecting) {
89+
void goto(`${editorHref}${page.url.search}`, { replaceState: true });
90+
}
91+
});
92+
7993
onMount(() => {
8094
if (redirecting) {
81-
void goto(`${editorHref}${window.location.search}`, { replaceState: true });
8295
return;
8396
}
8497

0 commit comments

Comments
 (0)