fix(workbench): handle ?app= deep-links reactively while page is mounted

The onMount handler only fires once, so clicking a /?app=settings link
from the companion chat (or any in-app link) while already on the
workbench page did nothing. Add a reactive $effect that watches
$page.url.searchParams for 'app' changes and opens/scrolls to the
target panel on every navigation, not just on initial mount.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Till JS 2026-04-17 15:08:25 +02:00
parent e60965ee19
commit fa31fa0caf

View file

@ -82,6 +82,25 @@
history.replaceState({}, '', clean);
}
});
// Reactive deep-link: handles `/?app=…` navigations that happen
// while the page is already mounted (e.g. clicking a link inside
// the companion chat). onMount only fires once; this $effect
// re-runs whenever the URL search params change.
$effect(() => {
const target = $page.url.searchParams.get('app');
if (!target || !getApp(target)) return;
// Use queueMicrotask so we don't mutate state during the effect's first run
queueMicrotask(async () => {
const already = workbenchScenesStore.openApps.find((a) => a.appId === target);
if (!already) await workbenchScenesStore.addApp(target);
await tick();
scrollToPage(target);
const clean = new URL($page.url);
clean.searchParams.delete('app');
history.replaceState({}, '', clean);
});
});
onDestroy(() => {
workbenchScenesStore.dispose();
bottomBarStore.clear();