fix(canvas): 主题存储 - 修复非法 theme 值导致 /create 崩溃 (#155)

useThemeStore persist 无 merge 校验,坏 session/后端同步失败时可能将
非法 theme 值写入 localStorage,导致 canvasThemes[非法值] 为 undefined,
渲染时访问 theme.node 抛出 "Cannot read properties of undefined
(reading 'node')",/create 页面崩溃。

4 层防线(只加校验,不回退代码):
- useThemeStore persist merge 白名单校验,非法值回退 dark
- useThemeStore setTheme 写入前校验,防止同步路径绕过 merge
- normalizeConfigSnapshot 入口兜底 undefined/partial 快照
- ModelPicker 与 CanvasResourceMentionTextarea 消费端加 fallback

Closes #154

Co-authored-by: sikongyue <3155157671@qq.com>
This commit is contained in:
爱笑的毛毛虫andsikongyue authored and GitHub committed 2026-08-06 08:32:27 +08:00
1 parent a7eb4c3bd5
commit 6671c331e3
4 files changed
+25 -7

No files matched your search

+3 -2
View File
@@ -279,8 +279,9 @@ export const useConfigStore = create<ConfigStore>()(
),
);
export function normalizeConfigSnapshot(snapshot: ConfigStoreSnapshot) {
const persistedConfig = (snapshot.config || {}) as Partial<AiConfig>;
export function normalizeConfigSnapshot(snapshot: ConfigStoreSnapshot | undefined = {}) {
// 坏存储/旧版本快照可能是 undefined 或缺 config,兜底为 defaultConfig,保证渲染不崩溃
const persistedConfig = (snapshot?.config || {}) as Partial<AiConfig>;
const config = { ...defaultConfig, ...persistedConfig };
const hasPersistedChannels = Array.isArray(persistedConfig.channels);
if (!hasPersistedChannels) config.channels = [];