Open source CapCut alternative.
TypeScript
fix(site): a share keeps its surface through window resizes
David Le7149bdf0f309
diff --git a/site/src/app/cut/s/[token]/SharedProjectView.tsx b/site/src/app/cut/s/[token]/SharedProjectView.tsxindex 895ee52b..e8b27fbd 100644--- a/site/src/app/cut/s/[token]/SharedProjectView.tsx+++ b/site/src/app/cut/s/[token]/SharedProjectView.tsx@@ -7,7 +7,7 @@ import { authHrefFor } from "@/app/_components/landing/useAppEntryHref";import { Button } from "@/components/ui/button";import { Editor } from "@/cut/components/Editor";import { MobileShare } from "@/cut/components/share/MobileShare";-import { useIsNarrow } from "@/cut/hooks/useIsNarrow";+import { useIsNarrowAtOpen } from "@/cut/hooks/useIsNarrow";import { bindCutMode } from "@/cut/lib/backend";import { bindSharedBackend } from "@/cut/lib/backend/shared";import { holdThreadsInMemory } from "@/cut/lib/chatThreads";@@ -33,7 +33,7 @@ export function SharedProject() {const { token } = useParams<{ token: string }>();const [gate, setGate] = useState<Gate>({ state: "loading" });const { data: session } = authClient.useSession();- const narrow = useIsNarrow();+ const narrow = useIsNarrowAtOpen();useEffect(() => {let alive = true;diff --git a/site/src/cut/hooks/useIsNarrow.ts b/site/src/cut/hooks/useIsNarrow.tsindex 61c3cc30..d68d635c 100644--- a/site/src/cut/hooks/useIsNarrow.ts+++ b/site/src/cut/hooks/useIsNarrow.ts@@ -33,3 +33,20 @@ export function useIsNarrow(): boolean | null {}, []);return narrow;}++/**+ * The viewport's narrowness measured once, when the component opens — null+ * only on the server. For mount decisions that must hold for the visit: the+ * share view picks its surface (player or editor) by this, and a desktop+ * window resized across the threshold keeps the surface it opened with —+ * following the live width would tear down a playing editor and reload the+ * whole project mid-drag.+ */+export function useIsNarrowAtOpen(): boolean | null {+ const [narrow] = useState<boolean | null>(() =>+ typeof window === "undefined"+ ? null+ : window.matchMedia(`(max-width: ${NARROW_MAX_WIDTH - 1}px)`).matches+ );+ return narrow;+}