fix: serialize Appwrite rows before sending to client components

Next 16's server-to-client serializer rejects values whose prototype is
not plain Object. node-appwrite returns row objects carrying internal
helpers (toString etc.), so every <ClientComponent prop={row}> crashed with
'Only plain objects, and a few built-ins, can be passed to Client
Components from Server Components.'

Added a tiny toPlain helper that JSON-roundtrips any value and applied it
at the boundary of every query that returns rows consumed by 'use client'
files:
  - connection-queries (enrich)
  - job-queries (inbound, outbound, approved labs)
  - job-file-queries (listJobFiles)
  - job-history-queries (listJobHistory)
  - prosthetic-queries (listProsthetics, listActiveProsthetics)
  - finance-queries (listFinanceEntries)
  - notification-helpers (listNotifications)
  - dashboard-queries (getDashboardData)
  - jobs/[jobId] page (direct getRow for the job prop on JobActionsPanel)

Internal Maps inside queries stay live — only the data crossing the
server/client boundary is normalised.
This commit is contained in:
kovakmedya
2026-05-21 20:57:59 +03:00
parent c980ce1d8d
commit f34630de62
10 changed files with 57 additions and 25 deletions
+3 -2
View File
@@ -4,6 +4,7 @@ import { Query } from "node-appwrite";
import { DATABASE_ID, TABLES, type Prosthetic } from "./schema";
import { createAdminClient } from "./server";
import { toPlain } from "./serialize";
export async function listProsthetics(tenantId: string): Promise<Prosthetic[]> {
const { tablesDB } = createAdminClient();
@@ -16,7 +17,7 @@ export async function listProsthetics(tenantId: string): Promise<Prosthetic[]> {
Query.limit(200),
],
});
return result.rows as unknown as Prosthetic[];
return toPlain(result.rows as unknown as Prosthetic[]);
}
export async function listActiveProsthetics(tenantId: string): Promise<Prosthetic[]> {
@@ -31,5 +32,5 @@ export async function listActiveProsthetics(tenantId: string): Promise<Prostheti
Query.limit(200),
],
});
return result.rows as unknown as Prosthetic[];
return toPlain(result.rows as unknown as Prosthetic[]);
}