fix: replay search opened before its modal loads, guard lazy icons

This commit is contained in:
Diego Imbert
2026-09-26 21:30:38 +02:00
parent f2b536bbba
commit 86867ce6bd
3 changed files with 36 additions and 8 deletions
@@ -115,7 +115,9 @@
<Icon class="mr-0.5" size={12} />
{:else if resourceType}
{@const SvelteComponent = appIconComponent(filter)}
<SvelteComponent height="14px" width="14px" />
{#if SvelteComponent}
<SvelteComponent height="14px" width="14px" />
{/if}
{:else if filter.startsWith('u/')}
<User class="mr-0.5" size={14} />
{:else if filter.startsWith('f/')}
@@ -8,11 +8,17 @@ let icons = $state.raw<typeof import('./index')>()
let loading: Promise<unknown> | undefined
function load() {
if (!icons) loading ??= import('./index').then((m) => (icons = m))
if (!icons)
loading ??= import('./index').then(
(m) => (icons = m),
// Cleared so the next read retries rather than keeping the tab icon-less.
() => (loading = undefined)
)
return icons
}
export function appIconComponent(name: string | undefined): Component | undefined {
if (!name) return undefined
return load()?.appIconComponent(name)
}
@@ -1,5 +1,6 @@
<script lang="ts">
import { BROWSER } from 'esm-env'
import { isMac } from '$lib/utils'
import {
AppService,
@@ -685,11 +686,30 @@
}
}
function openSearchModal(
text?: string,
stack?: import('$lib/components/common/overlayHost.svelte').OverlayStack
): void {
globalSearchModal?.openSearchWithPrefilledText(text, stack)
type OverlayStack = import('$lib/components/common/overlayHost.svelte').OverlayStack
// The modal is a dynamic import, so a request can arrive before it is bound; it is
// held here and replayed on bind rather than dropped.
let pendingSearchOpen: { text?: string; stack?: OverlayStack } | undefined = $state()
function openSearchModal(text?: string, stack?: OverlayStack): void {
if (globalSearchModal) globalSearchModal.openSearchWithPrefilledText(text, stack)
else pendingSearchOpen = { text, stack }
}
$effect(() => {
if (globalSearchModal && pendingSearchOpen) {
const { text, stack } = pendingSearchOpen
pendingSearchOpen = undefined
untrack(() => globalSearchModal?.openSearchWithPrefilledText(text, stack))
}
})
// Until the modal is bound its own Ctrl/Cmd+K listener does not exist yet.
function onSearchShortcutBeforeLoad(e: KeyboardEvent) {
if (!globalSearchModal && (isMac() ? e.metaKey : e.ctrlKey) && e.key === 'k') {
e.preventDefault()
openSearchModal()
}
}
setContext('openSearchWithPrefilledText', openSearchModal)
@@ -920,7 +940,7 @@
})
</script>
<svelte:window bind:innerWidth />
<svelte:window bind:innerWidth onkeydown={onSearchShortcutBeforeLoad} />
<!-- Home + Runs lifted to the top of the workspace nav, sitting with Favorites
and Search as the primary quick-access cluster. Excluded from SidebarContent