Fix worker-only database architecture and Vue Proxy serialization

- Implement worker-only database access to eliminate double migrations
- Add parameter serialization in usePlatformService to prevent Capacitor "object could not be cloned" errors
- Fix infinite logging loop with circuit breaker in databaseUtil
- Use dynamic imports in WebPlatformService to prevent worker thread errors
- Add higher-level database methods (getContacts, getSettings) to composable
- Eliminate Vue Proxy objects through JSON serialization and Object.freeze protection

Resolves Proxy(Array) serialization failures and worker context conflicts across Web/Capacitor/Electron platforms.
This commit is contained in:
Matthew Raymer
2025-07-02 07:24:51 +00:00
parent a82e00f4d9
commit e283fcf0ac
19 changed files with 1790 additions and 121 deletions

View File

@@ -1,10 +1,14 @@
import { initBackend } from "absurd-sql/dist/indexeddb-main-thread";
import { initializeApp } from "./main.common";
import { logger } from "./utils/logger";
// import { logger } from "./utils/logger"; // DISABLED FOR DEBUGGING
const platform = process.env.VITE_PLATFORM;
const pwa_enabled = process.env.VITE_PWA_ENABLED === "true";
// Debug: Check SharedArrayBuffer availability
console.log(`[SharedArrayBuffer] Available: ${typeof SharedArrayBuffer !== 'undefined'}`);
console.log(`[Browser] User Agent: ${navigator.userAgent}`);
console.log(`[Headers] Check COOP/COEP in Network tab if SharedArrayBuffer is false`);
// Only import service worker for web builds
if (pwa_enabled) {
import("./registerServiceWorker"); // Web PWA support
@@ -12,23 +16,18 @@ if (pwa_enabled) {
const app = initializeApp();
function sqlInit() {
// see https://github.com/jlongster/absurd-sql
const worker = new Worker(
new URL("./registerSQLWorker.js", import.meta.url),
{
type: "module",
},
);
// This is only required because Safari doesn't support nested
// workers. This installs a handler that will proxy creating web
// workers through the main thread
initBackend(worker);
}
// Note: Worker initialization is now handled by WebPlatformService
// This ensures single-point database access and prevents double migrations
if (platform === "web" || platform === "development") {
sqlInit();
// logger.log( // DISABLED
// "[Web] Database initialization will be handled by WebPlatformService",
// );
console.log(
"[Web] Database initialization will be handled by WebPlatformService",
);
} else {
logger.warn("[Web] SQL not initialized for platform", { platform });
// logger.warn("[Web] SQL not initialized for platform", { platform }); // DISABLED
console.warn("[Web] SQL not initialized for platform", { platform });
}
app.mount("#app");