fix(chat): mount the model list only while it is open
reka-ui mounts every item of a closed Select to resolve the selected label, so opening the More menu rendered the whole model catalogue first. With 400 models the menu took about 400 ms to open; it now takes about 30 ms.
This commit is contained in:
1 file changed
+16
-7
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from "vue";
|
||||
import { computed, ref } from "vue";
|
||||
|
||||
import {
|
||||
Select,
|
||||
@@ -26,6 +26,12 @@ const DEFAULT = "__default__";
|
||||
|
||||
const modelValue = computed(() => selectedModel.value || DEFAULT);
|
||||
|
||||
// reka-ui mounts every item of a closed Select to find the selected label, so a
|
||||
// catalogue of hundreds of models stalled the menu that holds this control.
|
||||
// The items mount only while the list is open and the label is written here.
|
||||
const listOpen = ref(false);
|
||||
const label = computed(() => (selectedModel.value ? selectedModel.value : "Default"));
|
||||
|
||||
// The server groups models by provider; one flat list stands in when it does not.
|
||||
const groups = computed(() => {
|
||||
const grouped = selectorData.value.models_by_provider || {};
|
||||
@@ -44,18 +50,21 @@ const choosable = computed(() => groups.value.some(([, models]) => models.length
|
||||
<span v-if="selectorData.model_error" class="text-caption text-destructive">{{ selectorData.model_error }}</span>
|
||||
<Select
|
||||
v-if="choosable"
|
||||
v-model:open="listOpen"
|
||||
:model-value="modelValue"
|
||||
@update:model-value="setModel($event === DEFAULT ? '' : String($event ?? ''))"
|
||||
>
|
||||
<SelectTrigger size="sm" class="w-full" aria-label="Model">
|
||||
<SelectValue />
|
||||
<SelectValue>{{ label }}</SelectValue>
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem :value="DEFAULT">Default</SelectItem>
|
||||
<SelectGroup v-for="[provider, models] in groups" :key="provider">
|
||||
<SelectLabel v-if="provider">{{ provider }}</SelectLabel>
|
||||
<SelectItem v-for="model in models" :key="model" :value="model">{{ model }}</SelectItem>
|
||||
</SelectGroup>
|
||||
<template v-if="listOpen">
|
||||
<SelectItem :value="DEFAULT">Default</SelectItem>
|
||||
<SelectGroup v-for="[provider, models] in groups" :key="provider">
|
||||
<SelectLabel v-if="provider">{{ provider }}</SelectLabel>
|
||||
<SelectItem v-for="model in models" :key="model" :value="model">{{ model }}</SelectItem>
|
||||
</SelectGroup>
|
||||
</template>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user