From a9a153a37e399ca3c28bd7441065bb35250fcd93 Mon Sep 17 00:00:00 2001 From: broisnees Date: Tue, 17 Nov 2026 07:22:27 +0000 Subject: [PATCH] Load Settings, the command palette and one-off dialogs on first use --- src/lib/components/StudioShell.svelte | 79 ++++++++++++++++++++++++--- 1 file changed, 71 insertions(+), 8 deletions(-) diff --git a/src/lib/components/StudioShell.svelte b/src/lib/components/StudioShell.svelte index c5a6d6dc..a57aba6d 100644 --- a/src/lib/components/StudioShell.svelte +++ b/src/lib/components/StudioShell.svelte @@ -63,7 +63,6 @@ import * as PaneTree from '$lib/pane-layout.js' import TabLoading from './TabLoading.svelte' import TableToolbar from './TableToolbar.svelte' - import ImportDataDialog from './ImportDataDialog.svelte' import DataTable from './DataTable.svelte' import RowDetailPanel from './RowDetailPanel.svelte' // TableJsonView / TableTextView are NOT imported here: both reach the CodeMirror @@ -72,19 +71,14 @@ // view mode. They load via {#await import()} at their (already guarded) call // sites below, exactly like MapPage / EntityRelationPage. import TableRecordView from './TableRecordView.svelte' - import CommandPalette from './CommandPalette.svelte' // AiChat / AiSidebar (large, pull in marked + shiki) are loaded lazily the first time // the AI panel is opened - see the {#await import()} blocks below. - import AiSettingsDialog from './AiSettingsDialog.svelte' import ConnectionModal from './ConnectionModal.svelte' import { terminalDockOpen as terminalDockStore } from '$lib/stores/redis-nav.js' import DbIcon from './DbIcon.svelte' - import ShareDialog from './ShareDialog.svelte' - import { requestShare, sharesPageRequest, chartTitle } from '$lib/share-flow.js' + import { requestShare, sharesPageRequest, chartTitle, shareRequest } from '$lib/share-flow.js' import MySharesDialog from './MySharesDialog.svelte' import Icon from './Icon.svelte' - import DockerLaunchModal from './DockerLaunchModal.svelte' - import CreateTableDialog from './CreateTableDialog.svelte' import CreateSchemaDialog from './CreateSchemaDialog.svelte' import GenerateSqlDialog from './GenerateSqlDialog.svelte' import { genSelectStar } from '$lib/sql-generate.js' @@ -97,7 +91,6 @@ import { buildBatchUpdateSql } from '$lib/sql-batch-update.js' import { buildSearchQuery, searchOptionsSupported, supportedSearchOptions } from '$lib/search-options.js' import Onboarding from './Onboarding.svelte' - import SettingsDialog from './SettingsDialog.svelte' import KeyboardShortcutsDialog from './KeyboardShortcutsDialog.svelte' import LeaderPanel from './LeaderPanel.svelte' import { requestChat } from '$lib/stores/ai-chat-bridge.js' @@ -656,6 +649,48 @@ let showDisconnectDialog = $state(false) let showAiModelSettings = $state(false) let showProGate = $state(false) + // ── Dialogs loaded on first use ───────────────────────────────────────── + // Settings, the command palette, the AI settings and a few one-off dialogs + // were in the startup bundle (about 210KB of the 1.3MB entry) although none + // of them shows at launch. Each now mounts the first time it opens and stays + // mounted after, so closing keeps its exit animation. They are also fetched + // once the window is idle (below), so the first open is still instant. + // Keep these specifiers identical to the {#await import()} blocks in the + // markup so Vite resolves both to the same chunk. + const lazyDialogs = { + settings: () => import('./SettingsDialog.svelte'), + aiSettings: () => import('./AiSettingsDialog.svelte'), + palette: () => import('./CommandPalette.svelte'), + createTable: () => import('./CreateTableDialog.svelte'), + importData: () => import('./ImportDataDialog.svelte'), + share: () => import('./ShareDialog.svelte'), + docker: () => import('./DockerLaunchModal.svelte'), + } + let dialogMounted = $state({ settings: false, aiSettings: false, palette: false, createTable: false, importData: false, share: false, docker: false }) + // Mount on first open; never unmount (closing keeps its animation). + $effect(() => { + if (showSettingsModal) dialogMounted.settings = true + if (showAiModelSettings) dialogMounted.aiSettings = true + if (commandOpen) dialogMounted.palette = true + if (showCreateTableDialog) dialogMounted.createTable = true + if (importDataOpen) dialogMounted.importData = true + if ($shareRequest) dialogMounted.share = true + if (showDockerModal) dialogMounted.docker = true + }) + onMount(() => { + // The palette and Settings first: they are the ones a shortcut opens. + const order = [lazyDialogs.palette, lazyDialogs.settings, lazyDialogs.aiSettings, lazyDialogs.share, lazyDialogs.createTable, lazyDialogs.importData, lazyDialogs.docker] + let i = 0 + let cancel = () => {} + const pump = () => { + if (i >= order.length) return + order[i++]().catch(() => {}) + cancel = whenIdle(pump, { timeout: 3000 }) + } + cancel = whenIdle(pump, { timeout: 3000 }) + return () => cancel() + }) + let commandOpen = $state(false) let commandPage = $state(/** @type {'root'|'docker'|'connections'|'tables'|'pages'} */ ('root')) // Reset to the root view whenever the palette closes so generic openers @@ -9786,6 +9821,8 @@ let rowSearch = $state('') error={dbInfoError} /> _sessions.get(k.key)?.label ?? 'database')} ondisconnect={() => handleDisconnect()} ondisconnectall={() => void handleDisconnectAll()} /> +{#if dialogMounted.createTable} + {#await lazyDialogs.createTable() then { default: CreateTableDialog }} + {/await} +{/if} { if (aiMode) exitAiMode(); void openQueryInEditor(sql) }} /> +{#if dialogMounted.docker} + {#await lazyDialogs.docker() then { default: DockerLaunchModal }} + {/await} +{/if} +{#if dialogMounted.settings} + {#await lazyDialogs.settings() then { default: SettingsDialog }} openExtensionsTab()} onopenlicense={() => openLicenseTab()} /> + {/await} +{/if} +{#if dialogMounted.importData} + {#await lazyDialogs.importData() then { default: ImportDataDialog }} reloadTableFromQuery(false)} /> + {/await} +{/if} +{#if dialogMounted.aiSettings} + {#await lazyDialogs.aiSettings() then { default: AiSettingsDialog }} + {/await} +{/if} @@ -9860,7 +9915,11 @@ let rowSearch = $state('') lead={crashReport ? 'Stroke closed by itself last time. This report holds the error and where in Stroke it happened, nothing else; read it over before you send it.' : ''} /> +{#if dialogMounted.share} + {#await lazyDialogs.share() then { default: ShareDialog }} + {/await} +{/if} @@ -9912,6 +9971,8 @@ let rowSearch = $state('') /> +{#if dialogMounted.palette} + {#await lazyDialogs.palette() then { default: CommandPalette }} + {/await} +{/if}