fix(autocomplete): reactively refresh lora syntax format cache on settings change (#917)

The autocomplete module cached the lora_syntax_format value at module load
but never updated it when the setting changed, causing autocomplete to
always insert legacy A1111 format even when 'full path' was configured.

- Expose refreshLoraSyntaxFormat() to re-fetch the setting from the API
- Listen for cross-tab 'storage' events to react to settings saved in
  the standalone web UI
- Listen for 'visibilitychange' to refresh when the user switches back
  to the ComfyUI tab
- Wire SettingsManager.saveSetting() to set a localStorage key when
  lora_syntax_format changes, triggering the storage event
This commit is contained in:
Will Miao
2026-05-25 22:03:56 +08:00
parent 5e1cf68bbd
commit 5dd8b96422
2 changed files with 47 additions and 4 deletions

View File

@@ -295,6 +295,13 @@ export class SettingsManager {
// Update state // Update state
state.global.settings[settingKey] = value; state.global.settings[settingKey] = value;
if (settingKey === 'lora_syntax_format') {
try {
localStorage.setItem('lm:lora-syntax-format-changed', Date.now().toString());
} catch (_) {
}
}
if (!this.isBackendSetting(settingKey)) { if (!this.isBackendSetting(settingKey)) {
return; return;
} }

View File

@@ -105,14 +105,16 @@ function removeLoraExtension(fileName = '') {
} }
let _loraSyntaxFormatCache = null; let _loraSyntaxFormatCache = null;
let _loraSyntaxFormatRefreshPromise = null;
function _getLoraSyntaxFormat() { function _getLoraSyntaxFormat() {
if (typeof _loraSyntaxFormatCache !== 'undefined' && _loraSyntaxFormatCache !== null) { if (_loraSyntaxFormatCache !== null) {
return _loraSyntaxFormatCache; return _loraSyntaxFormatCache;
} }
return 'legacy'; return 'legacy';
} }
async function _initLoraSyntaxFormat() {
async function _fetchLoraSyntaxFormat() {
try { try {
const response = await api.fetchApi('/lm/settings'); const response = await api.fetchApi('/lm/settings');
if (response.ok) { if (response.ok) {
@@ -124,10 +126,44 @@ async function _initLoraSyntaxFormat() {
} }
} catch (e) { } catch (e) {
} }
_loraSyntaxFormatCache = 'legacy'; if (_loraSyntaxFormatCache === null) {
_loraSyntaxFormatCache = 'legacy';
}
}
function _triggerBackgroundRefresh() {
if (_loraSyntaxFormatRefreshPromise) {
return;
}
_loraSyntaxFormatRefreshPromise = _fetchLoraSyntaxFormat().finally(() => {
_loraSyntaxFormatRefreshPromise = null;
});
}
async function refreshLoraSyntaxFormat() {
await _fetchLoraSyntaxFormat();
}
function _initLoraSyntaxFormat() {
_triggerBackgroundRefresh();
} }
_initLoraSyntaxFormat(); _initLoraSyntaxFormat();
function _initLoraSyntaxFormatReactive() {
window.addEventListener('storage', (e) => {
if (e.key === 'lm:lora-syntax-format-changed') {
_triggerBackgroundRefresh();
}
});
document.addEventListener('visibilitychange', () => {
if (document.visibilityState === 'visible') {
_triggerBackgroundRefresh();
}
});
}
_initLoraSyntaxFormatReactive();
function parseSearchTokens(term = '') { function parseSearchTokens(term = '') {
const include = []; const include = [];
const exclude = []; const exclude = [];
@@ -2791,4 +2827,4 @@ class AutoComplete {
} }
} }
export { AutoComplete }; export { AutoComplete, refreshLoraSyntaxFormat };