Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

fix(web): persist memo sort preference across restarts (#757)

LuoQianhonga0ed947911ca
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 06724f7e..f9b1bea6 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -125,5 +125,5 @@ jobs:
- name: Install Chromium and WebKit
run: bun run test:e2e:install
- - name: Test notebook appearance in both browsers
- run: bun run test:e2e tests/e2e/notebook-appearance.spec.ts
+ - name: Test notebook appearance and memo sort persistence
+ run: bun run test:e2e tests/e2e/notebook-appearance.spec.ts tests/e2e/memo-sort-preference.spec.ts
diff --git a/apps/web/src/components/WorkspaceApp.tsx b/apps/web/src/components/WorkspaceApp.tsx
index 867f8749..5f99a662 100644
--- a/apps/web/src/components/WorkspaceApp.tsx
+++ b/apps/web/src/components/WorkspaceApp.tsx
@@ -83,6 +83,8 @@ import {
getMemoIdsNeedingMove,
getCreateMemoNotebookId,
resolveSelectionMoveTargetNotebookId,
+ readMemoSortPreference,
+ writeMemoSortPreference,
} from "@/lib/app-helpers";
import { useBrowserBackLayer } from "@/lib/app-hooks";
import { sortDesktopTitleMemoSummaries, updateMemoSummaryInLists } from "@/lib/memo-list-cache";
@@ -566,7 +568,7 @@ export const WorkspaceApp = ({
const [noteOutlineToggleToken, setNoteOutlineToggleToken] = useState(0);
const [search, setSearch] = useState("");
const [memoFilterMode, setMemoFilterMode] = useState<MemoFilterMode>("all");
- const [memoSortMode, setMemoSortMode] = useState<MemoSortMode>("updated-desc");
+ const [memoSortMode, setMemoSortMode] = useState<MemoSortMode>(readMemoSortPreference);
const [mobileEditorReturnPreview, setMobileEditorReturnPreview] = useState<MobileEditorReturnPreview | null>(() =>
readMobileEditorReturnPreview(route.mobileEditorReturnMemoId)
);
@@ -2677,6 +2679,7 @@ export const WorkspaceApp = ({
const handleSortModeChange = (mode: MemoSortMode) => {
if (mode !== memoSortMode) clearPendingMemoSelection();
setMemoSortMode(mode);
+ writeMemoSortPreference(mode);
};
const clearHiddenMobileSearch = () => {
diff --git a/apps/web/src/lib/app-helpers.ts b/apps/web/src/lib/app-helpers.ts
index 0588e499..59fc3f2d 100644
--- a/apps/web/src/lib/app-helpers.ts
+++ b/apps/web/src/lib/app-helpers.ts
@@ -155,6 +155,7 @@ export const EDITOR_PHONE_PREVIEW_STORAGE_KEY = "edgeever.editor.phonePreviewOpe
export const EDITOR_PHONE_PREVIEW_FOLLOW_STORAGE_KEY = "edgeever.editor.phonePreviewFollow";
export const MEMO_LIST_DENSITY_STORAGE_KEY = "edgeever.memoListDensity";
export const MEMO_LIST_WIDTH_STORAGE_KEY = "edgeever.memoListWidth";
+export const MEMO_SORT_STORAGE_KEY = "edgeever.memoSort";
export const NOTEBOOK_SORT_STORAGE_KEY = "edgeever.notebookSort";
export const NOTEBOOK_TREE_COLLAPSED_IDS_STORAGE_KEY = "edgeever.notebookTreeCollapsedIds:v1";
export const NOTEBOOK_SECTION_COLLAPSED_STORAGE_KEY = "edgeever.notebookSectionCollapsed";
@@ -178,6 +179,7 @@ export const getMemoSortOptions = (t: TFunction): Array<{ value: MemoSortMode; l
{ value: "title-desc", label: t("options.memoSort.titleDesc") },
];
+const MEMO_SORT_VALUES: MemoSortMode[] = ["updated-desc", "created-desc", "title-asc", "title-desc"];
const NOTEBOOK_SORT_VALUES: NotebookSortMode[] = ["custom", "name-asc", "memo-count-desc", "updated-desc"];
export const getNotebookSortOptions = (t: TFunction): Array<{ value: NotebookSortMode; label: string }> => [
@@ -515,6 +517,23 @@ export const writeMemoListWidthPreference = (width: number) => {
}
};
+export const readMemoSortPreference = (): MemoSortMode => {
+ try {
+ const sortMode = window.localStorage.getItem(MEMO_SORT_STORAGE_KEY);
+ return MEMO_SORT_VALUES.includes(sortMode as MemoSortMode) ? (sortMode as MemoSortMode) : "updated-desc";
+ } catch {
+ return "updated-desc";
+ }
+};
+
+export const writeMemoSortPreference = (sortMode: MemoSortMode) => {
+ try {
+ window.localStorage.setItem(MEMO_SORT_STORAGE_KEY, sortMode);
+ } catch {
+ // Local storage can be unavailable in private or restricted browser contexts.
+ }
+};
+
export const readNotebookSortPreference = (): NotebookSortMode => {
try {
const sortMode = window.localStorage.getItem(NOTEBOOK_SORT_STORAGE_KEY);
diff --git a/docs/changes/2026-11-02-persist-memo-sort.md b/docs/changes/2026-11-02-persist-memo-sort.md
new file mode 100644
index 00000000..818cda18
--- /dev/null
+++ b/docs/changes/2026-11-02-persist-memo-sort.md
@@ -0,0 +1,31 @@
+# Remember the last memo sort mode
+
+[简体中文](2026-11-02-persist-memo-sort.zh-CN.md)
+
+## Problem and outcome
+
+The desktop/Web workspace initializes `memoSortMode` to `updated-desc` on every mount and never saves the selected value. Reopening the app therefore loses the choice even when the user did not change the sort setting. Remember the last selection on the current device, using the same local-preference mechanism as notebook sorting.
+
+Use local persistence because the goal is to remember a device's display preference, without requiring cross-device consistency. Reuse the existing `localStorage` mechanism rather than introducing server-side settings tables, endpoints or a server upgrade dependency.
+
+## Allowed changes and acceptance
+
+1. Persist the existing four modes (`updated-desc`, `created-desc`, `title-asc`, `title-desc`) in `edgeever.memoSort`. Keep one workspace-wide choice per browser origin/desktop profile, matching the current in-memory scope; do not introduce per-notebook/account settings or cloud synchronization.
+2. Read the preference in the workspace state's lazy initializer, before the first list query. Write once when the user chooses a sort option, not during note saves, rendering, polling or startup effects. Keep the existing sorting, cache and pagination algorithms, including the #750 repair.
+3. Missing/invalid stored values retain the existing `updated-desc` default. If local storage is unavailable, reading uses that default and writing does not block the in-session selection. Do not change or clear other preferences.
+4. Add a focused browser regression before implementing the fix: select each mode, reopen the workspace and check the restored selection; any initial network list queries must use that mode (an initialized local mirror can serve lists without a request). Cover an absent/invalid preference and unavailable preference storage. Reuse the existing browser CI job for this test without adding runners or changing check identities. Run the required Web/mobile type checks and Web build.
+5. Reuse the confirmed official v2.16.1 restart behavior as the baseline. Exercise a desktop candidate across a full quit/relaunch with a persistent profile, and distinguish actual macOS/Cloudflare validation from browser reloads, package/release acceptance and unverified platforms. Keep user notes, existing workspaces and backup settings intact.
+
+## Boundaries, risks and recovery
+
+The benefit is avoiding a manual sort reset on every launch. The change only adds a small local preference read at workspace initialization and a write after an explicit selection; it adds no database/network read, scan, migration, dependency or background task. Filtering, notebook selection, account/authentication, native Android/iOS clients, backups, installation and updates are unchanged.
+
+The main failure mode is an unavailable local preference store, in which case the current session remains usable and later launches use the old default. Revert the preference wiring to roll back; older versions ignore the additional key and no data migration is required. Windows/Linux native UI and packaged cross-version validation must be reported separately from macOS/browser checks.
+
+## Implementation and acceptance
+
+- `app-helpers.ts` reads, validates and writes the preference; `WorkspaceApp.tsx` connects it to state initialization and the existing sort-selection callback. Sorting, cache, pagination and server code are unchanged. The browser regression uses the existing CI job without additional runners or dependencies. The actual changes match the scope above.
+- Before the fix, the focused browser case reproduced the missing preference after selecting A–Z. After the fix, all seven Chromium end-to-end cases passed, covering reopening with each sort mode, absent/invalid values, unavailable storage and preservation of existing preferences.
+- The macOS candidate reused the official v2.16.1 native main process and Sidecar, loaded the candidate Web build through a file entry and connected to a real Cloudflare workspace. After choosing A–Z, fully quitting and relaunching, the menu retained A–Z and the workspace showed a synced state. The official client was restored afterward; the installed package was not replaced.
+- `bun run typecheck`, `bun run typecheck:mobile`, `EDGE_EVER_DESKTOP_BUILD=1 bun run build:web` and lint for the changed files passed.
+- Windows/Linux native UI, packaged cross-version upgrades and remote CI remain unverified. This change has not deployed the server or released a client.
diff --git a/docs/changes/2026-11-02-persist-memo-sort.zh-CN.md b/docs/changes/2026-11-02-persist-memo-sort.zh-CN.md
new file mode 100644
index 00000000..2577a786
--- /dev/null
+++ b/docs/changes/2026-11-02-persist-memo-sort.zh-CN.md
@@ -0,0 +1,31 @@
+# 记住上次选择的笔记排序方式
+
+[English](2026-11-02-persist-memo-sort.md)
+
+## 问题与目标
+
+桌面/Web 工作区每次挂载都把 `memoSortMode` 初始化为 `updated-desc`,用户选择后没有保存。因此重新打开应用时,即使没有主动修改排序,也会丢失上次选择。复用笔记本排序的本地偏好机制,记住当前设备上的最后一次选择。
+
+选择本地持久化,因为本次目标是记住当前设备的显示偏好,不需要多端一致;复用现有 `localStorage` 即可,不引入服务端设置表、接口或升级依赖。
+
+## 允许变更与验收
+
+1. 将现有四种排序(`updated-desc`、`created-desc`、`title-asc`、`title-desc`)保存到 `edgeever.memoSort`。沿用当前内存状态的作用范围:每个浏览器来源/桌面配置一项工作区通用偏好,不新增逐笔记本、逐账号设置或云同步。
+2. 工作区状态通过惰性初始化读取偏好,在首次列表查询之前确定排序。仅在用户选择排序选项时写入一次,不在保存笔记、渲染、轮询或启动 effect 中写入。排序、缓存和分页算法保持不变,保留 #750 的修复。
+3. 没有偏好或存储值无效时,沿用原默认值 `updated-desc`。本地存储不可用时,读取使用该默认值,写入失败不阻断当前会话的排序选择。不修改或清除其他偏好。
+4. 实现前添加定向浏览器回归:依次选择四种排序,重新打开工作区,检查恢复的选中状态;如果启动时发生网络列表查询,其排序参数必须与恢复值一致(已初始化的本地镜像可以不发请求)。覆盖偏好缺失/无效及偏好存储不可用。将用例接入现有浏览器 CI job,不增加 Runner,也不改变检查名称。执行必需的 Web/移动端类型检查和 Web 构建。
+5. 复用已确认的官方 v2.16.1 重启丢失选择证据作为基线。通过持久化配置验证桌面候选完整退出再启动,区分真实 macOS/Cloudflare 验证、浏览器刷新、安装包/发布验收及未验证平台。保留用户笔记、已有工作区和备份设置。
+
+## 保持不变的边界、风险与恢复
+
+功能价值是避免每次启动后手动重选。仅在工作区初始化时读取一项小型本地偏好,用户明确选择后写入一次;不增加数据库/网络读取、扫描、迁移、依赖或后台任务。筛选、笔记本选择、账号/认证、原生 Android/iOS、备份、安装和升级行为不变。
+
+主要失败情形是本地偏好存储不可用:当前会话仍可使用,后续启动沿用原默认排序。回滚时撤回偏好接线即可;旧版忽略新增键,不需要迁移数据。Windows/Linux 原生界面和安装包跨版本验收须与 macOS/浏览器检查分别说明。
+
+## 实现与验收结论
+
+- `app-helpers.ts` 负责读取、校验和写入偏好,`WorkspaceApp.tsx` 在状态初始化和现有排序选择回调中接入;排序、缓存、分页以及服务端代码未改动。浏览器回归接入原有 CI job,未增加 Runner 或依赖。实际变更均对应上述范围。
+- 修复前的定向浏览器用例复现了选择 A–Z 后没有保存偏好。修复后 7 个 Chromium 端到端用例通过,覆盖四种排序重开、缺失/无效值、存储不可用,以及其他已有偏好不被覆盖。
+- macOS 候选复用正式 v2.16.1 的原生主进程和 Sidecar,通过文件入口加载候选 Web 构建并连接真实 Cloudflare 工作区。选择 A–Z 后完整退出并重新启动,菜单仍为 A–Z,工作区显示已同步;验证后恢复正式客户端。该验证未替换安装包。
+- `bun run typecheck`、`bun run typecheck:mobile`、`EDGE_EVER_DESKTOP_BUILD=1 bun run build:web` 及变更文件的 lint 通过。
+- Windows/Linux 原生界面、安装包跨版本升级和远端 CI 尚未验证;本次没有部署服务端或发布客户端。
diff --git a/tests/e2e/memo-sort-preference.spec.ts b/tests/e2e/memo-sort-preference.spec.ts
new file mode 100644
index 00000000..a174077a
--- /dev/null
+++ b/tests/e2e/memo-sort-preference.spec.ts
@@ -0,0 +1,73 @@
+import { expect, test, type Page } from "@playwright/test";
+
+const storageKey = "edgeever.memoSort";
+const modes = [
+ ["updated-desc", "最近更新"],
+ ["created-desc", "创建时间"],
+ ["title-asc", "标题 A-Z"],
+ ["title-desc", "标题 Z-A"],
+] as const;
+
+const openSort = async (page: Page) => {
+ await page.getByRole("button", { name: "列表更多操作", exact: true }).click();
+ return page.getByRole("menuitem", { name: /^排序:/ });
+};
+
+const chooseSort = async (page: Page, label: string) => {
+ await (await openSort(page)).hover();
+ await page.getByRole("menuitem", { name: label, exact: true }).click();
+};
+
+for (const [mode, label] of modes) {
+ test(`remembers ${mode} when the workspace reopens`, async ({ page }) => {
+ await page.goto("/");
+ await chooseSort(page, label);
+ await expect.poll(() => page.evaluate(key => localStorage.getItem(key), storageKey)).toBe(mode);
+
+ const requestedSorts: Array<string | null> = [];
+ page.on("request", request => {
+ const url = new URL(request.url());
+ if (url.pathname === "/api/v1/memos" && request.method() === "GET") {
+ requestedSorts.push(url.searchParams.get("sort"));
+ }
+ });
+ await page.reload();
+ await expect(await openSort(page)).toHaveText(`排序:${label}`);
+ // A populated local mirror can satisfy the list without an HTTP query.
+ expect(requestedSorts.every(value => value === mode)).toBe(true);
+ });
+}
+
+for (const stored of [null, "unknown-sort"]) {
+ test(`keeps the default when the stored sort is ${stored === null ? "absent" : "invalid"}`, async ({ page }) => {
+ await page.addInitScript(({ key, value }) => {
+ if (value === null) localStorage.removeItem(key);
+ else localStorage.setItem(key, value);
+ localStorage.setItem("edgeever.notebookSort", "custom");
+ }, { key: storageKey, value: stored });
+ await page.goto("/");
+ await expect(await openSort(page)).toHaveText("排序:最近更新");
+ expect(await page.evaluate(key => localStorage.getItem(key), storageKey)).toBe(stored);
+ expect(await page.evaluate(() => localStorage.getItem("edgeever.notebookSort"))).toBe("custom");
+ });
+}
+
+test("keeps in-session sorting usable when preference storage is blocked", async ({ page }) => {
+ await page.addInitScript(key => {
+ const get = Storage.prototype.getItem;
+ const set = Storage.prototype.setItem;
+ Storage.prototype.getItem = function(name) {
+ if (name === key) throw new DOMException("Blocked", "SecurityError");
+ return get.call(this, name);
+ };
+ Storage.prototype.setItem = function(name, value) {
+ if (name === key) throw new DOMException("Blocked", "SecurityError");
+ set.call(this, name, value);
+ };
+ }, storageKey);
+ await page.goto("/");
+ await chooseSort(page, "标题 A-Z");
+ await expect(await openSort(page)).toHaveText("排序:标题 A-Z");
+ await page.reload();
+ await expect(await openSort(page)).toHaveText("排序:最近更新");
+});