Open source CapCut alternative.
TypeScript
fix(site): resolve lint and build errors
David Lee5fd11575662
diff --git a/site/eslint.config.mjs b/site/eslint.config.mjsindex f16bb01c..82b56c25 100644--- a/site/eslint.config.mjs+++ b/site/eslint.config.mjs@@ -11,6 +11,8 @@ const eslintConfig = defineConfig([".next/**","out/**","build/**",+ "dist/**",+ "public/mediapipe/**","next-env.d.ts",// Cloudflare Worker shell for the Cut render worker: compiled by wrangler// against workers types, excluded from the site's tsconfig.diff --git a/site/src/app/api/su/blog/posts/[id]/uploads/route.ts b/site/src/app/api/su/blog/posts/[id]/uploads/route.tsindex 2235b461..888e32c0 100644--- a/site/src/app/api/su/blog/posts/[id]/uploads/route.ts+++ b/site/src/app/api/su/blog/posts/[id]/uploads/route.ts@@ -12,8 +12,8 @@ type Params = { params: Promise<{ id: string }> };const idSchema = z.string().trim().min(1);// What the encoder can read. HEIC needs a decoder the bundled sharp lacks.-export const BLOG_UPLOAD_MIMES = new Set(["image/png", "image/jpeg", "image/webp", "image/gif", "image/avif"]);-export const BLOG_UPLOAD_MAX_BYTES = 25 * 1024 * 1024;+const BLOG_UPLOAD_MIMES = new Set(["image/png", "image/jpeg", "image/webp", "image/gif", "image/avif"]);+const BLOG_UPLOAD_MAX_BYTES = 25 * 1024 * 1024;const bodySchema = z.object({diff --git a/site/src/app/cut/_components/landing/CutWorksWith.tsx b/site/src/app/cut/_components/landing/CutWorksWith.tsxindex 73ba26c0..56381faf 100644--- a/site/src/app/cut/_components/landing/CutWorksWith.tsx+++ b/site/src/app/cut/_components/landing/CutWorksWith.tsx@@ -27,7 +27,7 @@ export function CutWorksWith() {</div><p className="mx-auto mt-12 max-w-[720px] text-[17px] leading-[1.55] text-[#454545]">The assistant uses the Claude and Codex apps already signed in on your- Mac. If you have a subscription, you're done — no setup, no API keys.+ Mac. If you have a subscription, you’re done — no setup, no API keys.</p></section>);diff --git a/site/src/cut/components/ConnectGate.tsx b/site/src/cut/components/ConnectGate.tsxindex 601e938c..382df412 100644--- a/site/src/cut/components/ConnectGate.tsx+++ b/site/src/cut/components/ConnectGate.tsx@@ -116,7 +116,7 @@ export function ConnectGate({ children }: { children: ReactNode }) {setReached(false);}, []);- const check = useCallback(async () => {+ const check = useCallback(() => permissionState().then(async (perm) => {const forced = forcedGate();if (forced) {setSeen(true);@@ -124,7 +124,6 @@ export function ConnectGate({ children }: { children: ReactNode }) {setBlocked(forced === "blocked");return bindCloud();}- const perm = await permissionState();setSeen(engineSeen());setBlocked(perm === "denied");const quiet =@@ -141,7 +140,7 @@ export function ConnectGate({ children }: { children: ReactNode }) {}}bindCloud();- }, [bindCloud, bindEngine]);+ }), [bindCloud, bindEngine]);// The probe carries the account id like every other engine call, so it waits// for one. The banner and the app around it paint before that.diff --git a/site/src/cut/components/ProjectsHome.tsx b/site/src/cut/components/ProjectsHome.tsxindex 433e1bf1..4135d4e3 100644--- a/site/src/cut/components/ProjectsHome.tsx+++ b/site/src/cut/components/ProjectsHome.tsx@@ -1,6 +1,6 @@"use client";-import { useCallback, useEffect, useRef, useState, type RefObject } from "react";+import { useCallback, useEffect, useRef, useState, useSyncExternalStore, type RefObject } from "react";import { useQueryClient } from "@tanstack/react-query";import { useRouter, useSearchParams } from "next/navigation";import {@@ -97,6 +97,17 @@ import { FolderCrumb, FolderShelf, Marquee } from "./desktopFolders";import { formatBytes } from "@/lib/bytes";type View = "gallery" | "list";+const viewListeners = new Set<() => void>();+const readView = (): View => localStorage.getItem("cut-projects-view") === "list" ? "list" : "gallery";+const serverView = (): View => "gallery";+const subscribeView = (notify: () => void) => {+ viewListeners.add(notify);+ window.addEventListener("storage", notify);+ return () => {+ viewListeners.delete(notify);+ window.removeEventListener("storage", notify);+ };+};// The home lists every residency the user has, talking to the backend objects// directly — the global mode is only bound when a project opens into the@@ -277,7 +288,7 @@ export function ProjectsHome() {? (residencies.find((r) => data[r].folders.some((f) => f.id === openFolder)) ?? null): null;const [selected, setSelected] = useState<Set<string>>(new Set());- const [view, setView] = useState<View>("gallery");+ const view = useSyncExternalStore(subscribeView, readView, serverView);// The residency the pending creation was launched for; null when the naming// dialog is closed.const [createIn, setCreateIn] = useState<Residency | null>(null);@@ -299,11 +310,6 @@ export function ProjectsHome() {const [fileOver, setFileOver] = useState(false);const dragDepth = useRef(0);- useEffect(() => {- const saved = localStorage.getItem("cut-projects-view");- if (saved === "list" || saved === "gallery") setView(saved);- }, []);-// A folder the URL names and no listed shelf answers for — deleted// elsewhere — goes back to the top level.const allSettled = residencies.every((r) => data[r].projects !== null || data[r].error);@@ -313,8 +319,8 @@ export function ProjectsHome() {}, [staleFolder, router, base]);const switchView = (v: View) => {- setView(v);localStorage.setItem("cut-projects-view", v);+ viewListeners.forEach((notify) => notify());};// Each mutation below opens with the same guard: a shelf that isn'tdiff --git a/site/src/cut/components/onboarding/CutOnboarding.tsx b/site/src/cut/components/onboarding/CutOnboarding.tsxindex 34a06d11..f6af18c2 100644--- a/site/src/cut/components/onboarding/CutOnboarding.tsx+++ b/site/src/cut/components/onboarding/CutOnboarding.tsx@@ -1,6 +1,6 @@"use client";-import { useCallback, useEffect, useRef, useState } from "react";+import { useCallback, useEffect, useMemo, useRef, useState } from "react";import { ArrowLeft, ArrowRight } from "lucide-react";import { Button } from "@/components/ui/button";@@ -70,8 +70,12 @@ export function CutOnboarding() {const { data: pro } = useProSubscription();const save = useSaveOnboarding();const [rawStep, setStep] = useState(0);- const [referrals, setReferrals] = useState<ReferralSource[]>([]);- const [referralOther, setReferralOther] = useState("");+ const saved = useMemo(() => (state?.referralSources ?? []).filter(isKnownReferralSource), [state]);+ const savedOther = saved.includes("other") ? (state?.referralOther ?? "") : "";+ const [referralDraft, setReferrals] = useState<ReferralSource[] | null>(null);+ const [otherDraft, setReferralOther] = useState<string | null>(null);+ const referrals = referralDraft ?? saved;+ const referralOther = otherDraft ?? savedOther;const [dismissed, setDismissed] = useState(false);const [replaying, setReplaying] = useState(false);// Read once per mount: whether this browser can skip the wait below.@@ -85,22 +89,7 @@ export function CutOnboarding() {);// What the account already has, so leaving the question without changing// anything writes nothing.- const savedReferrals = useRef("");-- // An answer given in the past shows again: once the account read lands, the- // question opens already filled in, and it reads as saved rather than as a- // pending change.- const seeded = useRef(false);- useEffect(() => {- if (!state || seeded.current) return;- seeded.current = true;- const saved = (state.referralSources ?? []).filter(isKnownReferralSource);- if (!saved.length) return;- const other = saved.includes("other") ? (state.referralOther ?? "") : "";- setReferrals(saved);- setReferralOther(other);- savedReferrals.current = referralSignature(saved, other);- }, [state]);+ const savedReferrals = useRef<string | null>(null);// Which run is on screen, derived rather than set: the account read landing// is what opens a first run, and nothing has to push that into state. On the@@ -185,14 +174,14 @@ export function CutOnboarding() {const commitReferrals = useCallback(() => {const other = referrals.includes("other") ? referralOther.trim() : "";const signature = referralSignature(referrals, other);- if (!referrals.length || signature === savedReferrals.current) return;+ if (!referrals.length || signature === (savedReferrals.current ?? referralSignature(saved, savedOther))) return;savedReferrals.current = signature;track("onboarding_referral_selected", {referralSources: referrals,...(other && { referralOther: other }),});save.mutate({ referralSources: referrals, ...(other && { referralOther: other }) });- }, [referrals, referralOther, save]);+ }, [referrals, referralOther, saved, savedOther, save]);const finish = useCallback((skipped: boolean) => {@@ -285,11 +274,12 @@ export function CutOnboarding() {}const toggleReferral = (source: ReferralSource) => {- setReferrals((current) =>- current.includes(source)+ setReferrals((draft) => {+ const current = draft ?? saved;+ return current.includes(source)? current.filter((s) => s !== source)- : [...current, source],- );+ : [...current, source];+ });};const last = step === slideCount - 1;diff --git a/site/src/cut/lib/micTranscribe.ts b/site/src/cut/lib/micTranscribe.tsindex 69d7df1e..8ee08ee5 100644--- a/site/src/cut/lib/micTranscribe.ts+++ b/site/src/cut/lib/micTranscribe.ts@@ -1,6 +1,6 @@"use client";-import { useCallback, useEffect, useRef, useState } from "react";+import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";import { hasLocalCompute } from "./backend";import { localBackend } from "./backend/local";import { cloudTranscribeRecording } from "./cloudTranscribe";@@ -67,7 +67,9 @@ export function useMicTranscription(onResult: (text: string) => void): MicControconst feedTimer = useRef<ReturnType<typeof setInterval> | null>(null);const pollTimer = useRef<ReturnType<typeof setInterval> | null>(null);const onResultRef = useRef(onResult);- onResultRef.current = onResult;+ useLayoutEffect(() => {+ onResultRef.current = onResult;+ }, [onResult]);/** Stop and forget the cloud recorder (before its tracks stop). */const discardRecorder = useCallback(() => {