🎥 Make videos programmatically with React
revert style changes
Jonny Burgerf5f76eb7066b
diff --git a/packages/template-vercel/create-snapshot.ts b/packages/template-vercel/create-snapshot.tsindex ba98ccbe7c..36b88f66e8 100644--- a/packages/template-vercel/create-snapshot.ts+++ b/packages/template-vercel/create-snapshot.ts@@ -1,6 +1,8 @@import { createSandbox } from './src/app/api/render/sandbox/create-sandbox';import { saveSnapshotCache } from './src/app/api/render/sandbox/snapshots';+const SEVEN_DAYS_MS = 7 * 24 * 60 * 60 * 1000;+const sandbox = await createSandbox({onProgress: async (progress) => {if (progress.type === 'phase') {@@ -11,10 +13,18 @@ const sandbox = await createSandbox({});console.log('[create-snapshot] Taking snapshot...');-const snapshot = await sandbox.snapshot({ expiration: 0 });+const snapshot = await sandbox.snapshot(+ process.env.VERCEL ? { expiration: 0 } : undefined,+);++const expiresAt = process.env.VERCEL+ ? undefined+ : new Date(Date.now() + SEVEN_DAYS_MS);-await saveSnapshotCache(snapshot.snapshotId);+await saveSnapshotCache(snapshot.snapshotId, expiresAt);console.log(- `[create-snapshot] Snapshot saved: ${snapshot.snapshotId} (never expires)`,+ `[create-snapshot] Snapshot saved: ${snapshot.snapshotId}${+ expiresAt ? ` (expires ${expiresAt.toISOString()})` : ' (never expires)'+ }`,);diff --git a/packages/template-vercel/src/app/api/render/helpers.ts b/packages/template-vercel/src/app/api/render/helpers.tsindex 575a4b1d67..8b6291e026 100644--- a/packages/template-vercel/src/app/api/render/helpers.ts+++ b/packages/template-vercel/src/app/api/render/helpers.ts@@ -1,6 +1,6 @@-import { Sandbox } from "@vercel/sandbox";-import { readFile } from "fs/promises";-import path from "path";+import { Sandbox } from '@vercel/sandbox';+import { readFile } from 'fs/promises';+import path from 'path';export const createDisposableSandbox = async (options: Parameters<typeof Sandbox.create>[0],@@ -24,9 +24,9 @@ export const createDisposableWriter = (};export type RenderProgress =- | { type: "phase"; phase: string; progress: number }- | { type: "done"; url: string; size: number }- | { type: "error"; message: string };+ | { type: 'phase'; phase: string; progress: number; subtitle?: string }+ | { type: 'done'; url: string; size: number }+ | { type: 'error'; message: string };export type OnProgressFn = (message: RenderProgress) => Promise<void>;@@ -35,6 +35,6 @@ export function formatSSE(message: RenderProgress): string {}export async function getRenderScript(): Promise<Buffer> {- const renderScriptPath = path.join(process.cwd(), "render.ts");+ const renderScriptPath = path.join(process.cwd(), 'render.ts');return readFile(renderScriptPath);}diff --git a/packages/template-vercel/src/app/api/render/render.ts b/packages/template-vercel/src/app/api/render/render.tsindex b869db10af..7d850537bc 100644--- a/packages/template-vercel/src/app/api/render/render.ts+++ b/packages/template-vercel/src/app/api/render/render.ts@@ -1,12 +1,12 @@-import { Sandbox } from "@vercel/sandbox";-import { BUILD_DIR } from "../../../../build-dir.mjs";-import type { RenderConfig } from "../../../../render";-import { COMP_NAME } from "../../../../types/constants";+import { Sandbox } from '@vercel/sandbox';+import { BUILD_DIR } from '../../../../build-dir.mjs';+import type { RenderConfig } from '../../../../render';+import { COMP_NAME } from '../../../../types/constants';export type RenderInSandboxProgress =- | { type: "render-progress"; progress: number }- | { type: "uploading" }- | { type: "done"; url: string; size: number };+ | { type: 'render-progress'; progress: number }+ | { type: 'uploading' }+ | { type: 'done'; url: string; size: number };export async function renderInSandbox({sandbox,@@ -23,7 +23,7 @@ export async function renderInSandbox({const renderId = crypto.randomUUID();const blobToken = process.env.BLOB_READ_WRITE_TOKEN;if (!blobToken) {- throw new Error("BLOB_READ_WRITE_TOKEN is not set");+ throw new Error('BLOB_READ_WRITE_TOKEN is not set');}const renderConfig: RenderConfig = {@@ -36,8 +36,8 @@ export async function renderInSandbox({// Run the render scriptconst renderCmd = await sandbox.runCommand({- cmd: "node",- args: ["--strip-types", "render.ts", JSON.stringify(renderConfig)],+ cmd: 'node',+ args: ['--strip-types', 'render.ts', JSON.stringify(renderConfig)],detached: true,});@@ -45,17 +45,17 @@ export async function renderInSandbox({let doneSize: number | null = null;for await (const log of renderCmd.logs()) {- if (log.stream === "stdout") {+ if (log.stream === 'stdout') {try {const message = JSON.parse(log.data);- if (message.type === "progress") {+ if (message.type === 'progress') {await onProgress({- type: "render-progress",+ type: 'render-progress',progress: message.progress,});- } else if (message.type === "uploading") {- await onProgress({ type: "uploading" });- } else if (message.type === "done") {+ } else if (message.type === 'uploading') {+ await onProgress({ type: 'uploading' });+ } else if (message.type === 'done') {doneUrl = message.url;doneSize = message.size;}@@ -73,8 +73,8 @@ export async function renderInSandbox({}if (!doneUrl || doneSize === null) {- throw new Error("Render script did not return upload result");+ throw new Error('Render script did not return upload result');}- await onProgress({ type: "done", url: doneUrl, size: doneSize });+ await onProgress({ type: 'done', url: doneUrl, size: doneSize });}diff --git a/packages/template-vercel/src/app/api/render/route.ts b/packages/template-vercel/src/app/api/render/route.tsindex 9b2a38b8f2..11001ae104 100644--- a/packages/template-vercel/src/app/api/render/route.ts+++ b/packages/template-vercel/src/app/api/render/route.ts@@ -1,12 +1,12 @@-import { waitUntil } from "@vercel/functions";-import { RenderRequest } from "../../../../types/schema";+import { waitUntil } from '@vercel/functions';+import { RenderRequest } from '../../../../types/schema';import {createDisposableWriter,formatSSE,type RenderProgress,-} from "./helpers";-import { renderInSandbox } from "./render";-import { getSandbox } from "./sandbox/get-sandbox";+} from './helpers';+import { renderInSandbox } from './render';+import { reuseOrCreateSandbox } from './sandbox/reuse-or-create-sandbox';export async function POST(req: Request) {const encoder = new TextEncoder();@@ -25,33 +25,33 @@ export async function POST(req: Request) {const payload = await req.json();const body = RenderRequest.parse(payload);- await using sandbox = await getSandbox();- const renderingPhase = "Rendering video...";- await send({ type: "phase", phase: renderingPhase, progress: 0 });+ await using sandbox = await reuseOrCreateSandbox(send);+ const renderingPhase = 'Rendering video...';+ await send({ type: 'phase', phase: renderingPhase, progress: 0 });await renderInSandbox({sandbox,inputProps: body.inputProps,onProgress: async (update) => {- if (update.type === "render-progress") {+ if (update.type === 'render-progress') {await send({- type: "phase",+ type: 'phase',phase: renderingPhase,progress: update.progress,});- } else if (update.type === "uploading") {+ } else if (update.type === 'uploading') {await send({- type: "phase",- phase: "Uploading video...",+ type: 'phase',+ phase: 'Uploading video...',progress: 1,});- } else if (update.type === "done") {- await send({ type: "done", url: update.url, size: update.size });+ } else if (update.type === 'done') {+ await send({ type: 'done', url: update.url, size: update.size });}},});} catch (err) {console.log(err);- await send({ type: "error", message: (err as Error).message });+ await send({ type: 'error', message: (err as Error).message });}};@@ -59,9 +59,9 @@ export async function POST(req: Request) {return new Response(stream.readable, {headers: {- "Content-Type": "text/event-stream",- "Cache-Control": "no-cache",- Connection: "keep-alive",+ 'Content-Type': 'text/event-stream',+ 'Cache-Control': 'no-cache',+ Connection: 'keep-alive',},});}diff --git a/packages/template-vercel/src/app/api/render/sandbox/add-bundle.ts b/packages/template-vercel/src/app/api/render/sandbox/add-bundle.tsindex 963fe1cbe9..6ff60b73c2 100644--- a/packages/template-vercel/src/app/api/render/sandbox/add-bundle.ts+++ b/packages/template-vercel/src/app/api/render/sandbox/add-bundle.ts@@ -1,9 +1,9 @@-import { Sandbox } from "@vercel/sandbox";-import { execSync } from "child_process";-import { existsSync } from "fs";-import { readdir, readFile } from "fs/promises";-import path from "path";-import { BUILD_DIR } from "../../../../../build-dir.mjs";+import { Sandbox } from '@vercel/sandbox';+import { execSync } from 'child_process';+import { existsSync } from 'fs';+import { readdir, readFile } from 'fs/promises';+import path from 'path';+import { BUILD_DIR } from '../../../../../build-dir.mjs';export const addBundleToSandbox = async (sandbox: Sandbox & AsyncDisposable,@@ -14,18 +14,18 @@ export const addBundleToSandbox = async (const dirs = new Set<string>();for (const file of bundleFiles) {const dir = path.dirname(file.path);- if (dir && dir !== ".") {+ if (dir && dir !== '.') {dirs.add(dir);}}for (const dir of Array.from(dirs).sort()) {- await sandbox.mkDir(BUILD_DIR + "/" + dir);+ await sandbox.mkDir(BUILD_DIR + '/' + dir);}await sandbox.writeFiles(bundleFiles.map((file) => ({- path: BUILD_DIR + "/" + file.path,+ path: BUILD_DIR + '/' + file.path,content: file.content,})),);@@ -40,7 +40,7 @@ async function getRemotionBundleFiles(): Promise<const files: { path: string; content: Buffer }[] = [];- async function readDirRecursive(dir: string, basePath: string = "") {+ async function readDirRecursive(dir: string, basePath: string = '') {const entries = await readdir(dir, { withFileTypes: true });for (const entry of entries) {const fullPath = path.join(dir, entry.name);@@ -68,10 +68,10 @@ async function ensureLocalBundle(): Promise<void> {try {execSync(`node_modules/.bin/remotion bundle --out-dir ./${BUILD_DIR}`, {cwd: process.cwd(),- stdio: "pipe",+ stdio: 'pipe',});} catch (e) {- const stderr = (e as { stderr?: Buffer }).stderr?.toString() ?? "";+ const stderr = (e as { stderr?: Buffer }).stderr?.toString() ?? '';throw new Error(`Remotion bundle failed: ${stderr}`);}}diff --git a/packages/template-vercel/src/app/api/render/sandbox/create-sandbox.ts b/packages/template-vercel/src/app/api/render/sandbox/create-sandbox.tsindex e04f89a8dc..37b3e453e7 100644--- a/packages/template-vercel/src/app/api/render/sandbox/create-sandbox.ts+++ b/packages/template-vercel/src/app/api/render/sandbox/create-sandbox.ts@@ -1,14 +1,14 @@-import { Sandbox } from "@vercel/sandbox";+import { Sandbox } from '@vercel/sandbox';import {createDisposableSandbox,getRenderScript,OnProgressFn,-} from "../helpers";-import { addBundleToSandbox } from "./add-bundle";-import { installBrowser } from "./install-browser";-import { installJsDependencies } from "./install-js-dependencies";-import { installSystemDependencies } from "./install-system-dependencies";-import { patchCompositor } from "./patch-compositor";+} from '../helpers';+import { addBundleToSandbox } from './add-bundle';+import { installBrowser } from './install-browser';+import { installJsDependencies } from './install-js-dependencies';+import { installSystemDependencies } from './install-system-dependencies';+import { patchCompositor } from './patch-compositor';export async function createSandbox({onProgress,@@ -16,12 +16,15 @@ export async function createSandbox({onProgress: OnProgressFn;}): Promise<Sandbox & AsyncDisposable> {const sandbox = await createDisposableSandbox({- runtime: "node24",+ runtime: 'node24',resources: { vcpus: 4 },timeout: 5 * 60 * 1000,});- const preparingPhase = "Preparing...";+ const preparingPhase = 'Preparing...';+ const preparingSubtitle = process.env.VERCEL+ ? 'This only needs to be done once.'+ : 'This is only needed during development.';// Preparation has 3 stages with weights:// - System dependencies: 60%@@ -32,8 +35,9 @@ export async function createSandbox({const WEIGHT_BROWSER = 0.2;await onProgress({- type: "phase",+ type: 'phase',phase: preparingPhase,+ subtitle: preparingSubtitle,progress: 0,});@@ -42,25 +46,28 @@ export async function createSandbox({sandbox,onProgress: async (stageProgress: number) => {await onProgress({- type: "phase",+ type: 'phase',phase: preparingPhase,+ subtitle: preparingSubtitle,progress: stageProgress * WEIGHT_SYS_DEPS,});},});await onProgress({- type: "phase",- phase: "Adding Remotion video to Sandbox...",+ type: 'phase',+ phase: 'Adding Remotion video to Sandbox...',progress: 0,+ subtitle: preparingSubtitle,});// Stage 2: Copy Remotion bundle (20%)await addBundleToSandbox(sandbox);await onProgress({- type: "phase",+ type: 'phase',phase: preparingPhase,+ subtitle: preparingSubtitle,progress: WEIGHT_SYS_DEPS + WEIGHT_BUNDLE,});@@ -75,8 +82,9 @@ export async function createSandbox({sandbox,onProgress: async (browserProgress: number) => {await onProgress({- type: "phase",+ type: 'phase',phase: preparingPhase,+ subtitle: preparingSubtitle,progress:WEIGHT_SYS_DEPS + WEIGHT_BUNDLE + browserProgress * WEIGHT_BROWSER,});@@ -86,12 +94,12 @@ export async function createSandbox({const renderScript = await getRenderScript();await sandbox.writeFiles([{- path: "render.ts",+ path: 'render.ts',content: renderScript,},{- path: "package.json",- content: Buffer.from(JSON.stringify({ type: "module" })),+ path: 'package.json',+ content: Buffer.from(JSON.stringify({ type: 'module' })),},]);diff --git a/packages/template-vercel/src/app/api/render/sandbox/get-sandbox.ts b/packages/template-vercel/src/app/api/render/sandbox/get-sandbox.tsdeleted file mode 100644index 5978c114b9..0000000000--- a/packages/template-vercel/src/app/api/render/sandbox/get-sandbox.ts+++ /dev/null@@ -1,20 +0,0 @@-import { Sandbox } from "@vercel/sandbox";-import { createDisposableSandbox } from "../helpers";-import { getCachedSnapshot } from "./snapshots";--const TIMEOUT = 5 * 60 * 1000;--export async function getSandbox(): Promise<Sandbox & AsyncDisposable> {- const cachedSnapshotId = await getCachedSnapshot();-- if (!cachedSnapshotId) {- throw new Error(- "No sandbox snapshot found. Run `bun run create-snapshot` first.",- );- }-- return await createDisposableSandbox({- source: { type: "snapshot", snapshotId: cachedSnapshotId },- timeout: TIMEOUT,- });-}diff --git a/packages/template-vercel/src/app/api/render/sandbox/install-browser.ts b/packages/template-vercel/src/app/api/render/sandbox/install-browser.tsindex 233a50fccc..e3333539b6 100644--- a/packages/template-vercel/src/app/api/render/sandbox/install-browser.ts+++ b/packages/template-vercel/src/app/api/render/sandbox/install-browser.ts@@ -1,9 +1,9 @@-import { Sandbox } from "@vercel/sandbox";-import { readFile } from "fs/promises";-import path from "path";+import { Sandbox } from '@vercel/sandbox';+import { readFile } from 'fs/promises';+import path from 'path';async function getEnsureBrowserScript(): Promise<Buffer> {- const scriptPath = path.join(process.cwd(), "ensure-browser.ts");+ const scriptPath = path.join(process.cwd(), 'ensure-browser.ts');return readFile(scriptPath);}@@ -17,22 +17,22 @@ export async function installBrowser({const ensureBrowserScript = await getEnsureBrowserScript();await sandbox.writeFiles([{- path: "ensure-browser.ts",+ path: 'ensure-browser.ts',content: ensureBrowserScript,},]);const ensureBrowserCmd = await sandbox.runCommand({- cmd: "node",- args: ["--strip-types", "ensure-browser.ts"],+ cmd: 'node',+ args: ['--strip-types', 'ensure-browser.ts'],detached: true,});for await (const log of ensureBrowserCmd.logs()) {- if (log.stream === "stdout") {+ if (log.stream === 'stdout') {try {const message = JSON.parse(log.data);- if (message.type === "browser-progress") {+ if (message.type === 'browser-progress') {await onProgress(message.percent ?? 0);continue;}diff --git a/packages/template-vercel/src/app/api/render/sandbox/install-js-dependencies.ts b/packages/template-vercel/src/app/api/render/sandbox/install-js-dependencies.tsindex d7a0d66918..cd38cea4a4 100644--- a/packages/template-vercel/src/app/api/render/sandbox/install-js-dependencies.ts+++ b/packages/template-vercel/src/app/api/render/sandbox/install-js-dependencies.ts@@ -1,5 +1,5 @@-import { Sandbox } from "@vercel/sandbox";-import { VERSION } from "remotion/version";+import { Sandbox } from '@vercel/sandbox';+import { VERSION } from 'remotion/version';export async function installJsDependencies({sandbox,@@ -7,7 +7,7 @@ export async function installJsDependencies({sandbox: Sandbox;}): Promise<void> {const installCmd = await sandbox.runCommand({- cmd: "pnpm",+ cmd: 'pnpm',args: [`i`,`@remotion/renderer@${VERSION}`,diff --git a/packages/template-vercel/src/app/api/render/sandbox/install-system-dependencies.ts b/packages/template-vercel/src/app/api/render/sandbox/install-system-dependencies.tsindex 06c12a5b88..e889e191bb 100644--- a/packages/template-vercel/src/app/api/render/sandbox/install-system-dependencies.ts+++ b/packages/template-vercel/src/app/api/render/sandbox/install-system-dependencies.ts@@ -1,4 +1,4 @@-import { Sandbox } from "@vercel/sandbox";+import { Sandbox } from '@vercel/sandbox';export async function installSystemDependencies({sandbox,@@ -8,26 +8,26 @@ export async function installSystemDependencies({onProgress: (progress: number) => Promise<void>;}): Promise<void> {const sysInstallCmd = await sandbox.runCommand({- cmd: "sudo",+ cmd: 'sudo',args: [- "dnf",- "install",- "-y",- "nss",- "atk",- "at-spi2-atk",- "cups-libs",- "libdrm",- "libXcomposite",- "libXdamage",- "libXrandr",- "mesa-libgbm",- "alsa-lib",- "pango",- "gtk3",- "patchelf",- "zstd",- "binutils",+ 'dnf',+ 'install',+ '-y',+ 'nss',+ 'atk',+ 'at-spi2-atk',+ 'cups-libs',+ 'libdrm',+ 'libXcomposite',+ 'libXdamage',+ 'libXrandr',+ 'mesa-libgbm',+ 'alsa-lib',+ 'pango',+ 'gtk3',+ 'patchelf',+ 'zstd',+ 'binutils',],detached: true,});diff --git a/packages/template-vercel/src/app/api/render/sandbox/patch-compositor.ts b/packages/template-vercel/src/app/api/render/sandbox/patch-compositor.tsindex cc621a25fd..251516fb61 100644--- a/packages/template-vercel/src/app/api/render/sandbox/patch-compositor.ts+++ b/packages/template-vercel/src/app/api/render/sandbox/patch-compositor.ts@@ -1,8 +1,8 @@-import { Sandbox } from "@vercel/sandbox";+import { Sandbox } from '@vercel/sandbox';-const GLIBC_DIR = "/tmp/glibc235";+const GLIBC_DIR = '/tmp/glibc235';const LIBC6_DEB_URL =- "https://launchpadlibrarian.net/612471225/libc6_2.35-0ubuntu3.1_amd64.deb";+ 'https://launchpadlibrarian.net/612471225/libc6_2.35-0ubuntu3.1_amd64.deb';/*** Remotion does not officially support glibc 2.34, but it can be patched.@@ -88,8 +88,8 @@ echo "[patch-compositor] Compositor patched successfully"`;const cmd = await sandbox.runCommand({- cmd: "bash",- args: ["-c", script],+ cmd: 'bash',+ args: ['-c', script],detached: true,});diff --git a/packages/template-vercel/src/app/api/render/sandbox/reuse-or-create-sandbox.ts b/packages/template-vercel/src/app/api/render/sandbox/reuse-or-create-sandbox.tsnew file mode 100644index 0000000000..05da214b4f--- /dev/null+++ b/packages/template-vercel/src/app/api/render/sandbox/reuse-or-create-sandbox.ts@@ -0,0 +1,41 @@+import { Sandbox } from '@vercel/sandbox';+import { createDisposableSandbox, OnProgressFn } from '../helpers';+import { createSandbox } from './create-sandbox';+import { getCachedSnapshot } from './snapshots';++const TIMEOUT = 5 * 60 * 1000;++export async function reuseOrCreateSandbox(+ onProgress: OnProgressFn,+): Promise<Sandbox & AsyncDisposable> {+ await onProgress({+ type: 'phase',+ phase: 'Creating sandbox...',+ progress: 0,+ });++ // In production, the snapshot is created at build time via `create-snapshot`+ const cachedSnapshotId = await getCachedSnapshot();++ if (cachedSnapshotId) {+ try {+ return await createDisposableSandbox({+ source: { type: 'snapshot', snapshotId: cachedSnapshotId },+ timeout: TIMEOUT,+ });+ } catch {+ if (process.env.VERCEL) {+ throw new Error('Failed to create sandbox from snapshot');+ }++ // In development, fall through to full setup+ }+ } else if (process.env.VERCEL) {+ throw new Error(+ 'No sandbox snapshot found. Run `bun run create-snapshot` first.',+ );+ }++ // Local development: create sandbox from scratch (no snapshotting)+ return await createSandbox({ onProgress });+}diff --git a/packages/template-vercel/src/app/api/render/sandbox/snapshots.ts b/packages/template-vercel/src/app/api/render/sandbox/snapshots.tsindex 31b9b158e0..e3eac389d3 100644--- a/packages/template-vercel/src/app/api/render/sandbox/snapshots.ts+++ b/packages/template-vercel/src/app/api/render/sandbox/snapshots.ts@@ -1,10 +1,11 @@-import { head, put } from "@vercel/blob";+import { head, put } from '@vercel/blob';type SnapshotCache = {snapshotId: string;+ expiresAt?: string;};-const SNAPSHOT_BLOB_KEY = `snapshot-cache/${process.env.VERCEL_DEPLOYMENT_ID ?? "local"}.json`;+const SNAPSHOT_BLOB_KEY = `snapshot-cache/${process.env.VERCEL_DEPLOYMENT_ID ?? 'local'}.json`;export async function getCachedSnapshot(): Promise<string | null> {if (!process.env.VERCEL) {@@ -16,20 +17,28 @@ export async function getCachedSnapshot(): Promise<string | null> {const response = await fetch(metadata.url);const cache: SnapshotCache = await response.json();+ if (cache.expiresAt && new Date(cache.expiresAt) < new Date()) {+ return null;+ }+return cache.snapshotId;} catch {return null;}}-export async function saveSnapshotCache(snapshotId: string): Promise<void> {+export async function saveSnapshotCache(+ snapshotId: string,+ expiresAt?: Date,+): Promise<void> {const cache: SnapshotCache = {snapshotId,+ ...(expiresAt ? { expiresAt: expiresAt.toISOString() } : {}),};await put(SNAPSHOT_BLOB_KEY, JSON.stringify(cache), {- access: "public",- contentType: "application/json",+ access: 'public',+ contentType: 'application/json',addRandomSuffix: false,});}diff --git a/packages/template-vercel/src/app/layout.tsx b/packages/template-vercel/src/app/layout.tsxindex 296ec01712..0ce8a02457 100644--- a/packages/template-vercel/src/app/layout.tsx+++ b/packages/template-vercel/src/app/layout.tsx@@ -1,13 +1,13 @@-import { Metadata, Viewport } from "next";-import "../../styles/global.css";+import { Metadata, Viewport } from 'next';+import '../../styles/global.css';export const metadata: Metadata = {- title: "Remotion rendering on Vercel Sandbox",- description: "Remotion rendering on Vercel Sandbox",+ title: 'Remotion rendering on Vercel Sandbox',+ description: 'Remotion rendering on Vercel Sandbox',};export const viewport: Viewport = {- width: "device-width",+ width: 'device-width',initialScale: 1,maximumScale: 1,};diff --git a/packages/template-vercel/src/app/page.tsx b/packages/template-vercel/src/app/page.tsxindex 4b225065c5..53515295c9 100644--- a/packages/template-vercel/src/app/page.tsx+++ b/packages/template-vercel/src/app/page.tsx@@ -1,9 +1,9 @@-"use client";+'use client';-import { Player } from "@remotion/player";-import type { NextPage } from "next";-import { useMemo, useState } from "react";-import { z } from "zod";+import { Player } from '@remotion/player';+import type { NextPage } from 'next';+import { useMemo, useState } from 'react';+import { z } from 'zod';import {CompositionProps,defaultMyCompProps,@@ -11,10 +11,10 @@ import {VIDEO_FPS,VIDEO_HEIGHT,VIDEO_WIDTH,-} from "../../types/constants";-import { RenderControls } from "../components/RenderControls";-import { Tips } from "../components/Tips";-import { Main } from "../remotion/MyComp/Main";+} from '../../types/constants';+import { RenderControls } from '../components/RenderControls';+import { Tips } from '../components/Tips';+import { Main } from '../remotion/MyComp/Main';const Home: NextPage = () => {const [text, setText] = useState<string>(defaultMyCompProps.title);@@ -37,7 +37,7 @@ const Home: NextPage = () => {compositionHeight={VIDEO_HEIGHT}compositionWidth={VIDEO_WIDTH}style={{- width: "100%",+ width: '100%',}}controlsautoPlaydiff --git a/packages/template-vercel/src/components/AlignEnd.tsx b/packages/template-vercel/src/components/AlignEnd.tsxindex 834b07ab2d..3c48b89036 100644--- a/packages/template-vercel/src/components/AlignEnd.tsx+++ b/packages/template-vercel/src/components/AlignEnd.tsx@@ -1,8 +1,8 @@-import React from "react";+import React from 'react';export const AlignEnd: React.FC<{children: React.ReactNode;className?: string;}> = ({ children, className }) => {- return <div className={`self-end ${className ?? ""}`}>{children}</div>;+ return <div className={`self-end ${className ?? ''}`}>{children}</div>;};diff --git a/packages/template-vercel/src/components/Button.tsx b/packages/template-vercel/src/components/Button.tsxindex c717c2e94a..4b49513f6b 100644--- a/packages/template-vercel/src/components/Button.tsx+++ b/packages/template-vercel/src/components/Button.tsx@@ -1,7 +1,7 @@-import React, { forwardRef } from "react";-import { cn } from "../lib/utils";-import { Spacing } from "./Spacing";-import { Spinner } from "./Spinner";+import React, { forwardRef } from 'react';+import { cn } from '../lib/utils';+import { Spacing } from './Spacing';+import { Spinner } from './Spinner';const ButtonForward: React.ForwardRefRenderFunction<HTMLButtonElement,@@ -17,9 +17,9 @@ const ButtonForward: React.ForwardRefRenderFunction<<buttonref={ref}className={cn(- "border-foreground border rounded-geist bg-foreground text-background px-geist-half font-geist h-10 font-medium transition-all duration-150 ease-in-out inline-flex items-center appearance-none text-sm hover:bg-background hover:text-foreground hover:border-focused-border-color disabled:bg-button-disabled-color disabled:text-disabled-text-color disabled:border-unfocused-border-color disabled:cursor-not-allowed",+ 'border-foreground border rounded-geist bg-foreground text-background px-geist-half font-geist h-10 font-medium transition-all duration-150 ease-in-out inline-flex items-center appearance-none text-sm hover:bg-background hover:text-foreground hover:border-focused-border-color disabled:bg-button-disabled-color disabled:text-disabled-text-color disabled:border-unfocused-border-color disabled:cursor-not-allowed',secondary- ? "bg-background text-foreground border-unfocused-border-color"+ ? 'bg-background text-foreground border-unfocused-border-color': undefined,)}onClick={onClick}diff --git a/packages/template-vercel/src/components/Container.tsx b/packages/template-vercel/src/components/Container.tsxindex 19cbcb59e5..9703b44927 100644--- a/packages/template-vercel/src/components/Container.tsx+++ b/packages/template-vercel/src/components/Container.tsx@@ -1,4 +1,4 @@-import React from "react";+import React from 'react';export const InputContainer: React.FC<{children: React.ReactNode;diff --git a/packages/template-vercel/src/components/DownloadButton.tsx b/packages/template-vercel/src/components/DownloadButton.tsxindex 0ffa9576ba..99e8718a74 100644--- a/packages/template-vercel/src/components/DownloadButton.tsx+++ b/packages/template-vercel/src/components/DownloadButton.tsx@@ -1,16 +1,16 @@-import React from "react";-import { State } from "../helpers/use-rendering";-import { Button } from "./Button";-import { Spacing } from "./Spacing";+import React from 'react';+import { State } from '../helpers/use-rendering';+import { Button } from './Button';+import { Spacing } from './Spacing';const Megabytes: React.FC<{sizeInBytes: number;}> = ({ sizeInBytes }) => {- const megabytes = Intl.NumberFormat("en", {- notation: "compact",- style: "unit",- unit: "byte",- unitDisplay: "narrow",+ const megabytes = Intl.NumberFormat('en', {+ notation: 'compact',+ style: 'unit',+ unit: 'byte',+ unitDisplay: 'narrow',}).format(sizeInBytes);return <span className="opacity-60">{megabytes}</span>;};@@ -19,8 +19,8 @@ export const DownloadButton: React.FC<{state: State;undo: () => void;}> = ({ state, undo }) => {- if (state.status !== "done") {- throw new Error("Download button should not be rendered when not done");+ if (state.status !== 'done') {+ throw new Error('Download button should not be rendered when not done');}return (diff --git a/packages/template-vercel/src/components/Error.tsx b/packages/template-vercel/src/components/Error.tsxindex 28020e53c2..2df268555a 100644--- a/packages/template-vercel/src/components/Error.tsx+++ b/packages/template-vercel/src/components/Error.tsx@@ -1,4 +1,4 @@-import React from "react";+import React from 'react';export const ErrorComp: React.FC<{message: string;diff --git a/packages/template-vercel/src/components/Input.tsx b/packages/template-vercel/src/components/Input.tsxindex b31484af23..654e50364d 100644--- a/packages/template-vercel/src/components/Input.tsx+++ b/packages/template-vercel/src/components/Input.tsx@@ -1,4 +1,4 @@-import React, { useCallback } from "react";+import React, { useCallback } from 'react';export const Input: React.FC<{text: string;diff --git a/packages/template-vercel/src/components/ProgressBar.tsx b/packages/template-vercel/src/components/ProgressBar.tsxindex 7eac570836..224c0a2bed 100644--- a/packages/template-vercel/src/components/ProgressBar.tsx+++ b/packages/template-vercel/src/components/ProgressBar.tsx@@ -1,4 +1,4 @@-import React, { useMemo } from "react";+import React, { useMemo } from 'react';export const ProgressBar: React.FC<{progress: number;diff --git a/packages/template-vercel/src/components/RenderControls.tsx b/packages/template-vercel/src/components/RenderControls.tsxindex c3f0e0bda6..332f82b234 100644--- a/packages/template-vercel/src/components/RenderControls.tsx+++ b/packages/template-vercel/src/components/RenderControls.tsx@@ -1,14 +1,14 @@-import { z } from "zod";-import { COMP_NAME, CompositionProps } from "../../types/constants";-import { useRendering } from "../helpers/use-rendering";-import { AlignEnd } from "./AlignEnd";-import { Button } from "./Button";-import { InputContainer } from "./Container";-import { DownloadButton } from "./DownloadButton";-import { ErrorComp } from "./Error";-import { Input } from "./Input";-import { ProgressBar } from "./ProgressBar";-import { Spacing } from "./Spacing";+import { z } from 'zod';+import { COMP_NAME, CompositionProps } from '../../types/constants';+import { useRendering } from '../helpers/use-rendering';+import { AlignEnd } from './AlignEnd';+import { Button } from './Button';+import { InputContainer } from './Container';+import { DownloadButton } from './DownloadButton';+import { ErrorComp } from './Error';+import { Input } from './Input';+import { ProgressBar } from './ProgressBar';+import { Spacing } from './Spacing';export const RenderControls: React.FC<{text: string;@@ -19,51 +19,60 @@ export const RenderControls: React.FC<{return (<InputContainer>- {state.status === "init" ||- state.status === "invoking" ||- state.status === "error" ? (+ {state.status === 'init' ||+ state.status === 'invoking' ||+ state.status === 'error' ? (<><Input- disabled={state.status === "invoking"}+ disabled={state.status === 'invoking'}setText={setText}text={text}></Input><AlignEnd className="mt-4"><Button- disabled={state.status === "invoking"}- loading={state.status === "invoking"}+ disabled={state.status === 'invoking'}+ loading={state.status === 'invoking'}onClick={renderMedia}>Render video</Button></AlignEnd>- {state.status === "invoking" ? (+ {state.status === 'invoking' ? (<><Spacing></Spacing><divstyle={{fontSize: 14,lineHeight: 1.5,- minHeight: "2.5em",+ minHeight: '2.5em',marginBottom: 8,}}>- <div style={{ color: "#666" }}>+ <div style={{ color: '#666' }}>{state.phase}{state.progress < 1? ` ${Math.max(Math.round(state.progress * 100), 1)}%`: null}</div>+ <div+ style={{+ color: '#999',+ fontSize: 12,+ visibility: state.subtitle ? 'visible' : 'hidden',+ }}+ >+ {state.subtitle ?? '\u00A0'}+ </div></div><ProgressBar progress={state.progress} /></>) : null}- {state.status === "error" ? (+ {state.status === 'error' ? (<ErrorComp message={state.error.message}></ErrorComp>) : null}</>) : null}- {state.status === "done" ? (+ {state.status === 'done' ? (<><ProgressBar progress={1} /><Spacing></Spacing>diff --git a/packages/template-vercel/src/components/Spacing.tsx b/packages/template-vercel/src/components/Spacing.tsxindex c901cfdadb..742905d320 100644--- a/packages/template-vercel/src/components/Spacing.tsx+++ b/packages/template-vercel/src/components/Spacing.tsx@@ -1,4 +1,4 @@-import React from "react";+import React from 'react';export const Spacing: React.FC = () => {return <div className="w-geist-quarter h-geist-quarter" />;diff --git a/packages/template-vercel/src/components/Spinner.tsx b/packages/template-vercel/src/components/Spinner.tsxindex 2c88b26509..e1cae300fa 100644--- a/packages/template-vercel/src/components/Spinner.tsx+++ b/packages/template-vercel/src/components/Spinner.tsx@@ -1,6 +1,6 @@-import { translatePath } from "@remotion/paths";-import { makeRect } from "@remotion/shapes";-import React, { useMemo } from "react";+import { translatePath } from '@remotion/paths';+import { makeRect } from '@remotion/shapes';+import React, { useMemo } from 'react';const viewBox = 100;const lines = 12;@@ -32,7 +32,7 @@ export const Spinner: React.FC<{className="animate-spinner"style={{rotate: `${(index * Math.PI * 2) / lines}rad`,- transformOrigin: "center center",+ transformOrigin: 'center center',animationDelay: `${index * 0.1 - lines * 0.1}s`,}}key={index}diff --git a/packages/template-vercel/src/components/Tips.tsx b/packages/template-vercel/src/components/Tips.tsxindex 3f88e15754..dbfb3b9050 100644--- a/packages/template-vercel/src/components/Tips.tsx+++ b/packages/template-vercel/src/components/Tips.tsx@@ -1,4 +1,4 @@-import React from "react";+import React from 'react';const Tip: React.FC<{title: React.ReactNode;diff --git a/packages/template-vercel/src/helpers/api-response.ts b/packages/template-vercel/src/helpers/api-response.tsindex d4da4ce786..574a3134ae 100644--- a/packages/template-vercel/src/helpers/api-response.ts+++ b/packages/template-vercel/src/helpers/api-response.ts@@ -1,13 +1,13 @@-import { NextResponse } from "next/server";-import { z, ZodType } from "zod";+import { NextResponse } from 'next/server';+import { z, ZodType } from 'zod';export type ApiResponse<Res> =| {- type: "error";+ type: 'error';message: string;}| {- type: "success";+ type: 'success';data: Res;};@@ -22,12 +22,12 @@ export const executeApi =const parsed = schema.parse(payload);const data = await handler(req, parsed);return NextResponse.json({- type: "success",+ type: 'success',data: data,});} catch (err) {return NextResponse.json(- { type: "error", message: (err as Error).message },+ { type: 'error', message: (err as Error).message },{status: 500,},diff --git a/packages/template-vercel/src/helpers/use-rendering.ts b/packages/template-vercel/src/helpers/use-rendering.tsindex 5b0a636a1e..0e57ab2989 100644--- a/packages/template-vercel/src/helpers/use-rendering.ts+++ b/packages/template-vercel/src/helpers/use-rendering.ts@@ -1,25 +1,26 @@-import { useCallback, useMemo, useState } from "react";-import { z } from "zod";-import { CompositionProps } from "../../types/constants";-import { SSEMessage } from "../../types/schema";+import { useCallback, useMemo, useState } from 'react';+import { z } from 'zod';+import { CompositionProps } from '../../types/constants';+import { SSEMessage } from '../../types/schema';export type State =| {- status: "init";+ status: 'init';}| {- status: "invoking";+ status: 'invoking';phase: string;progress: number;+ subtitle: string | null;}| {- status: "error";+ status: 'error';error: Error;}| {url: string;size: number;- status: "done";+ status: 'done';};export const useRendering = (@@ -27,63 +28,65 @@ export const useRendering = (inputProps: z.infer<typeof CompositionProps>,) => {const [state, setState] = useState<State>({- status: "init",+ status: 'init',});const renderMedia = useCallback(async () => {setState({- status: "invoking",- phase: "Starting...",+ status: 'invoking',+ phase: 'Starting...',progress: 0,+ subtitle: null,});try {- const response = await fetch("/api/render", {- method: "POST",- headers: { "content-type": "application/json" },+ const response = await fetch('/api/render', {+ method: 'POST',+ headers: { 'content-type': 'application/json' },body: JSON.stringify({ id, inputProps }),});if (!response.ok || !response.body) {- throw new Error("Failed to start render");+ throw new Error('Failed to start render');}const reader = response.body.getReader();const decoder = new TextDecoder();- let buffer = "";+ let buffer = '';while (true) {const { done, value } = await reader.read();if (done) break;buffer += decoder.decode(value, { stream: true });- const lines = buffer.split("\n\n");- buffer = lines.pop() || "";+ const lines = buffer.split('\n\n');+ buffer = lines.pop() || '';for (const line of lines) {- if (!line.startsWith("data: ")) continue;+ if (!line.startsWith('data: ')) continue;const json = line.slice(6);const message = JSON.parse(json) as SSEMessage;- if (message.type === "phase") {+ if (message.type === 'phase') {setState((prev) => {- if (prev.status !== "invoking") return prev;+ if (prev.status !== 'invoking') return prev;return {...prev,phase: message.phase,progress: message.progress,+ subtitle: message.subtitle ?? null,};});- } else if (message.type === "done") {+ } else if (message.type === 'done') {setState({- status: "done",+ status: 'done',url: message.url,size: message.size,});- } else if (message.type === "error") {+ } else if (message.type === 'error') {setState({- status: "error",+ status: 'error',error: new Error(message.message),});}@@ -91,14 +94,14 @@ export const useRendering = (}} catch (err) {setState({- status: "error",+ status: 'error',error: err as Error,});}}, [id, inputProps]);const undo = useCallback(() => {- setState({ status: "init" });+ setState({ status: 'init' });}, []);return useMemo(() => {diff --git a/packages/template-vercel/src/lib/utils.ts b/packages/template-vercel/src/lib/utils.tsindex a5ef193506..2819a830d2 100644--- a/packages/template-vercel/src/lib/utils.ts+++ b/packages/template-vercel/src/lib/utils.ts@@ -1,5 +1,5 @@-import { clsx, type ClassValue } from "clsx";-import { twMerge } from "tailwind-merge";+import { clsx, type ClassValue } from 'clsx';+import { twMerge } from 'tailwind-merge';export function cn(...inputs: ClassValue[]) {return twMerge(clsx(inputs));diff --git a/packages/template-vercel/src/remotion/MyComp/Main.tsx b/packages/template-vercel/src/remotion/MyComp/Main.tsxindex df866b81d6..10a7583072 100644--- a/packages/template-vercel/src/remotion/MyComp/Main.tsx+++ b/packages/template-vercel/src/remotion/MyComp/Main.tsx@@ -1,20 +1,20 @@-import { fontFamily, loadFont } from "@remotion/google-fonts/Inter";+import { fontFamily, loadFont } from '@remotion/google-fonts/Inter';import {AbsoluteFill,Sequence,spring,useCurrentFrame,useVideoConfig,-} from "remotion";-import { z } from "zod";-import { CompositionProps } from "../../../types/constants";-import { NextLogo } from "./NextLogo";-import { Rings } from "./Rings";-import { TextFade } from "./TextFade";+} from 'remotion';+import { z } from 'zod';+import { CompositionProps } from '../../../types/constants';+import { NextLogo } from './NextLogo';+import { Rings } from './Rings';+import { TextFade } from './TextFade';-loadFont("normal", {- subsets: ["latin"],- weights: ["400", "700"],+loadFont('normal', {+ subsets: ['latin'],+ weights: ['400', '700'],});export const Main = ({ title }: z.infer<typeof CompositionProps>) => {const frame = useCurrentFrame();diff --git a/packages/template-vercel/src/remotion/MyComp/NextLogo.tsx b/packages/template-vercel/src/remotion/MyComp/NextLogo.tsxindex b7f87f6bf2..f5aacd6d5e 100644--- a/packages/template-vercel/src/remotion/MyComp/NextLogo.tsx+++ b/packages/template-vercel/src/remotion/MyComp/NextLogo.tsx@@ -1,9 +1,9 @@-import { evolvePath } from "@remotion/paths";-import React, { useMemo } from "react";-import { interpolate, spring, useCurrentFrame, useVideoConfig } from "remotion";+import { evolvePath } from '@remotion/paths';+import React, { useMemo } from 'react';+import { interpolate, spring, useCurrentFrame, useVideoConfig } from 'remotion';const nStroke =- "M149.508 157.52L69.142 54H54V125.97H66.1136V69.3836L139.999 164.845C143.333 162.614 146.509 160.165 149.508 157.52Z";+ 'M149.508 157.52L69.142 54H54V125.97H66.1136V69.3836L139.999 164.845C143.333 162.614 146.509 160.165 149.508 157.52Z';export const NextLogo: React.FC<{outProgress: number;diff --git a/packages/template-vercel/src/remotion/MyComp/Rings.tsx b/packages/template-vercel/src/remotion/MyComp/Rings.tsxindex 8e27bae856..d4aa3ce012 100644--- a/packages/template-vercel/src/remotion/MyComp/Rings.tsx+++ b/packages/template-vercel/src/remotion/MyComp/Rings.tsx@@ -1,5 +1,5 @@-import React from "react";-import { AbsoluteFill, interpolateColors, useVideoConfig } from "remotion";+import React from 'react';+import { AbsoluteFill, interpolateColors, useVideoConfig } from 'remotion';const RadialGradient: React.FC<{radius: number;@@ -11,8 +11,8 @@ const RadialGradient: React.FC<{return (<AbsoluteFillstyle={{- justifyContent: "center",- alignItems: "center",+ justifyContent: 'center',+ alignItems: 'center',}}><div@@ -46,7 +46,7 @@ export const Rings: React.FC<{<RadialGradientkey={i}radius={height * 0.3 * i}- color={interpolateColors(i, [0, 4], ["#fff", "#fff"])}+ color={interpolateColors(i, [0, 4], ['#fff', '#fff'])}/>);})diff --git a/packages/template-vercel/src/remotion/MyComp/TextFade.tsx b/packages/template-vercel/src/remotion/MyComp/TextFade.tsxindex 1b71930a0b..09ddcd20be 100644--- a/packages/template-vercel/src/remotion/MyComp/TextFade.tsx+++ b/packages/template-vercel/src/remotion/MyComp/TextFade.tsx@@ -1,11 +1,11 @@-import React, { useMemo } from "react";+import React, { useMemo } from 'react';import {AbsoluteFill,interpolate,spring,useCurrentFrame,useVideoConfig,-} from "remotion";+} from 'remotion';export const TextFade: React.FC<{children: React.ReactNode;diff --git a/packages/template-vercel/src/remotion/Root.tsx b/packages/template-vercel/src/remotion/Root.tsxindex 35901f2f06..284b680e91 100644--- a/packages/template-vercel/src/remotion/Root.tsx+++ b/packages/template-vercel/src/remotion/Root.tsx@@ -1,4 +1,4 @@-import { Composition } from "remotion";+import { Composition } from 'remotion';import {COMP_NAME,defaultMyCompProps,@@ -6,9 +6,9 @@ import {VIDEO_FPS,VIDEO_HEIGHT,VIDEO_WIDTH,-} from "../../types/constants";-import { Main } from "./MyComp/Main";-import { NextLogo } from "./MyComp/NextLogo";+} from '../../types/constants';+import { Main } from './MyComp/Main';+import { NextLogo } from './MyComp/NextLogo';export const RemotionRoot: React.FC = () => {return (diff --git a/packages/template-vercel/src/remotion/index.ts b/packages/template-vercel/src/remotion/index.tsindex 2142852e8d..092fe6e97d 100644--- a/packages/template-vercel/src/remotion/index.ts+++ b/packages/template-vercel/src/remotion/index.ts@@ -1,5 +1,5 @@-import { registerRoot } from "remotion";-import "../../styles/global.css";-import { RemotionRoot } from "./Root";+import { registerRoot } from 'remotion';+import '../../styles/global.css';+import { RemotionRoot } from './Root';registerRoot(RemotionRoot);diff --git a/packages/template-vercel/types/constants.ts b/packages/template-vercel/types/constants.tsindex a0f8d14c3d..931f1d3295 100644--- a/packages/template-vercel/types/constants.ts+++ b/packages/template-vercel/types/constants.ts@@ -1,12 +1,12 @@-import { z } from "zod";-export const COMP_NAME = "MyComp";+import { z } from 'zod';+export const COMP_NAME = 'MyComp';export const CompositionProps = z.object({title: z.string(),});export const defaultMyCompProps: z.infer<typeof CompositionProps> = {- title: "Vercel and Remotion",+ title: 'Vercel and Remotion',};export const DURATION_IN_FRAMES = 200;diff --git a/packages/template-vercel/types/schema.ts b/packages/template-vercel/types/schema.tsindex 3a24a04455..8dfb89aec5 100644--- a/packages/template-vercel/types/schema.ts+++ b/packages/template-vercel/types/schema.ts@@ -18,6 +18,6 @@ export type RenderResponse =};export type SSEMessage =- | { type: 'phase'; phase: string; progress: number }+ | { type: 'phase'; phase: string; progress: number; subtitle?: string }| { type: 'done'; url: string; size: number }| { type: 'error'; message: string };