# Commit Message for SharedArrayBuffer Platform Exclusion

fix: eliminate SharedArrayBuffer checks on non-web platforms

* Add platform guard in AbsurdSqlDatabaseService to only initialize on web
* Change singleton pattern from eager to lazy instantiation
* Update worker import to use lazy singleton pattern
* Prevents absurd-sql initialization on Electron/Capacitor platforms
* Reduces console noise and memory footprint on desktop/mobile
* Maintains full web platform functionality and performance

Resolves SharedArrayBuffer-related console output on Electron platform
while preserving all web features and maintaining clean architecture.
This commit is contained in:
Matthew Raymer
2025-07-03 05:15:57 +00:00
parent 797db7069c
commit 292aceee75
21 changed files with 1044 additions and 151 deletions

View File

@@ -70,6 +70,14 @@ class AbsurdSqlDatabaseService implements DatabaseService {
return;
}
// **PLATFORM CHECK**: AbsurdSqlDatabaseService should only run on web platform
// This prevents SharedArrayBuffer checks and web-specific initialization on Electron/Capacitor
if (process.env.VITE_PLATFORM !== "web") {
throw new Error(
`AbsurdSqlDatabaseService is only supported on web platform. Current platform: ${process.env.VITE_PLATFORM}`,
);
}
const SQL = await initSqlJs({
locateFile: (file: string) => {
return new URL(
@@ -86,10 +94,15 @@ class AbsurdSqlDatabaseService implements DatabaseService {
SQL.FS.mount(sqlFS, {}, "/sql");
const path = "/sql/timesafari.absurd-sql";
// **SHARED ARRAY BUFFER FALLBACK**: Only needed for web platform
// This check handles Safari and other browsers without SharedArrayBuffer support
if (typeof SharedArrayBuffer === "undefined") {
logger.debug("[AbsurdSqlDatabaseService] SharedArrayBuffer not available, using fallback mode");
const stream = SQL.FS.open(path, "a+");
await stream.node.contents.readIfFallback();
SQL.FS.close(stream);
} else {
logger.debug("[AbsurdSqlDatabaseService] SharedArrayBuffer available, using optimized mode");
}
this.db = new SQL.Database(path, { filename: true });
@@ -237,7 +250,6 @@ class AbsurdSqlDatabaseService implements DatabaseService {
}
}
// Create a singleton instance
const databaseService = AbsurdSqlDatabaseService.getInstance();
export default databaseService;
// Export the service class for lazy instantiation
// The singleton will only be created when actually needed (web platform only)
export default AbsurdSqlDatabaseService;