ui: apply ui_settings on first visit in router mode (#29668)
This commit is contained in:
1 parent
c811cb8f0a
commit
4f92965a7b
2 files changed
+20
-5
No files matched your search
@@ -283,10 +283,12 @@ class SettingsStore {
|
||||
*/
|
||||
syncWithServerDefaults(): void {
|
||||
const propsDefaults = this.getServerDefaults();
|
||||
|
||||
if (Object.keys(propsDefaults).length === 0) return;
|
||||
|
||||
const uiSettings = serverStore.uiSettings;
|
||||
|
||||
// a router main instance reports no sampling defaults, but its
|
||||
// ui_settings still need the first visit pass below
|
||||
if (Object.keys(propsDefaults).length === 0 && !(uiSettings && this.isFirstVisit)) return;
|
||||
|
||||
const uiSettingsKeys = new Set(uiSettings ? Object.keys(uiSettings) : []);
|
||||
|
||||
for (const [key, propsValue] of Object.entries(propsDefaults)) {
|
||||
|
||||
@@ -3,12 +3,15 @@ import { serverStore } from '$lib/stores/server.svelte';
|
||||
import { settingsStore } from '$lib/stores/settings/index.svelte';
|
||||
import { beforeEach, describe, expect, it } from 'vitest';
|
||||
|
||||
function mockProps(uiSettings: Record<string, string | number | boolean>) {
|
||||
function mockProps(
|
||||
uiSettings: Record<string, string | number | boolean>,
|
||||
params: Record<string, number> = { temperature: 0.8 }
|
||||
) {
|
||||
Object.defineProperty(serverStore, 'props', {
|
||||
configurable: true,
|
||||
get: () =>
|
||||
({
|
||||
default_generation_settings: { params: { temperature: 0.8 } },
|
||||
default_generation_settings: { params },
|
||||
ui_settings: uiSettings
|
||||
}) as unknown as typeof serverStore.props
|
||||
});
|
||||
@@ -28,6 +31,16 @@ describe('server ui_settings application semantics', () => {
|
||||
expect(settingsStore.config.theme).toBe('dark');
|
||||
});
|
||||
|
||||
it('applies the admin defaults when /props carries no sampling defaults', () => {
|
||||
settingsStore.initialize();
|
||||
// router mode: the main instance answers /props with empty params
|
||||
mockProps({ theme: 'dark' }, {});
|
||||
|
||||
settingsStore.syncWithServerDefaults();
|
||||
|
||||
expect(settingsStore.config.theme).toBe('dark');
|
||||
});
|
||||
|
||||
it('never reapplies on later loads: the user config diverges freely', () => {
|
||||
settingsStore.initialize();
|
||||
settingsStore.updateConfig('theme', 'light');
|
||||
|
||||
Reference in new issue
Block a user