Files
EpicNext-Cms/src/app/admin/translations/client/page.tsx
T
openhands dc8fb8a6ed feat: speed up admin clone import and enable Cache Components
- Clone import: defer FurnitureData.json writes and append all entries in a
  single batched write instead of one read-modify-write per item, removing
  the main serialization bottleneck for large batches.
- Clone import: raise SSE batch concurrency cap from 5 to 10 and bump the
  clone client/route default from 2 to 6.
- Add a flush hook to runSseBatch so callers can batch deferred work before
  batch_complete is emitted, and surface flush errors as an error event.
- Enable Next.js Cache Components (instant: false opt-out) and silence the
  related build warnings in next.config.ts.
- Switch isomorphic-dompurify to dompurify and refresh dependencies.
2026-08-05 11:10:16 +02:00

59 lines
1.8 KiB
TypeScript

import fs from "node:fs/promises";
import path from "node:path";
import JSON5 from "json5";
import {
CLIENT_TRANSLATION_FILES,
getClientTranslationFile,
} from "@/lib/client-translation-files";
import { ClientTranslations } from "./client-translations";
// TODO: Cache Components adoption. Refactor this route so this opt-out can be removed.
// See: https://nextjs.org/docs/app/guides/migrating-to-cache-components
export const instant = false;
export default async function ClientTranslationsPage({
searchParams,
}: {
searchParams: Promise<Record<string, string | undefined>>;
}) {
const sp = await searchParams;
const requested = sp.file;
const file =
(requested && getClientTranslationFile(requested)) ||
CLIENT_TRANSLATION_FILES.find((f) => !f.readOnly) ||
CLIENT_TRANSLATION_FILES[0];
const entries: Record<string, string> = {};
let parseError: string | null = null;
try {
// file.relPath comes from CLIENT_TRANSLATION_FILES (closed enum) but
// Turbopack's tracer can't prove that — hint avoids tracing the whole project.
const raw = await fs.readFile(
path.join(/*turbopackIgnore: true*/ process.cwd(), file.relPath),
"utf-8",
);
const parsed = file.format === "json5" ? JSON5.parse(raw) : JSON.parse(raw);
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
// Nitro localization files are flat: { "key.with.dots": "value" }.
// Coerce values to strings so the editor can render them in <input>.
for (const [k, v] of Object.entries(parsed)) {
entries[k] = v == null ? "" : String(v);
}
} else {
parseError = "File root is not an object.";
}
} catch (err) {
parseError = err instanceof Error ? err.message : "Failed to read file.";
}
return (
<ClientTranslations
files={CLIENT_TRANSLATION_FILES}
activeFile={file}
entries={entries}
parseError={parseError}
/>
);
}