Skip to content

Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.

fix(frontend): prevent white screen from corrupted localStorage

Binks Riverton85f5cd760b93
diff --git a/frontend/src/main.ts b/frontend/src/main.ts
index 9b87ece0b..522ded435 100644
--- a/frontend/src/main.ts
+++ b/frontend/src/main.ts
@@ -27,6 +27,11 @@ initFont();
const app = createApp(App);
+// 全局错误处理:捕获未处理的组件错误,防止白屏
+app.config.errorHandler = (err, instance, info) => {
+ console.error("[WeKnora] Unhandled Vue error:", err, "\nComponent:", instance, "\nInfo:", info);
+};
+
app.use(TDesign);
app.use(createPinia());
app.use(router);
diff --git a/frontend/src/stores/settings.ts b/frontend/src/stores/settings.ts
index 9af40c66f..c56c0faab 100644
--- a/frontend/src/stores/settings.ts
+++ b/frontend/src/stores/settings.ts
@@ -112,15 +112,25 @@ const defaultSettings: Settings = {
/** Keep builtin agent id and isAgentEnabled in sync after localStorage reload. */
function loadAndReconcileSettings(): Settings {
- const loaded = JSON.parse(
- localStorage.getItem("WeKnora_settings") || JSON.stringify(defaultSettings),
- ) as Settings;
+ let loaded: Settings;
+ try {
+ const raw = localStorage.getItem("WeKnora_settings");
+ loaded = raw ? (JSON.parse(raw) as Settings) : { ...defaultSettings };
+ } catch (e) {
+ console.error("[settings] Failed to parse WeKnora_settings from localStorage, resetting to defaults:", e);
+ localStorage.removeItem("WeKnora_settings");
+ return { ...defaultSettings };
+ }
loaded.selectedTags ||= [];
loaded.selectedMCPServices ||= [];
loaded.selectedSkills ||= loaded.selectedTools || [];
loaded.selectedFileKbMap ||= {};
if (reconcileBuiltinAgentMode(loaded)) {
- localStorage.setItem("WeKnora_settings", JSON.stringify(loaded));
+ try {
+ localStorage.setItem("WeKnora_settings", JSON.stringify(loaded));
+ } catch {
+ /* quota exceeded — non-critical */
+ }
}
return loaded;
}