From 788a66e0ed404ae322261c51ff3bbb3c6e51ecf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nathana=C3=ABl=20HANNEBERT?= Date: Thu, 2 Jul 2026 11:57:42 +0200 Subject: [PATCH] fix: apply default model on fresh page load when models load after init MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit initNewChat() runs on mount via page.subscribe, but $models is loaded asynchronously and the Chat component mounts before that fetch resolves. When initNewChat() runs against an empty $models list, none of its precedence branches (URL/folder/session/settings/default) match and selectedModels is left as ['']. Nothing re-applies the default afterwards, so the configured default model (DEFAULT_MODELS / admin Models defaults) is never selected on a fresh full-page load — only via in-app New Chat once models have loaded. Add a guarded reactive statement that re-applies the default selection once models arrive, for a brand-new chat that still has no valid model selected. It reuses the same availableModels/defaultModels precedence as initNewChat and only fires when the selection is empty and there is no URL model param, so it never overrides a manual pick, a loaded chat, or a folder selection. --- src/lib/components/chat/Chat.svelte | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index 869ab7a880..9647905e0d 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -888,6 +888,36 @@ savedModelIds(); } + // initNewChat() runs on mount via page.subscribe, but $models is loaded + // asynchronously (getModels() in the app layout) and this component mounts before + // that resolves. So initNewChat() can run while $models is still empty, in which + // case none of its precedence branches match and selectedModels is left as ['']. + // Nothing else re-applies the default afterwards, so the default model never gets + // selected on a fresh page load. Re-apply the default once models arrive, for a + // brand-new chat that still has no valid model selected. + $: if ( + chatIdProp === '' && + $models.length > 0 && + selectedModels.length === 1 && + selectedModels[0] === '' && + !$page.url.searchParams.get('models') && + !$page.url.searchParams.get('model') + ) { + const availableModels = $models + .filter((m) => !(m?.info?.meta?.hidden ?? false)) + .map((m) => m.id); + const defaultModels = $config?.default_models ? $config.default_models.split(',') : []; + let next = ($settings?.models?.length ? $settings.models : defaultModels).filter((id) => + availableModels.includes(id) + ); + if (next.length === 0 && availableModels.length > 0) { + next = [availableModels[0]]; + } + if (next.length > 0) { + selectedModels = next; + } + } + const stopAudio = () => { try { speechSynthesis.cancel();