Production-ready animations, transitions, backgrounds, and scenes for Remotion
TypeScript ai-agentsclaude-codedemo-videomcpmcp-servermodel-context-protocolmotion-designproduct-demoreactremotionshadcnvideo
feat: remove lazy-loading, remove reduce motion
dev_wandryc054c672280e
diff --git a/bun.lock b/bun.lockindex 7b2b1c08..0affea07 100644--- a/bun.lock+++ b/bun.lock@@ -15,6 +15,7 @@"@remotion/renderer": "4.0.473","@remotion/transitions": "4.0.473","@shadcn/react": "^0.1.0",+ "@uidotdev/usehooks": "^2.4.1","class-variance-authority": "^0.7.1","clsx": "^2.1.1","cmdk": "^1.1.1",@@ -640,6 +641,8 @@"@types/webxr": ["@types/[email protected]", "", {}, "sha512-h8fgEd/DpoS9CBrjEQXR+dIDraopAEfu4wYVNY2tEPwk60stPWhvZMf4Foo5FakuQ7HFZoa8WceaWFervK2Ovg=="],+ "@uidotdev/usehooks": ["@uidotdev/[email protected]", "", { "peerDependencies": { "react": ">=18.0.0", "react-dom": ">=18.0.0" } }, "sha512-1I+RwWyS+kdv3Mv0Vmc+p0dPYH0DTRAo04HLyXReYBL9AeseDWUJyi4THuksBJcu9F0Pih69Ak150VDnqbVnXg=="],+"@ungap/structured-clone": ["@ungap/[email protected]", "", {}, "sha512-WmoN8qaIAo7WTYWbAZuG8PYEhn5fkz7dZrqTBZ7dtt//lL2Gwms1IcnQ5yHqjDfX8Ft5j4YzDM23f87zBfDe9g=="],"@webassemblyjs/ast": ["@webassemblyjs/[email protected]", "", { "dependencies": { "@webassemblyjs/helper-numbers": "1.13.2", "@webassemblyjs/helper-wasm-bytecode": "1.13.2" } }, "sha512-nuBEDgQfm1ccRp/8bCQrx1frohyufl4JlbMMZ4P1wpeOfDhF6FQkxZJ1b/e+PLwr6X1Nhw6OLme5usuBWYBvuQ=="],diff --git a/components/docs/component-card.tsx b/components/docs/component-card.tsxindex bbe58a36..a4367b51 100644--- a/components/docs/component-card.tsx+++ b/components/docs/component-card.tsx@@ -1,14 +1,12 @@"use client";-import { Player, type PlayerRef, Thumbnail } from "@remotion/player";+import { Player, type PlayerRef } from "@remotion/player";import Link from "next/link";-import { type ReactNode, useEffect, useRef, useState } from "react";+import { useRef } from "react";import { getDefaults } from "@/lib/customizer-config";-import { usePrefersReducedMotion } from "@/lib/use-prefers-reduced-motion";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) {@@ -21,44 +19,25 @@ function PreviewPlaceholder() {}function CardPreview({ item }: { item: CardItem }) {- const reducedMotion = usePrefersReducedMotion();- const ref = useRef<HTMLDivElement>(null);+ const slug = slugFromHref(item.href);+ const entry = slug ? registry[slug] : undefined;const playerRef = useRef<PlayerRef>(null);- const [inView, setInView] = useState(false);- const { resolvedTheme } = useTheme();- const backgroundColor = resolvedTheme === "dark" ? "#f5f5f5" : "#f5f5f5";+ useAutoplay(playerRef);- useEffect(() => {- if (inView) return;- const el = ref.current;- if (!el || typeof IntersectionObserver === "undefined") return;- const observer = new IntersectionObserver(- (entries) => {- if (entries.some((entry) => entry.isIntersecting)) {- setInView(true);- observer.disconnect();- }- },- { rootMargin: "200px 0px" },+ if (!entry) {+ return (+ <div className="size-full">+ <PreviewPlaceholder />+ </div>);- observer.observe(el);- return () => observer.disconnect();- }, [inView]);-- const slug = slugFromHref(item.href);- const entry = slug ? registry[slug] : undefined;+ }- useAutoplay(playerRef);+ const { Component, config } = entry;+ const inputProps = getDefaults(config.controls);- let content: ReactNode;- if (item.status !== "stable" || !entry || !inView) {- content = <PreviewPlaceholder />;- } else {- const { Component, config } = entry;- const inputProps = getDefaults(config.controls);- const playing = !reducedMotion;- content = playing ? (+ return (+ <div className="size-full"><Playerref={playerRef}component={Component}@@ -67,29 +46,11 @@ function CardPreview({ item }: { item: CardItem }) {fps={config.fps}compositionWidth={config.compositionWidth}compositionHeight={config.compositionHeight}- style={{ width: "100%", height: "100%", backgroundColor }}+ style={{ width: "100%", height: "100%", backgroundColor: "#f5f5f5" }}controls={false}loopacknowledgeRemotionLicense/>- ) : (- <Thumbnail- component={Component}- inputProps={inputProps}- durationInFrames={config.durationInFrames}- fps={config.fps}- compositionWidth={config.compositionWidth}- compositionHeight={config.compositionHeight}- frameToDisplay={0}- style={{ width: "100%", height: "100%" }}- acknowledgeRemotionLicense- />- );- }-- return (- <div ref={ref} className="size-full">- {content}</div>);}diff --git a/hooks/use-in-view.ts b/hooks/use-in-view.tsnew file mode 100644index 00000000..8da3de8b--- /dev/null+++ b/hooks/use-in-view.ts@@ -0,0 +1,14 @@+import { useIntersectionObserver } from "@uidotdev/usehooks";++export const useInView = () => {+ const [ref, entry] = useIntersectionObserver({+ threshold: 0,+ root: null,+ rootMargin: "0px",+ });++ return {+ ref,+ inView: entry?.isIntersecting,+ };+};diff --git a/package.json b/package.jsonindex 6de709ce..0463969e 100644--- a/package.json+++ b/package.json@@ -25,6 +25,7 @@"@remotion/renderer": "4.0.473","@remotion/transitions": "4.0.473","@shadcn/react": "^0.1.0",+ "@uidotdev/usehooks": "^2.4.1","class-variance-authority": "^0.7.1","clsx": "^2.1.1","cmdk": "^1.1.1",