Skip to content

🎥 Make videos programmatically with React

Elements: Prerender library template for static hosting

Igor Samokhovets5da7802b9a74
diff --git a/bun.lock b/bun.lock
index bc33120a1e..e1c782d08d 100644
--- a/bun.lock
+++ b/bun.lock
@@ -2148,7 +2148,6 @@
"dependencies": {
"@heroicons/react": "2.2.0",
"@react-router/node": "8.3.0",
- "@react-router/serve": "8.3.0",
"@remotion/captions": "workspace:*",
"@remotion/cli": "workspace:*",
"@remotion/player": "workspace:*",
@@ -2168,6 +2167,7 @@
"@types/react-dom": "19.2.3",
"eslint": "10.12.0",
"prettier": "3.8.1",
+ "sirv-cli": "3.0.1",
"tailwindcss": "4.3.3",
"typescript": "5.9.3",
"vite": "8.3.4",
@@ -6223,6 +6223,8 @@
"consola": ["[email protected]", "", {}, "sha512-5IKcdX0nnYavi6G7TtOhwkYzyjfJlatbjMjuLSfE2kYT5pMDOilZ4OvMhi637CcDICTmz3wARPoyhqyX1Y+XvA=="],
+ "console-clear": ["[email protected]", "", {}, "sha512-pMD+MVR538ipqkG5JXeOEbKWS5um1H4LUUccUQG68qpeqBYbzYy79Gh55jkd2TtPdRfUaLWdv6LPP//5Zt0aPQ=="],
+
"content-disposition": ["[email protected]", "", { "dependencies": { "safe-buffer": "5.2.1" } }, "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ=="],
"content-type": ["[email protected]", "", {}, "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA=="],
@@ -7297,6 +7299,8 @@
"loadjs": ["[email protected]", "", {}, "sha512-vNX4ZZLJBeDEOBvdr2v/F+0aN5oMuPu7JTqrMwp+DtgK+AryOlpy6Xtm2/HpNr+azEa828oQjOtWsB6iDtSfSQ=="],
+ "local-access": ["[email protected]", "", {}, "sha512-XfegD5pyTAfb+GY6chk283Ox5z8WexG56OvM06RWLpAc/UHozO8X6xAxEkIitZOtsSMM1Yr3DkHgW5W+onLhCw=="],
+
"local-pkg": ["[email protected]", "", { "dependencies": { "mlly": "^1.7.4", "pkg-types": "^2.3.0", "quansync": "^0.2.11" } }, "sha512-++gUqRDEvcnN6Zhqrr+y/CkVEHhlrR96vZn3nZZPYzMcBUyBtTKzB9NadClFIsIVSsu+3i9tfk/erqy9kAmt7Q=="],
"locate-path": ["[email protected]", "", { "dependencies": { "p-locate": "5.0.0" } }, "sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw=="],
@@ -8377,6 +8381,8 @@
"semifies": ["[email protected]", "", {}, "sha512-xXR3KGeoxTNWPD4aBvL5NUpMTT7WMANr3EWnaS190QVkY52lqqcVRD7Q05UVbBhiWDGWMlJEUam9m7uFFGVScw=="],
+ "semiver": ["[email protected]", "", {}, "sha512-QNI2ChmuioGC1/xjyYwyZYADILWyW6AmS1UH6gDj/SFUUUS4MBAWs/7mxnkRPc/F4iHezDP+O8t0dO8WHiEOdg=="],
+
"semver": ["[email protected]", "", { "dependencies": { "lru-cache": "6.0.0" }, "bin": { "semver": "bin/semver.js" } }, "sha512-QBlUtyVk/5EeHbi7X0fw6liDZc7BBmEaSYn01fMU1OUYbf6GPsbTtd8WmnqbI20SeycoHSeiybkE/q1Q+qlThQ=="],
"semver-compare": ["[email protected]", "", {}, "sha512-YM3/ITh2MJ5MtzaM429anh+x2jiLVjqILF4m4oyQB18W7Ggea7BfqdH/wGMK7dDiMghv/6WG7znWMwUDzJiXow=="],
@@ -8437,6 +8443,8 @@
"sirv": ["[email protected]", "", { "dependencies": { "@polka/url": "^1.0.0-next.24", "mrmime": "^2.0.0", "totalist": "^3.0.0" } }, "sha512-2wcC/oGxHis/BoHkkPwldgiPSYcpZK3JU28WoMVv55yHJgcZ8rlXvuG9iZggz+sU1d4bRgIGASwyWqjxu3FM0g=="],
+ "sirv-cli": ["[email protected]", "", { "dependencies": { "console-clear": "^1.1.0", "get-port": "^5.1.1", "kleur": "^4.1.4", "local-access": "^1.0.1", "sade": "^1.6.0", "semiver": "^1.0.0", "sirv": "^3.0.0", "tinydate": "^1.0.0" }, "bin": { "sirv": "bin.js" } }, "sha512-ICXaF2u6IQhLZ0EXF6nqUF4YODfSQSt+mGykt4qqO5rY+oIiwdg7B8w2PVDBJlQulaS2a3J8666CUoDoAuCGvg=="],
+
"sisteransi": ["[email protected]", "", {}, "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg=="],
"sitemap": ["[email protected]", "", { "dependencies": { "@types/node": "17.0.17", "@types/sax": "1.2.3", "arg": "5.0.2", "sax": "1.2.4" }, "bin": { "sitemap": "dist/cli.js" } }, "sha512-mK3aFtjz4VdJN0igpIJrinf3EO8U8mxOPsTBzSsy06UtjZQJ3YY3o3Xa7zSc5nMqcMrRwlChHZ18Kxg0caiPBg=="],
@@ -8729,6 +8737,8 @@
"tinyclip": ["[email protected]", "", {}, "sha512-Ae3OVUqifDw0wBriIBS7yVaW44Dp6eSHQcyq4Igc7eN2TJH/2YsicswaW+J/OuMvhpDPOKEgpAZCjkb4hpoyeA=="],
+ "tinydate": ["[email protected]", "", {}, "sha512-7cR8rLy2QhYHpsBDBVYnnWXm8uRTr38RoZakFSW7Bs7PzfMPNZthuMLkwqZv7MTu8lhQ91cOFYS5a7iFj2oR3w=="],
+
"tinyexec": ["[email protected]", "", {}, "sha512-QKAl9m8gWWGHV8jZcPeym6j+XULi6tOf1mT83WYJ4Lk2ytW/uwAWkrP0uFsdoYMdueVJ0qs26wZ+23xeB4ibNQ=="],
"tinyglobby": ["[email protected]", "", { "dependencies": { "fdir": "^6.5.0", "picomatch": "^4.0.4" } }, "sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g=="],
@@ -12613,6 +12623,8 @@
"shiki-twoslash/shiki": ["[email protected]", "", { "dependencies": { "jsonc-parser": "3.2.0", "vscode-oniguruma": "1.7.0", "vscode-textmate": "5.2.0" } }, "sha512-VsY7QJVzU51j5o1+DguUd+6vmCmZ5v/6gYu4vyYAhzjuNQU6P/vmSy4uQaOhvje031qQMiW0d2BwgMH52vqMng=="],
+ "sirv-cli/kleur": ["[email protected]", "", {}, "sha512-o+NO+8WrRiQEE4/7nwRJhN1HWpVmJm511pBHUxPLtp0BUISzlBplORYSmTclCnJvQq2tKu/sgl3xVpkc7ZWuQQ=="],
+
"sitemap/@types/node": ["@types/[email protected]", "", {}, "sha512-e8PUNQy1HgJGV3iU/Bp2+D/DXh3PYeyli8LgIwsQcs1Ar1LoaWHSIT6Rw+H2rNJmiq6SNWiDytfx8+gYj7wDHw=="],
"sitemap/sax": ["[email protected]", "", {}, "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw=="],
diff --git a/packages/create-video/src/templates.ts b/packages/create-video/src/templates.ts
index 94e72f7a1c..8f9afe2511 100644
--- a/packages/create-video/src/templates.ts
+++ b/packages/create-video/src/templates.ts
@@ -285,7 +285,7 @@ export const FEATURED_TEMPLATES: Template[] = [
repoName: 'template-element-library',
description: 'Build and publish your own Remotion Element library',
longerDescription:
- 'A React Router and Tailwind CSS website with three editable Elements, a development Studio, and installation through the Studio Protocol. Deploy as a static site.',
+ 'A React Router and Tailwind CSS website with four editable Elements, including captions, an authoring Studio, and installation through the Studio Protocol.',
promoBanner: {
width: 1200,
height: 800,
diff --git a/packages/docs/src/remotion/AllTemplates.tsx b/packages/docs/src/remotion/AllTemplates.tsx
index 66d446d108..7920d1cfa5 100644
--- a/packages/docs/src/remotion/AllTemplates.tsx
+++ b/packages/docs/src/remotion/AllTemplates.tsx
@@ -73,7 +73,7 @@ export const AllTemplates: React.FC = () => {
style={{
height: 80,
width: 80,
- margin: 20,
+ margin: 10,
justifyContent: 'center',
alignItems: 'center',
display: 'flex',
diff --git a/packages/docs/static/generated/template-all.png b/packages/docs/static/generated/template-all.png
index 0bd8813670..13ee72b26b 100644
Binary files a/packages/docs/static/generated/template-all.png and b/packages/docs/static/generated/template-all.png differ
diff --git a/packages/template-element-library/README.md b/packages/template-element-library/README.md
index 15b1dc3710..0d3a90b6c2 100644
--- a/packages/template-element-library/README.md
+++ b/packages/template-element-library/README.md
@@ -1,6 +1,6 @@
# Remotion Element Library
-A React Router + Tailwind CSS starter for publishing [Remotion Elements](https://www.remotion.dev/elements). Includes server-side rendering, an authoring Studio, and four editable examples. See the [third-party Element libraries](https://www.remotion.dev/elements/libraries) for examples of published catalogs.
+A React Router + Tailwind CSS starter for publishing [Remotion Elements](https://www.remotion.dev/elements). Includes a prerendered static website, an authoring Studio, and four editable examples. See the [third-party Element libraries](https://www.remotion.dev/elements/libraries) for examples of published catalogs.
## Develop
@@ -41,10 +41,10 @@ Accent captions remixes [Word Highlight Captions](https://www.remotion.dev/eleme
```sh
npm run lint
npm run build
-npm start
+npm run preview
```
-Deploy with an SSR-capable host using the [React Router deployment guide](https://reactrouter.com/start/framework/deploying). Use HTTPS and allow embedding in Remotion Studio, as described in the library integration guide.
+Publish `build/client` to a static host. All Element pages are prerendered from the registry. See the [React Router prerendering guide](https://reactrouter.com/how-to/pre-rendering) for static hosting and fallback routing. Use HTTPS and allow embedding in Remotion Studio, as described in the library integration guide.
## License
diff --git a/packages/template-element-library/app/components/category-navigation.tsx b/packages/template-element-library/app/components/category-navigation.tsx
index a29b707b54..023e2b127b 100644
--- a/packages/template-element-library/app/components/category-navigation.tsx
+++ b/packages/template-element-library/app/components/category-navigation.tsx
@@ -1,4 +1,4 @@
-import { Link, useSearchParams } from "react-router";
+import { Link, useOutletContext } from "react-router";
import { elements } from "../../elements/registry";
export const CategoryNavigation = ({
@@ -6,7 +6,7 @@ export const CategoryNavigation = ({
}: {
category: string | null;
}) => {
- const [searchParams] = useSearchParams();
+ const { search } = useOutletContext<{ search: string }>();
const categories = [...new Set(elements.map((element) => element.category))];
return (
@@ -15,7 +15,7 @@ export const CategoryNavigation = ({
aria-label="Filter by category"
>
{[null, ...categories].map((item) => {
- const params = new URLSearchParams(searchParams);
+ const params = new URLSearchParams(search);
if (item === null || item === "Captions") {
params.delete("category");
} else {
diff --git a/packages/template-element-library/app/components/element-use-button.tsx b/packages/template-element-library/app/components/element-use-button.tsx
index d90a729579..5eb683f799 100644
--- a/packages/template-element-library/app/components/element-use-button.tsx
+++ b/packages/template-element-library/app/components/element-use-button.tsx
@@ -1,4 +1,4 @@
-import { ArrowPathIcon } from "@heroicons/react/16/solid";
+import { ArrowPathIcon, EllipsisVerticalIcon } from "@heroicons/react/16/solid";
import { setStudioDragData } from "@remotion/studio-protocol";
import type { DragEvent, RefObject } from "react";
import type { CatalogEntry } from "../../lib/element-payload";
@@ -50,11 +50,14 @@ export const ElementUseButton = ({
<div
aria-label="Drag into Studio"
title="Drag into Studio"
- className="flex min-h-12 w-12 shrink-0 cursor-grab items-center justify-center rounded-r-md border-l border-white/20 text-2xl/none select-none hover:bg-neutral-700 active:cursor-grabbing"
+ className="flex min-h-12 w-12 shrink-0 cursor-grab items-center justify-center rounded-r-md border-l border-white/20 select-none hover:bg-neutral-700 active:cursor-grabbing"
draggable
onDragStart={onDragStart}
>
- <span aria-hidden>â ¿</span>
+ <span aria-hidden className="grid w-3 grid-cols-2 place-items-center">
+ <EllipsisVerticalIcon className="size-4 shrink-0 fill-current" />
+ <EllipsisVerticalIcon className="size-4 shrink-0 fill-current" />
+ </span>
</div>
</div>
);
diff --git a/packages/template-element-library/app/root.tsx b/packages/template-element-library/app/root.tsx
index 1ed9429154..ddf900a369 100644
--- a/packages/template-element-library/app/root.tsx
+++ b/packages/template-element-library/app/root.tsx
@@ -34,6 +34,10 @@ export default function Root() {
return <Outlet />;
}
+export function HydrateFallback() {
+ return null;
+}
+
export function ErrorBoundary() {
const error = useRouteError();
const notFound = isRouteErrorResponse(error) && error.status === 404;
diff --git a/packages/template-element-library/app/routes/layout.tsx b/packages/template-element-library/app/routes/layout.tsx
index ccac5c6113..85d5b67914 100644
--- a/packages/template-element-library/app/routes/layout.tsx
+++ b/packages/template-element-library/app/routes/layout.tsx
@@ -5,14 +5,14 @@ import { StudioActions } from "../components/studio-actions";
export default function LibraryLayout() {
const location = useLocation();
- const search = location.search;
- const [insideStudio, setInsideStudio] = useState(
- new URLSearchParams(search).get("remotion-studio") === "true",
- );
+ const [hydrated, setHydrated] = useState(false);
+ const search = hydrated ? location.search : "";
+ const [insideStudio, setInsideStudio] = useState(false);
const isCaptionPicker =
insideStudio &&
new URLSearchParams(search).get("remotion-studio-context") === "captions";
useEffect(() => {
+ setHydrated(true);
setInsideStudio(isInsideStudio());
}, []);
@@ -42,7 +42,7 @@ export default function LibraryLayout() {
</Link>
</div>
{(location.pathname === "/" ||
- location.pathname === "/captions") && (
+ location.pathname.replace(/\/$/, "") === "/captions") && (
<div className="w-full min-w-0 sm:w-auto sm:max-w-80">
<StudioActions entry={null} variant="default" />
</div>
diff --git a/packages/template-element-library/app/routes/library.tsx b/packages/template-element-library/app/routes/library.tsx
index 287d197e7f..81a3e0ac26 100644
--- a/packages/template-element-library/app/routes/library.tsx
+++ b/packages/template-element-library/app/routes/library.tsx
@@ -1,4 +1,4 @@
-import { useSearchParams, type MetaFunction } from "react-router";
+import { useOutletContext, type MetaFunction } from "react-router";
import { CategoryNavigation } from "../components/category-navigation";
import { catalog } from "../../lib/element-payload";
import { ElementCard } from "../components/element-card";
@@ -13,7 +13,8 @@ export const meta: MetaFunction = () => [
];
export default function Library() {
- const [searchParams] = useSearchParams();
+ const { search } = useOutletContext<{ search: string }>();
+ const searchParams = new URLSearchParams(search);
const categories = [
...new Set(catalog.map(({ definition }) => definition.category)),
];
diff --git a/packages/template-element-library/eslint.config.mjs b/packages/template-element-library/eslint.config.mjs
index aba68bf040..64cf76a65f 100644
--- a/packages/template-element-library/eslint.config.mjs
+++ b/packages/template-element-library/eslint.config.mjs
@@ -2,5 +2,5 @@ import { makeConfig } from "@remotion/eslint-config-flat";
export default [
{ ignores: [".react-router/**", "build/**"] },
- ...makeConfig({ remotionDir: ["elements/**", "remotion/**"] }),
+ ...makeConfig({ remotionDir: "{elements,remotion}/**" }),
];
diff --git a/packages/template-element-library/package.json b/packages/template-element-library/package.json
index 71f0034940..6b6e355fee 100644
--- a/packages/template-element-library/package.json
+++ b/packages/template-element-library/package.json
@@ -8,7 +8,7 @@
"scripts": {
"dev": "react-router dev",
"build": "react-router build",
- "start": "react-router-serve build/server/index.js",
+ "preview": "sirv build/client --single __spa-fallback.html",
"typecheck": "react-router typegen && tsc",
"lint": "eslint . && react-router typegen && tsc",
"remotion:studio": "remotion studio"
@@ -19,7 +19,6 @@
"dependencies": {
"@heroicons/react": "2.2.0",
"@react-router/node": "8.3.0",
- "@react-router/serve": "8.3.0",
"@remotion/captions": "workspace:*",
"@remotion/cli": "workspace:*",
"@remotion/player": "workspace:*",
@@ -38,6 +37,7 @@
"@types/react-dom": "19.2.3",
"eslint": "10.12.0",
"prettier": "3.8.1",
+ "sirv-cli": "3.0.1",
"typescript": "5.9.3",
"vite": "8.3.4",
"tailwindcss": "4.3.3",
diff --git a/packages/template-element-library/react-router.config.ts b/packages/template-element-library/react-router.config.ts
index e45e2735ab..66a88402fc 100644
--- a/packages/template-element-library/react-router.config.ts
+++ b/packages/template-element-library/react-router.config.ts
@@ -1,5 +1,11 @@
import type { Config } from "@react-router/dev/config";
+import { elements } from "./elements/registry";
export default {
- ssr: true,
+ ssr: false,
+ prerender: [
+ "/",
+ "/captions",
+ ...elements.map(({ slug }) => `/elements/${slug}`),
+ ],
} satisfies Config;