|
2 | 2 | import { onMount } from 'svelte'; |
3 | 3 | import { base } from '$app/paths'; |
4 | 4 | import { goto } from '$app/navigation'; |
| 5 | + import { page } from '$app/state'; |
5 | 6 | import FlowCanvas from '$lib/components/FlowCanvas.svelte'; |
6 | 7 | import Icon from '$lib/components/icons/Icon.svelte'; |
7 | 8 | import Tooltip, { tooltip } from '$lib/components/Tooltip.svelte'; |
|
21 | 22 | // full query string (which also preserves theme/fancyloading). The |
22 | 23 | // landing never renders in that case. A bare ?theme= stays here: the |
23 | 24 | // 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 | + ); |
30 | 36 |
|
31 | 37 | const editorHref = `${base}/editor`; |
32 | 38 |
|
|
76 | 82 | recentFiles = await listRecentFiles(); |
77 | 83 | } |
78 | 84 |
|
| 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 | +
|
79 | 93 | onMount(() => { |
80 | 94 | if (redirecting) { |
81 | | - void goto(`${editorHref}${window.location.search}`, { replaceState: true }); |
82 | 95 | return; |
83 | 96 | } |
84 | 97 |
|
|
0 commit comments