diff --git a/src/database/db.ts b/src/database/db.ts index 9bb177b..2bc1a57 100644 --- a/src/database/db.ts +++ b/src/database/db.ts @@ -11,6 +11,12 @@ import type { export interface LocalList extends List { pendingSync?: boolean + // Stable identity for this list on this client, independent of `id`. + // `id` starts out as a client-generated placeholder and gets swapped for + // the server-assigned one once "createList" syncs (see remapListId) - + // clientId never changes, so UI code that needs a stable key across that + // swap (e.g. 's :key) can use it instead of `id`. + clientId?: string } export interface LocalListItem extends ListItem { diff --git a/src/stores/lists.ts b/src/stores/lists.ts index ca25441..8ac9c80 100644 --- a/src/stores/lists.ts +++ b/src/stores/lists.ts @@ -147,8 +147,10 @@ export const useListsStore = defineStore('lists', () => { async function createList(name: string): Promise { const now = new Date().toISOString() + const id = generateId() const localList: LocalList = { - id: generateId(), + id, + clientId: id, name, created_at: now, modified_at: now, @@ -538,7 +540,11 @@ export const useListsStore = defineStore('lists', () => { for (const serverList of serverLists) { const existingList = localById.get(serverList.id) if (!existingList || !existingList.pendingSync) { - toPut.push({ ...serverList, pendingSync: false }) + toPut.push({ + ...serverList, + pendingSync: false, + clientId: existingList?.clientId ?? serverList.id, + }) } } if (toPut.length > 0) { diff --git a/src/views/ListsView.vue b/src/views/ListsView.vue index ca460cc..16226f1 100644 --- a/src/views/ListsView.vue +++ b/src/views/ListsView.vue @@ -110,7 +110,7 @@ async function handleCreateList() {