Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(client/lightweight): saving not working
Elian Doranb1f3fe534597
diff --git a/apps/client/src/lightweight/browser_router.ts b/apps/client/src/lightweight/browser_router.tsindex e6dcd74b6a..fd1f587ef4 100644--- a/apps/client/src/lightweight/browser_router.ts+++ b/apps/client/src/lightweight/browser_router.ts@@ -139,12 +139,29 @@ export class BrowserRouter {/*** Dispatch a request to the appropriate handler.*/- async dispatch(method: string, urlString: string, body?: unknown): Promise<BrowserResponse> {+ async dispatch(method: string, urlString: string, body?: unknown, headers?: Record<string, string>): Promise<BrowserResponse> {const url = new URL(urlString);const path = url.pathname;const query = parseQuery(url.search);const upperMethod = method.toUpperCase();+ // Parse JSON body if it's an ArrayBuffer and content-type suggests JSON+ let parsedBody = body;+ if (body instanceof ArrayBuffer && headers) {+ const contentType = headers['content-type'] || headers['Content-Type'] || '';+ if (contentType.includes('application/json')) {+ try {+ const text = new TextDecoder().decode(body);+ if (text.trim()) {+ parsedBody = JSON.parse(text);+ }+ } catch (e) {+ console.warn('[Router] Failed to parse JSON body:', e);+ // Keep original body if JSON parsing fails+ parsedBody = body;+ }+ }+ }// Find matching routefor (const route of this.routes) {if (route.method !== upperMethod) continue;@@ -164,7 +181,7 @@ export class BrowserRouter {path,params,query,- body+ body: parsedBody};try {@@ -190,9 +207,12 @@ export class BrowserRouter {return jsonResponse(response, statusCode);}- // Handle undefined (no content)+ // Handle undefined (no content) - 204 should have no bodyif (result === undefined) {- return jsonResponse('', 204);+ return {+ status: 204,+ headers: {}+ };}// Default: JSON response with 200diff --git a/apps/client/src/local-server-worker.ts b/apps/client/src/local-server-worker.tsindex b12ab230fe..57865b49e1 100644--- a/apps/client/src/local-server-worker.ts+++ b/apps/client/src/local-server-worker.ts@@ -139,6 +139,7 @@ interface LocalRequest {method: string;url: string;body?: unknown;+ headers?: Record<string, string>;}// Main dispatch@@ -151,7 +152,7 @@ async function dispatch(request: LocalRequest) {const appRouter = await ensureInitialized();// Dispatch to the router- return appRouter.dispatch(request.method, request.url, request.body);+ return appRouter.dispatch(request.method, request.url, request.body, request.headers);}// Start initialization immediately when the worker loads