Skip to content

Open source CapCut alternative.

TypeScript

fix(site): the export eval answers the account config read

David Lea29852325477
diff --git a/site/scripts/eval-cut-export.ts b/site/scripts/eval-cut-export.ts
index 25890693..30d6a07d 100644
--- a/site/scripts/eval-cut-export.ts
+++ b/site/scripts/eval-cut-export.ts
@@ -28,6 +28,9 @@ import { existsSync } from "node:fs";
import { mkdir, readFile, writeFile } from "node:fs/promises";
import path from "node:path";
+import { defaultSettings } from "../src/lib/config/registry";
+import { publicSubset } from "../src/lib/config/resolve";
+
const SITE = path.resolve(import.meta.dir, "..");
const OUT = path.resolve(SITE, "..", "dist", "cut-export");
const STOCK = path.join(SITE, "public", "cut-stock-video");
@@ -124,6 +127,18 @@ async function launch(): Promise<{ browser: Browser; page: Page }> {
await context.route("**/api/account/onboarding", (route) =>
route.fulfill({ status: 200, contentType: "application/json", body: "null" })
);
+ // The session gate's configuration read: defaults, no experiments held.
+ await context.route("**/api/account/config", (route) =>
+ route.fulfill({
+ status: 200,
+ contentType: "application/json",
+ body: JSON.stringify({
+ settings: publicSubset(defaultSettings()),
+ experiments: {},
+ exposed: [],
+ }),
+ })
+ );
await context.route(
(u) => /\/api\/(cut|cut-cloud)\/(projects|export-jobs|library)$/.test(u.pathname),
(route) =>
diff --git a/site/src/queries/accountConfig.ts b/site/src/queries/accountConfig.ts
index bac5e50c..592ecf07 100644
--- a/site/src/queries/accountConfig.ts
+++ b/site/src/queries/accountConfig.ts
@@ -15,13 +15,24 @@ export type AccountConfig = {
exposed: string[];
};
+// A body that is not this shape is a failed read. Parsed here, at the wire,
+// so the query holds the error: the gate this runs from wraps the whole app,
+// and a payload thrown into that tree takes the editor down with it.
+function parseAccountConfig(raw: unknown): AccountConfig {
+ const body = raw as Partial<AccountConfig> | null;
+ if (!body?.settings || !body.experiments || !Array.isArray(body.exposed)) {
+ throw new Error("/api/account/config answered without settings, experiments and exposed");
+ }
+ return { settings: body.settings, experiments: body.experiments, exposed: body.exposed };
+}
+
// Fetched once per page load from the session gate. It never refetches on
// focus: a variant switching under someone mid-session is the one thing an
// experiment must not do.
export function useAccountConfig({ enabled }: { enabled: boolean }) {
return useQuery({
enabled,
- queryFn: () => apiFetch<AccountConfig>("/api/account/config"),
+ queryFn: async () => parseAccountConfig(await apiFetch<unknown>("/api/account/config")),
queryKey: accountConfigQueryKey,
refetchOnWindowFocus: false,
retry: false,