Skip to content

Production-ready animations, transitions, backgrounds, and scenes for Remotion

feat: refactor ui

dev_wandry42299a0e2ce8
diff --git a/app/(home)/stars/components/stars-tool.tsx b/app/(home)/stars/components/stars-tool.tsx
index 41c43db4..99d37c2a 100644
--- a/app/(home)/stars/components/stars-tool.tsx
+++ b/app/(home)/stars/components/stars-tool.tsx
@@ -246,15 +246,30 @@ export function StarsTool() {
try {
const { renderMediaOnWeb } = await import("@remotion/web-renderer");
- const { width, height } = dims(orientation);
+ const base = dims(orientation);
+ // Render the export cheaper than the 30fps preview: lower resolution + fps.
+ // The composition's motion is purely frame/durationInFrames ratios (no
+ // spring, never reads fps), so a 24fps/240-frame render is real-time
+ // identical to 30fps/300 — only the encode + per-frame cost drops (≈2-3×
+ // faster). Raise EXPORT_SCALE/EXPORT_FPS to trade speed for fidelity.
+ const EXPORT_SCALE = 0.7;
+ const EXPORT_FPS = 24;
+ const even = (n: number) =>
+ Math.max(2, Math.round((n * EXPORT_SCALE) / 2) * 2);
+ const durationInFrames = Math.max(
+ 1,
+ Math.round(
+ (entry.config.durationInFrames / entry.config.fps) * EXPORT_FPS,
+ ),
+ );
const { getBlob } = await renderMediaOnWeb({
composition: {
id: "github-stars",
component: entry.Component,
- durationInFrames: entry.config.durationInFrames,
- fps: entry.config.fps,
- width,
- height,
+ durationInFrames,
+ fps: EXPORT_FPS,
+ width: even(base.width),
+ height: even(base.height),
},
inputProps,
container: "mp4",
@@ -273,7 +288,11 @@ export function StarsTool() {
URL.revokeObjectURL(url);
} catch (err) {
if (!(err instanceof DOMException && err.name === "AbortError")) {
- toast.error("Export failed — try again");
+ // Surface the real cause (e.g. a Remotion version mismatch) instead of
+ // swallowing it — the toast stays friendly, the console is diagnosable.
+ console.error("[stars] MP4 export failed:", err);
+ const detail = err instanceof Error ? err.message : String(err);
+ toast.error("Export failed", { description: detail });
}
} finally {
setExporting(false);
@@ -561,23 +580,14 @@ function ReadyView({
animate={{ y: 0, opacity: 1 }}
transition={{ ...SPRING_BOUNCE, delay: 0.05 }}
>
- {/* Repo header + reset to a different repo. */}
- <div className="mb-3 flex items-center justify-between gap-3">
- <p className="min-w-0 truncate text-sm font-medium text-foreground">
+ {/* Repo title — centered heading. */}
+ <div className="mb-4 text-center">
+ <h2 className="truncate text-xl font-semibold tracking-tight text-foreground sm:text-2xl">
{repo}
- <span className="ml-2 font-normal text-muted-foreground">
- {formatStars(totalStars)} stars
- </span>
+ </h2>
+ <p className="mt-0.5 text-sm text-muted-foreground">
+ {formatStars(totalStars)} stars
</p>
- <Button
- variant="ghost"
- size="sm"
- onClick={onReset}
- className="shrink-0 gap-2 rounded-full"
- >
- <RotateCcw className="size-4" aria-hidden="true" />
- Change repository
- </Button>
</div>
{/* Controls bar */}
@@ -694,7 +704,17 @@ function ReadyView({
</Button>
</div>
- {exporting ? (
+ <div className="flex items-center justify-end gap-2">
+ <Button
+ variant="ghost"
+ size="lg"
+ onClick={onReset}
+ className="gap-2 rounded-full"
+ >
+ <RotateCcw className="size-4" aria-hidden="true" />
+ Change repository
+ </Button>
+ {exporting ? (
<div className="flex w-full items-center gap-3 sm:w-72">
<Progress
value={Math.round(exportProgress * 100)}
@@ -735,7 +755,8 @@ function ReadyView({
/>
<TooltipContent>MP4 export needs Chrome or Edge</TooltipContent>
</Tooltip>
- )}
+ )}
+ </div>
</div>
</motion.div>
);
diff --git a/bun.lock b/bun.lock
index bc33f9f9..c4f929bc 100644
--- a/bun.lock
+++ b/bun.lock
@@ -9,8 +9,8 @@
"@openpanel/nextjs": "^1.0.13",
"@react-three/fiber": "^9.3.0",
"@react-three/postprocessing": "^3.0.4",
- "@remotion/player": "^4.0.392",
- "@remotion/web-renderer": "^4.0.473",
+ "@remotion/player": "4.0.473",
+ "@remotion/web-renderer": "4.0.473",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"cmdk": "^1.1.1",
@@ -33,7 +33,7 @@
"react-dom": "19.2.4",
"react-resizable-panels": "^4.9.0",
"recharts": "3.8.0",
- "remotion": "^4.0.392",
+ "remotion": "4.0.473",
"shadcn": "^4.1.2",
"sonner": "^2.0.7",
"tailwind-merge": "^3.5.0",
@@ -418,7 +418,7 @@
"@remotion/licensing": ["@remotion/[email protected]", "", {}, "sha512-BBw6SuEWuUD/lYXbLKEC0TTUzW7aLsO0X72pG38W1dOUyfU2KZYYfWGZkd+ermZTWWJ8cW+mevIwloUGk7FRaQ=="],
- "@remotion/player": ["@remotion/[email protected]", "", { "dependencies": { "remotion": "4.0.446" }, "peerDependencies": { "react": ">=16.8.0", "react-dom": ">=16.8.0" } }, "sha512-l3sYiMmT0yx39qgGsWKkv/auTQ7BJYmEb+FPzwacBe5Oi1R1klBWABsbO+L4OSN6lDOCrI2U8uWfpsPZv1sqxA=="],
+ "@remotion/player": ["@remotion/[email protected]", "", { "dependencies": { "remotion": "4.0.473" }, "peerDependencies": { "react": ">=16.8.0", "react-dom": ">=16.8.0" } }, "sha512-giJ8cIQEdVxftpcX4m+9jWYCbIvpcdKRGVUc3ownxYEsJ30WUSP2+TuQ6aqqLXFAfwhY/SdBVLfopylh3BgMXA=="],
"@remotion/web-renderer": ["@remotion/[email protected]", "", { "dependencies": { "@mediabunny/aac-encoder": "1.45.0", "@mediabunny/flac-encoder": "1.45.0", "@mediabunny/mp3-encoder": "1.45.0", "@remotion/licensing": "4.0.473", "mediabunny": "1.45.0", "remotion": "4.0.473" }, "peerDependencies": { "react": ">=18.0.0", "react-dom": ">=18.0.0" } }, "sha512-WTyFdBdqsmmqrMpW1k6Uhcze2z8tZvKc15BYu1FwmDgdQ1QeaAMgEsyp5qRLzKZ/000XafK4q8bUjdEQoudc8A=="],
@@ -1354,7 +1354,7 @@
"remark-stringify": ["[email protected]", "", { "dependencies": { "@types/mdast": "^4.0.0", "mdast-util-to-markdown": "^2.0.0", "unified": "^11.0.0" } }, "sha512-1OSmLd3awB/t8qdoEOMazZkNsfVTeY4fTsgzcQFdXNq8ToTN4ZGwrMnlda4K6smTFKD+GRV6O48i6Z4iKgPPpw=="],
- "remotion": ["[email protected]", "", { "peerDependencies": { "react": ">=16.8.0", "react-dom": ">=16.8.0" } }, "sha512-NkE0d1APetJywF6MJJXE1dlMDXKhQWtlJV3HUfVBd7QUKPmoA3nhFBJaIsCyl/Rve2bmnq8h+yBjAU/skXezcA=="],
+ "remotion": ["[email protected]", "", { "peerDependencies": { "react": ">=16.8.0", "react-dom": ">=16.8.0" } }, "sha512-Li2u4cVxlbxWgxQPn5oBpUlmNKYFpLUmpE9OHMP7QurvOMfvVK1tcC7utxVEwYFZf18tXwqIPBwmuFvdzMu+YA=="],
"require-directory": ["[email protected]", "", {}, "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q=="],
@@ -1598,8 +1598,6 @@
"@reduxjs/toolkit/immer": ["[email protected]", "", {}, "sha512-XREFCPo6ksxVzP4E0ekD5aMdf8WMwmdNaz6vuvxgI40UaEiu6q3p8X52aU6GdyvLY3XXX/8R7JOTXStz/nBbRw=="],
- "@remotion/web-renderer/remotion": ["[email protected]", "", { "peerDependencies": { "react": ">=16.8.0", "react-dom": ">=16.8.0" } }, "sha512-Li2u4cVxlbxWgxQPn5oBpUlmNKYFpLUmpE9OHMP7QurvOMfvVK1tcC7utxVEwYFZf18tXwqIPBwmuFvdzMu+YA=="],
-
"@tailwindcss/oxide-wasm32-wasi/@emnapi/core": ["@emnapi/[email protected]", "", { "dependencies": { "@emnapi/wasi-threads": "1.2.1", "tslib": "^2.4.0" }, "bundled": true }, "sha512-UC+ZhH3XtczQYfOlu3lNEkdW/p4dsJ1r/bP7H8+rhao3TTTMO1ATq/4DdIi23XuGoFY+Cz0JmCbdVl0hz9jZcA=="],
"@tailwindcss/oxide-wasm32-wasi/@emnapi/runtime": ["@emnapi/[email protected]", "", { "dependencies": { "tslib": "^2.4.0" }, "bundled": true }, "sha512-3U4+MIWHImeyu1wnmVygh5WlgfYDtyf0k8AbLhMFxOipihf6nrWC4syIm/SwEeec0mNSafiiNnMJwbza/Is6Lw=="],
diff --git a/lib/__tests__/github-stargazers.test.ts b/lib/__tests__/github-stargazers.test.ts
index 7460ef5a..7ba1d32c 100644
--- a/lib/__tests__/github-stargazers.test.ts
+++ b/lib/__tests__/github-stargazers.test.ts
@@ -238,14 +238,14 @@ describe("fetchStargazers", () => {
);
});
- it("sets truncated=true when the repo has more pages than MAX_PAGES (50)", async () => {
+ it("sets truncated=true when the repo exceeds GitHub's ~400-page listing ceiling", async () => {
const repoBody = { stargazers_count: 99999 };
- // First page link header signals 100 total pages (> MAX_PAGES=50)
+ // First page link header signals 500 total pages (> the 400-page ceiling).
const linkHeader =
- '<https://api.github.com/repos/test/repo/stargazers?page=100>; rel="last"';
+ '<https://api.github.com/repos/test/repo/stargazers?page=500>; rel="last"';
const starBody = [rawEntry("alice", "2021-01-01T00:00:00Z")];
- // Repo fetch + page 1 + pages 2-50 (all return same one-entry body)
+ // Repo fetch + each sampled stargazer page returns the same one-entry body.
global.fetch = vi.fn().mockImplementation((url: string) => {
if (String(url).includes("/repos/test/repo") && !String(url).includes("stargazers")) {
return Promise.resolve(mockResponse(repoBody));
@@ -259,7 +259,7 @@ describe("fetchStargazers", () => {
expect(result.truncated).toBe(true);
});
- it("sets truncated=false when the repo fits within MAX_PAGES", async () => {
+ it("sets truncated=false when the repo is within the listing ceiling", async () => {
const repoBody = { stargazers_count: 3 };
const linkHeader = null; // only one page
const starBody = [rawEntry("alice", "2021-01-01T00:00:00Z")];
diff --git a/lib/github-stargazers.ts b/lib/github-stargazers.ts
index 703b7444..870d4244 100644
--- a/lib/github-stargazers.ts
+++ b/lib/github-stargazers.ts
@@ -16,7 +16,7 @@ export type Stargazer = {
export type StargazersResult = {
stargazers: Stargazer[];
totalStars: number;
- /** True when the repo has more pages than `MAX_PAGES` allows us to fetch. */
+ /** True when the repo exceeds GitHub's ~400-page (~40k-star) listing ceiling. */
truncated: boolean;
};
@@ -39,11 +39,14 @@ export class StargazersError extends Error {
}
/**
- * GitHub caps the REST stargazers endpoint at ~400 pages; we cap far lower so a
- * runaway repo can't exhaust the serverless function budget. 50 × 100 = 5000
- * stargazers fetched, then `truncated: true`. The animation downsamples anyway.
+ * We only need ~60 keyframes spread across the repo's whole star history, so we
+ * fetch a small, evenly-spaced SAMPLE of pages instead of every page — a handful
+ * of requests regardless of repo size (this used to page through up to 5000
+ * stargazers). GitHub won't list stargazers past ~page 400 (~40k stars); beyond
+ * that the newest are unreachable → `truncated: true`.
*/
-const MAX_PAGES = 50;
+const SAMPLE_PAGES = 12;
+const GITHUB_MAX_LISTABLE_PAGES = 400;
const PER_PAGE = 100;
const CONCURRENCY = 6;
/** Keyframe cap kept in lockstep with the component's `downsampleStargazers`. */
@@ -126,6 +129,22 @@ function downsample(stargazers: Stargazer[], max = KEYFRAME_CAP): Stargazer[] {
return out;
}
+/**
+ * Evenly spaced page numbers across `[1..last]`, inclusive of the first (oldest
+ * stargazers) and last (newest) page, de-duplicated. For small repos
+ * (`last <= count`) this is simply every page.
+ */
+function samplePageNumbers(last: number, count: number): number[] {
+ if (last <= count) {
+ return Array.from({ length: last }, (_, i) => i + 1);
+ }
+ const pages = new Set<number>();
+ for (let i = 0; i < count; i++) {
+ pages.add(1 + Math.round((i * (last - 1)) / (count - 1)));
+ }
+ return [...pages].sort((a, b) => a - b);
+}
+
/** Run `fn` over `items` with a bounded number of in-flight requests. */
async function mapWithConcurrency<T, R>(
items: T[],
@@ -181,8 +200,10 @@ async function fetchStargazerPage(
* - Uses `Accept: application/vnd.github.star+json` (required for `starred_at`).
* - Sends `Authorization: Bearer ${GITHUB_TOKEN}` only when the env var is set;
* works unauthenticated (60/hr) too.
- * - Reads the total page count from the first response's Link header and fetches
- * the rest in parallel (bounded), capped at `MAX_PAGES` → `truncated: true`.
+ * - Reads the page count from the first response's Link header, then fetches a
+ * small evenly-spaced SAMPLE of pages (including the newest) in parallel — fast
+ * regardless of repo size. `truncated: true` only when GitHub can't list past
+ * its ~40k-star ceiling.
* - Throws {@link StargazersError} for not-found / rate-limited / fetch failures.
*/
export async function fetchStargazers({
@@ -225,17 +246,24 @@ export async function fetchStargazers({
// 3. First page drives the page count via its Link header.
const first = await fetchStargazerPage(owner, repo, 1, signal);
const lastPage = parseLastPage(first.link) ?? 1;
- const cappedLastPage = Math.min(lastPage, MAX_PAGES);
- const truncated = lastPage > MAX_PAGES;
+ const listableLast = Math.min(lastPage, GITHUB_MAX_LISTABLE_PAGES);
+ // "truncated" only when GitHub itself can't list the newest stargazers (repos
+ // beyond its ~40k-star ceiling); a normal sample still spans first → last.
+ const truncated = lastPage > GITHUB_MAX_LISTABLE_PAGES;
const rawEntries: RawStargazer[] = [...first.entries];
- // 4. Remaining pages in parallel (bounded concurrency).
- if (cappedLastPage > 1) {
- const pages: number[] = [];
- for (let p = 2; p <= cappedLastPage; p++) pages.push(p);
- const pageResults = await mapWithConcurrency(pages, CONCURRENCY, (page) =>
- fetchStargazerPage(owner, repo, page, signal),
+ // 4. Fetch a small, evenly-spaced SAMPLE of the remaining pages in parallel —
+ // enough to span the whole history (including the genuine newest page)
+ // without paging through thousands of stargazers we'd only downsample away.
+ const samplePages = samplePageNumbers(listableLast, SAMPLE_PAGES).filter(
+ (p) => p !== 1,
+ );
+ if (samplePages.length) {
+ const pageResults = await mapWithConcurrency(
+ samplePages,
+ CONCURRENCY,
+ (page) => fetchStargazerPage(owner, repo, page, signal),
);
for (const result of pageResults) rawEntries.push(...result.entries);
}
diff --git a/package.json b/package.json
index 9f99f308..239fd15a 100644
--- a/package.json
+++ b/package.json
@@ -16,8 +16,8 @@
"@openpanel/nextjs": "^1.0.13",
"@react-three/fiber": "^9.3.0",
"@react-three/postprocessing": "^3.0.4",
- "@remotion/player": "^4.0.392",
- "@remotion/web-renderer": "^4.0.473",
+ "@remotion/player": "4.0.473",
+ "@remotion/web-renderer": "4.0.473",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"cmdk": "^1.1.1",
@@ -40,7 +40,7 @@
"react-dom": "19.2.4",
"react-resizable-panels": "^4.9.0",
"recharts": "3.8.0",
- "remotion": "^4.0.392",
+ "remotion": "4.0.473",
"shadcn": "^4.1.2",
"sonner": "^2.0.7",
"tailwind-merge": "^3.5.0",