Production-ready animations, transitions, backgrounds, and scenes for Remotion
TypeScript ai-agentsclaude-codedemo-videomcpmcp-servermodel-context-protocolmotion-designproduct-demoreactremotionshadcnvideo
feat: replace custom hook with use-auto-play
dev_wandry94021628424b
diff --git a/app/(home)/components/use-autoplay.ts b/app/(home)/components/use-autoplay.tsindex 05640290..7f36cc0a 100644--- a/app/(home)/components/use-autoplay.ts+++ b/app/(home)/components/use-autoplay.ts@@ -1,16 +1,6 @@import type { PlayerRef } from "@remotion/player";import { type RefObject, useEffect } from "react";-/**- * Reliable autoplay for a `<Player>`. The `autoPlay` prop is discouraged and- * programmatic `play()` is "not entirely deterministic" (Remotion docs) — the- * player can mount a tick before its imperative handle is ready, and on the- * landing page many Players mount at once, so a player often isn't ready within- * a frame or two. Mount the Player paused and drive `play()` here, retrying each- * animation frame until it actually reports playing (bounded so a genuinely- * blocked player can't spin forever). These compositions have no audio, so the- * browser autoplay policy permits programmatic playback.- */export function useAutoplay(playerRef: RefObject<PlayerRef | null>,enabled = true,diff --git a/components/docs/component-card.tsx b/components/docs/component-card.tsxindex bb05ffc9..bbe58a36 100644--- a/components/docs/component-card.tsx+++ b/components/docs/component-card.tsx@@ -9,6 +9,7 @@ import { cn } from "@/lib/utils";import registry from "@/registry/__index__";import type { CardItem } from "./component-card-grid";import { useTheme } from "next-themes";+import { useAutoplay } from "@/app/(home)/components/use-autoplay";function slugFromHref(href?: string) {if (!href) return undefined;@@ -47,29 +48,8 @@ function CardPreview({ item }: { item: CardItem }) {const slug = slugFromHref(item.href);const entry = slug ? registry[slug] : undefined;- const showPlayer =- item.status === "stable" && !!entry && inView && !reducedMotion;- // Same reliable-autoplay shim as PreviewStage: `<Player autoPlay>` mounts a- // tick before its imperative handle is ready and silently fails to start, so- // we drive play() via the ref once the player is shown, retrying once.- useEffect(() => {- if (!showPlayer) return;- let raf1 = 0;- let raf2 = 0;- raf1 = requestAnimationFrame(() => {- playerRef.current?.play();- raf2 = requestAnimationFrame(() => {- if (playerRef.current && !playerRef.current.isPlaying()) {- playerRef.current.play();- }- });- });- return () => {- if (raf1) cancelAnimationFrame(raf1);- if (raf2) cancelAnimationFrame(raf2);- };- }, [showPlayer]);+ useAutoplay(playerRef);let content: ReactNode;if (item.status !== "stable" || !entry || !inView) {