Fix settings and env config stuck on loading via SSR form render
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -56,13 +56,29 @@
|
||||
return d[key] !== false;
|
||||
}
|
||||
|
||||
async function loadDisplayPrefsForm() {
|
||||
const pane = document.querySelector('.embed-tab-pane.is-active-pane') || document;
|
||||
const root = pane.querySelector ? pane.querySelector("#display-prefs-form") : document.getElementById("display-prefs-form");
|
||||
if (!root) {
|
||||
const fallback = document.getElementById("display-prefs-form");
|
||||
if (!fallback) return;
|
||||
return loadDisplayPrefsFormIn(fallback);
|
||||
function displayPrefsRoot() {
|
||||
const pane = document.querySelector(".embed-tab-pane.is-active-pane");
|
||||
if (pane) {
|
||||
const inPane = pane.querySelector("#display-prefs-form");
|
||||
if (inPane) return inPane;
|
||||
}
|
||||
return document.getElementById("display-prefs-form");
|
||||
}
|
||||
|
||||
function envConfigGrid() {
|
||||
const pane = document.querySelector(".embed-tab-pane.is-active-pane");
|
||||
if (pane) {
|
||||
const inPane = pane.querySelector("#env-config-grid");
|
||||
if (inPane) return inPane;
|
||||
}
|
||||
return document.getElementById("env-config-grid");
|
||||
}
|
||||
|
||||
async function loadDisplayPrefsForm(force) {
|
||||
const root = displayPrefsRoot();
|
||||
if (!root) return;
|
||||
if (!force && root.getAttribute("data-prefs-ssr") === "1" && root.querySelector("[data-pref-key]")) {
|
||||
return;
|
||||
}
|
||||
return loadDisplayPrefsFormIn(root);
|
||||
}
|
||||
@@ -96,6 +112,7 @@
|
||||
section.appendChild(grid);
|
||||
root.appendChild(section);
|
||||
});
|
||||
root.setAttribute("data-prefs-ssr", "1");
|
||||
} catch (e) {
|
||||
root.innerHTML = '<span class="err">' + (e.message || "加载失败") + "</span>";
|
||||
}
|
||||
@@ -103,8 +120,9 @@
|
||||
|
||||
async function saveDisplayPrefs() {
|
||||
const status = document.getElementById("display-prefs-status");
|
||||
const root = displayPrefsRoot();
|
||||
const display = {};
|
||||
document.querySelectorAll("#display-prefs-form input[data-pref-key]").forEach((cb) => {
|
||||
(root ? root.querySelectorAll("input[data-pref-key]") : []).forEach((cb) => {
|
||||
display[cb.dataset.prefKey] = !!cb.checked;
|
||||
});
|
||||
try {
|
||||
@@ -165,12 +183,13 @@
|
||||
return card;
|
||||
}
|
||||
|
||||
async function loadEnvConfig() {
|
||||
const pane = document.querySelector('.embed-tab-pane.is-active-pane') || document;
|
||||
const grid = pane.querySelector ? pane.querySelector("#env-config-grid") : document.getElementById("env-config-grid");
|
||||
const target = grid || document.getElementById("env-config-grid");
|
||||
if (!target) return;
|
||||
return loadEnvConfigIn(target);
|
||||
async function loadEnvConfig(force) {
|
||||
const grid = envConfigGrid();
|
||||
if (!grid) return;
|
||||
if (!force && grid.getAttribute("data-env-ssr") === "1" && grid.querySelector("[data-env-key]")) {
|
||||
return;
|
||||
}
|
||||
return loadEnvConfigIn(grid);
|
||||
}
|
||||
|
||||
async function loadEnvConfigIn(grid) {
|
||||
@@ -192,14 +211,17 @@
|
||||
card.appendChild(inner);
|
||||
grid.appendChild(card);
|
||||
});
|
||||
grid.setAttribute("data-env-ssr", "1");
|
||||
} catch (e) {
|
||||
grid.innerHTML = '<span class="err">' + (e.message || "加载失败") + "</span>";
|
||||
}
|
||||
}
|
||||
|
||||
function collectEnvValues() {
|
||||
const grid = envConfigGrid();
|
||||
const values = {};
|
||||
document.querySelectorAll(".env-field-input[data-env-key]").forEach((el) => {
|
||||
const scope = grid || document;
|
||||
scope.querySelectorAll(".env-field-input[data-env-key]").forEach((el) => {
|
||||
values[el.dataset.envKey] = el.value;
|
||||
});
|
||||
return values;
|
||||
@@ -276,15 +298,15 @@
|
||||
const eRestart = document.getElementById("env-config-save-restart");
|
||||
if (eRestart) eRestart.addEventListener("click", () => saveEnvConfig(true));
|
||||
const eReload = document.getElementById("env-config-reload");
|
||||
if (eReload) eReload.addEventListener("click", loadEnvConfig);
|
||||
if (eReload) eReload.addEventListener("click", () => loadEnvConfig(true));
|
||||
const pSave = document.getElementById("pwd-save-btn");
|
||||
if (pSave) pSave.addEventListener("click", savePassword);
|
||||
}
|
||||
|
||||
function initPage() {
|
||||
bindEvents();
|
||||
if (document.getElementById("display-prefs-form")) loadDisplayPrefsForm();
|
||||
if (document.getElementById("env-config-grid")) loadEnvConfig();
|
||||
loadDisplayPrefsForm(false);
|
||||
loadEnvConfig(false);
|
||||
if (global.__INSTANCE_DISPLAY__) applyDisplayToNav(global.__INSTANCE_DISPLAY__);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user