Skip to content

Open source CapCut alternative.

TypeScript

fix(site): keep session replay from recording the Cut editor and shared player

David Le49fe0ee14021
diff --git a/site/src/app/_components/NoSessionReplay.tsx b/site/src/app/_components/NoSessionReplay.tsx
new file mode 100644
index 00000000..3ac369c8
--- /dev/null
+++ b/site/src/app/_components/NoSessionReplay.tsx
@@ -0,0 +1,18 @@
+"use client";
+
+import posthog from "posthog-js";
+import { useEffect } from "react";
+
+// Mounted by surfaces that composite video onto a canvas every frame — the Cut
+// app and the shared player. Session replay's canvas capture reads that canvas
+// back off the GPU several times a second and records every timeline mutation
+// and media request, which degrades playback more the longer the tab lives, so
+// these surfaces never record. This stops a recorder that entered through a
+// client-side navigation; instrumentation-client.ts keeps direct loads from
+// starting one at all.
+export function NoSessionReplay() {
+ useEffect(() => {
+ if (process.env.NEXT_PUBLIC_POSTHOG_KEY) posthog.stopSessionRecording();
+ }, []);
+ return null;
+}
diff --git a/site/src/app/cut/app/layout.tsx b/site/src/app/cut/app/layout.tsx
index 4106e606..2ae5e794 100644
--- a/site/src/app/cut/app/layout.tsx
+++ b/site/src/app/cut/app/layout.tsx
@@ -1,6 +1,7 @@
import type { ReactNode } from "react";
import { AppSurfaceBackground } from "@/components/AppSurfaceBackground";
+import { NoSessionReplay } from "@/app/_components/NoSessionReplay";
import { ConnectGate } from "@/cut/components/ConnectGate";
import { ExportsDock } from "@/cut/components/ExportsDock";
import { CutOnboarding } from "@/cut/components/onboarding/CutOnboarding";
@@ -21,6 +22,7 @@ export default function CutAppLayout({ children }: { children: ReactNode }) {
return (
<div className="min-h-screen bg-white font-system text-foreground antialiased">
<AppSurfaceBackground />
+ <NoSessionReplay />
<RequireSession>
<ConnectGate>
{children}
diff --git a/site/src/app/cut/s/[token]/page.tsx b/site/src/app/cut/s/[token]/page.tsx
index a215dee2..bf9f2d91 100644
--- a/site/src/app/cut/s/[token]/page.tsx
+++ b/site/src/app/cut/s/[token]/page.tsx
@@ -1,6 +1,7 @@
import type { Metadata } from "next";
import { headers } from "next/headers";
import { shareMetaForToken } from "@/cut/server/cloud/shareCard";
+import { NoSessionReplay } from "@/app/_components/NoSessionReplay";
import { SharedProjectView } from "./SharedProjectView";
// The share page is a client view — it fetches its own access decision and
@@ -78,5 +79,10 @@ export async function generateMetadata({
}
export default function SharedProjectPage() {
- return <SharedProjectView />;
+ return (
+ <>
+ <NoSessionReplay />
+ <SharedProjectView />
+ </>
+ );
}
diff --git a/site/src/instrumentation-client.ts b/site/src/instrumentation-client.ts
index e01ceb8d..10c2d62c 100644
--- a/site/src/instrumentation-client.ts
+++ b/site/src/instrumentation-client.ts
@@ -1,8 +1,17 @@
import posthog from "posthog-js";
+// Surfaces that composite video onto a canvas every frame never record session
+// replay (see app/_components/NoSessionReplay.tsx): the Cut app and the shared
+// player, at their public paths and at the /cut/… routes the proxy serves them
+// from. Disabling at init keeps the recorder script from loading at all on a
+// direct load; NoSessionReplay stops a recorder carried in by a client-side
+// navigation.
+const REPLAY_FREE = /^\/(?:cut\/)?(?:app|s)(?:\/|$)/;
+
if (process.env.NEXT_PUBLIC_POSTHOG_KEY) {
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY, {
api_host: "https://us.i.posthog.com",
defaults: "2026-05-30",
+ disable_session_recording: REPLAY_FREE.test(window.location.pathname),
});
}