From fc979b6841a959fd7663212ecfde2b8303f24a57 Mon Sep 17 00:00:00 2001 From: MT-Mint <798521692@qq.com> Date: Wed, 13 May 2026 16:29:34 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9C=AC=E5=9C=B0=E6=B8=85=E7=90=86?= =?UTF-8?q?=E6=97=A7=E7=94=A8=E6=88=B7=E9=81=97=E7=95=99=E7=9A=84localstor?= =?UTF-8?q?age?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/core/settings/local.ts | 30 ++++------------ frontend/tests/e2e/local-settings.spec.ts | 43 +++++++++++++++++++++++ 2 files changed, 50 insertions(+), 23 deletions(-) create mode 100644 frontend/tests/e2e/local-settings.spec.ts diff --git a/frontend/src/core/settings/local.ts b/frontend/src/core/settings/local.ts index fc6a5ce2..29dca6a1 100644 --- a/frontend/src/core/settings/local.ts +++ b/frontend/src/core/settings/local.ts @@ -32,32 +32,16 @@ export interface LocalSettings { }; } +function clearLocalSettingsStorage() { + localStorage.removeItem(LOCAL_SETTINGS_KEY); +} + export function getLocalSettings(): LocalSettings { if (typeof window === "undefined") { return DEFAULT_LOCAL_SETTINGS; } - const json = localStorage.getItem(LOCAL_SETTINGS_KEY); - try { - if (json) { - const settings = JSON.parse(json); - const mergedSettings = { - ...DEFAULT_LOCAL_SETTINGS, - context: { - ...DEFAULT_LOCAL_SETTINGS.context, - ...settings.context, - }, - layout: { - ...DEFAULT_LOCAL_SETTINGS.layout, - ...settings.layout, - }, - notification: { - ...DEFAULT_LOCAL_SETTINGS.notification, - ...settings.notification, - }, - }; - return mergedSettings; - } - } catch {} + + clearLocalSettingsStorage(); return DEFAULT_LOCAL_SETTINGS; } @@ -65,6 +49,6 @@ export function saveLocalSettings(settings: LocalSettings) { void settings; // 注释了,因为本地存储会污染模型配置 console.log("localStorage设置,已经注释"); - localStorage.removeItem(LOCAL_SETTINGS_KEY); + clearLocalSettingsStorage(); // localStorage.setItem(LOCAL_SETTINGS_KEY, JSON.stringify(settings)); } diff --git a/frontend/tests/e2e/local-settings.spec.ts b/frontend/tests/e2e/local-settings.spec.ts new file mode 100644 index 00000000..77059f8d --- /dev/null +++ b/frontend/tests/e2e/local-settings.spec.ts @@ -0,0 +1,43 @@ +import { expect, test } from "@playwright/test"; + +import { invalidNewChatUrl } from "./support/chat-helpers"; + +const LOCAL_SETTINGS_KEY = "deerflow.local-settings"; + +test.describe("本地设置清理", () => { + test("禁用持久化后会在进入工作台时清除历史 localStorage 设置", async ({ + page, + }) => { + await page.addInitScript( + ({ key, value }: { key: string; value: string }) => { + window.localStorage.setItem(key, value); + }, + { + key: LOCAL_SETTINGS_KEY, + value: JSON.stringify({ + context: { + model_name: "gpt-5", + mode: "pro", + reasoning_effort: "high", + }, + layout: { + sidebar_collapsed: true, + }, + notification: { + enabled: false, + }, + }), + }, + ); + + await page.goto(invalidNewChatUrl()); + await expect(page.locator("textarea[name='message']")).toBeVisible(); + + await expect + .poll( + () => page.evaluate((key) => window.localStorage.getItem(key), LOCAL_SETTINGS_KEY), + { message: "expected deprecated local settings storage to be cleared" }, + ) + .toBeNull(); + }); +});