fix: zoom reset on drag and IndexedDB version conflict (#776)

- Fix zoom resetting when dragging items (#775): removed useEffect that
  called load() on every autosave-triggered chartXML change, which reset
  the viewport. Moved diagram restore logic to onDrawioLoad where it
  only fires on remount.

- Fix IndexedDB VersionError: template-storage.ts shared the same DB
  name as session-storage.ts but at version 2, causing session storage
  to fail with "requested version (1) < existing version (2)". Give
  templates their own DB ("next-ai-drawio-templates").
This commit is contained in:
Dayuan Jiang
2026-04-03 16:44:42 +09:00
committed by GitHub
parent 6c6cf98019
commit f593901fee
2 changed files with 6 additions and 36 deletions

View File

@@ -2,8 +2,8 @@ import { type DBSchema, type IDBPDatabase, openDB } from "idb"
import { nanoid } from "nanoid"
// Constants
const DB_NAME = "next-ai-drawio"
const DB_VERSION = 2
const DB_NAME = "next-ai-drawio-templates"
const DB_VERSION = 1
const STORE_NAME = "templates"
// Types
@@ -34,14 +34,6 @@ export type TemplateCreateInput = Pick<Template, "prompt"> &
>
interface TemplateDB extends DBSchema {
sessions: {
key: string
value: {
id: string
[key: string]: unknown
}
indexes: { "by-updated": number }
}
templates: {
key: string
value: Template
@@ -98,14 +90,6 @@ async function getDB(): Promise<IDBPDatabase<TemplateDB>> {
dbPromise = openDB<TemplateDB>(DB_NAME, DB_VERSION, {
upgrade(db, oldVersion) {
if (oldVersion < 1) {
if (!db.objectStoreNames.contains("sessions")) {
const sessionStore = db.createObjectStore("sessions", {
keyPath: "id",
})
sessionStore.createIndex("by-updated", "updatedAt")
}
}
if (oldVersion < 2) {
if (!db.objectStoreNames.contains(STORE_NAME)) {
const templateStore = db.createObjectStore(STORE_NAME, {
keyPath: "id",