From 70374f1274fd8ee1d06350ba03ea6b792003eb58 Mon Sep 17 00:00:00 2001 From: tiennm99 Date: Fri, 14 Aug 2026 16:25:24 +0700 Subject: [PATCH] fix(web): bind query parameters, and set the URL without the router Two failures, both reaching a browser for the first time now that the database actually opens. Parameters never reached SQLite. The worker forwards its arguments straight to sql.js: this.db.query = (...args) => toObjects(this.db.exec(...args)) and exec(sql, params) takes the whole parameter list as its second argument, ignoring anything that is not an array. Spreading them handed it a bare string, so every ? stayed unbound and read as NULL: the exam id lookup failed on LIMIT NULL with "datatype mismatch", and name search quietly matched nothing. The library's own type says ...params and is wrong about its own implementation. The address bar update went through SvelteKit's replaceState, which reaches into the client router's root component. That is undefined until the router has initialized, and the call then fails inside SvelteKit with "Cannot read properties of undefined (reading '$set')" (sveltejs/kit#12204). The native History API does the same job; passing the current history.state back unchanged leaves SvelteKit's own bookkeeping intact, and nothing reads page.url after the initial deep link. --- web/src/lib/sqlite.svelte.js | 7 ++++++- web/src/routes/[dataset]/+page.svelte | 12 +++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/web/src/lib/sqlite.svelte.js b/web/src/lib/sqlite.svelte.js index c127153..e6212c4 100644 --- a/web/src/lib/sqlite.svelte.js +++ b/web/src/lib/sqlite.svelte.js @@ -124,7 +124,12 @@ export class RemoteDatabase { const worker = this.#worker ?? (await this.#opening); const started = performance.now(); try { - return await worker.db.query(sql, ...params); + // One array argument, never spread. The worker forwards its arguments to + // sql.js's exec(sql, params), which takes the whole parameter list as its + // second argument and ignores anything that is not an array — leaving + // every ? unbound, which reads as NULL. The library's own type says + // `...params`, and it is wrong. + return await worker.db.query(sql, params); } finally { await this.#account(worker, label ?? firstLine(sql), performance.now() - started); } diff --git a/web/src/routes/[dataset]/+page.svelte b/web/src/routes/[dataset]/+page.svelte index f613093..62d8959 100644 --- a/web/src/routes/[dataset]/+page.svelte +++ b/web/src/routes/[dataset]/+page.svelte @@ -1,6 +1,5 @@