🎥 Make videos programmatically with React
`@remotion/studio`: Show component location in composition inspector (#8927)
Jonny Burger2fa4423cc134
diff --git a/.agents/skills/studio-css-reset/SKILL.md b/.agents/skills/studio-css-reset/SKILL.mdnew file mode 100644index 0000000000..a18d6db74a--- /dev/null+++ b/.agents/skills/studio-css-reset/SKILL.md@@ -0,0 +1,22 @@+---+name: studio-css-reset+description: Guidance for Remotion Studio UI changes where the global CSS reset affects nested elements. Use when editing packages/studio UI, especially when adding wrapper spans, inline icons, labels, buttons, compact rows, or any nested text whose typography, color, sizing, or truncation must stay stable.+---++# Studio CSS Reset++Remotion Studio applies a broad CSS reset to UI elements. Treat every new nested element as reset-styled unless the local component gives it explicit visual styles.++When changing Studio UI:++- Do not rely on a parent button or container for visible child text styles. Give wrapper spans or divs explicit `fontFamily`, `fontSize`, `lineHeight`, and either `color` or `color: 'inherit'`.+- Preserve compact-row layout when introducing icon-plus-label markup. Use fixed icon dimensions, `flexShrink: 0`, and explicit label truncation styles such as `minWidth`, `overflow`, `textOverflow`, and `whiteSpace`.+- Recheck hover and non-hover states after adding wrappers. The label should not grow, change row height, lose ellipsis, or change color unexpectedly.+- Prefer fixing the shared Studio component once when the reset issue appears in a repeated row pattern.++For Studio code changes, run at least the focused Studio checks:++```bash+bunx turbo run make --filter='@remotion/studio'+bunx turbo run lint test --filter='@remotion/studio'+```diff --git a/.agents/skills/studio-css-reset/agents/openai.yaml b/.agents/skills/studio-css-reset/agents/openai.yamlnew file mode 100644index 0000000000..0d1c009ff4--- /dev/null+++ b/.agents/skills/studio-css-reset/agents/openai.yaml@@ -0,0 +1,4 @@+interface:+ display_name: "Studio CSS Reset"+ short_description: "Guard Studio UI against reset-styled children"+ default_prompt: "Use $studio-css-reset when changing Remotion Studio UI that nests labels or icons."diff --git a/.agents/skills/studio/SKILL.md b/.agents/skills/studio/SKILL.mdindex 7d1018198b..6ab3abeb87 100644--- a/.agents/skills/studio/SKILL.md+++ b/.agents/skills/studio/SKILL.md@@ -20,12 +20,13 @@ bun i && bun run build2. Start Studio from the example package:```bash-cd packages/example && bunx remotion studio+cd packages/example && bunx remotion studio --no-open```-Use `bunx`, not `npx`.+Use `bunx`, not `npx`. Always pass `--no-open`; Codex should open the printed URL explicitly instead of letting the CLI open a browser.-3. Keep the server process running and read its output for the local URL. The expected default is `http://localhost:3000`, but follow the printed URL if Remotion chooses another port.-4. If the output says the server is already running on port 3000, confirm it with `curl http://localhost:3000` and open that URL if it responds.-5. Open the URL in the Codex in-app browser. If no browser tool is available yet, use `tool_search` for the in-app browser control tool, then navigate to the local URL.-6. Tell the user the Studio URL and whether this is a newly started or already running server.+3. Do not check `localhost:3000` before starting Studio. Another worktree may already be using that port, and probing it first can open the wrong Studio.+4. Keep the server process running and read its output for the local URL. The expected default is `http://localhost:3000`, but the CLI output is the source of truth.+5. If the CLI says Studio is already running, use the exact URL printed by that CLI invocation. Only verify with `curl` after the CLI has identified the URL for this worktree.+6. Open the exact CLI URL in the Codex in-app browser yourself. If no browser tool is available yet, use `tool_search` for the in-app browser control tool, then navigate to the local URL.+7. Tell the user the Studio URL and whether this is a newly started or already running server.diff --git a/packages/core/src/Still.tsx b/packages/core/src/Still.tsxindex 51d855c461..8d08480365 100644--- a/packages/core/src/Still.tsx+++ b/packages/core/src/Still.tsx@@ -2,6 +2,7 @@ import React from 'react';import type {AnyZodObject} from './any-zod-type.js';import type {CompositionProps, StillProps} from './Composition.js';import {Composition} from './Composition.js';+import {addSequenceStackTraces} from './enable-sequence-stack-traces.js';/** @description A `<Still />` is a `<Composition />` that is only 1 frame long.@@ -22,3 +23,5 @@ export const Still = <// @ts-expect-error TypeScript does not understand it, but should still fail on type mismatchreturn React.createElement(Composition<Schema, Props>, newProps);};++addSequenceStackTraces(Still);diff --git a/packages/core/src/test/still-stack.test.tsx b/packages/core/src/test/still-stack.test.tsxnew file mode 100644index 0000000000..99bbb8e89a--- /dev/null+++ b/packages/core/src/test/still-stack.test.tsx@@ -0,0 +1,56 @@+import {afterEach, expect, test} from 'bun:test';+import {cleanup, render, waitFor} from '@testing-library/react';+import React from 'react';+import type {AnyComposition} from '../CompositionManager.js';+import {+ CompositionSetters,+ type CompositionManagerSetters,+} from '../CompositionManagerContext.js';+import {Internals} from '../internals.js';+import {Still} from '../Still.js';++afterEach(cleanup);++const AnyComp: React.FC = () => null;++const makeCompositionSetters = (+ onRegisterComposition: (composition: AnyComposition) => void,+): CompositionManagerSetters => ({+ registerComposition: (composition) => {+ onRegisterComposition(composition as AnyComposition);+ },+ unregisterComposition: () => undefined,+ registerFolder: () => undefined,+ unregisterFolder: () => undefined,+ setCanvasContent: () => undefined,+ onlyRenderComposition: null,+});++test('Still gets automatic stack traces added', () => {+ expect(Internals.getComponentsToAddStacksTo()).toContain(Still);+});++test('Still forwards its stack to the registered composition', async () => {+ const stillStack = 'Error\n at StillCallsite (Root.tsx:10:2)';+ const registeredCompositions: AnyComposition[] = [];++ render(+ <CompositionSetters.Provider+ value={makeCompositionSetters((composition) => {+ registeredCompositions.push(composition);+ })}+ >+ <Still+ id="still-stack-test"+ component={AnyComp}+ width={100}+ height={100}+ {...({stack: stillStack} as {readonly stack: string})}+ />+ </CompositionSetters.Provider>,+ );++ await waitFor(() => {+ expect(registeredCompositions[0]?.stack).toBe(stillStack);+ });+});diff --git a/packages/studio/src/components/CurrentComposition.tsx b/packages/studio/src/components/CurrentComposition.tsxindex 8b37b5ee4c..575cd19176 100644--- a/packages/studio/src/components/CurrentComposition.tsx+++ b/packages/studio/src/components/CurrentComposition.tsx@@ -1,8 +1,21 @@-import {useCallback, useContext, useMemo} from 'react';+import {+ type CSSProperties,+ useCallback,+ useContext,+ useEffect,+ useMemo,+} from 'react';import {Internals} from 'remotion';import type {OriginalPosition} from '../error-overlay/react-overlay/utils/get-source-map';import {isCompositionStill} from '../helpers/is-composition-still';-import {openOriginalPositionInEditor} from '../helpers/open-in-editor';+import {+ openOriginalPositionInEditor,+ preloadCompositionComponentInfo,+ useCachedCompositionComponentInfo,+} from '../helpers/open-in-editor';+import {ReactIcon} from '../icons/react';+import {StillIcon} from '../icons/still';+import {FilmIcon} from '../icons/video';import {renderFrame} from '../state/render-frame';import {InlineCompositionName} from './InlineCompositionName';import {@@ -16,6 +29,16 @@ import {useResolvedStack} from './Timeline/use-resolved-stack';export const CURRENT_COMPOSITION_HEIGHT = INSPECTOR_INFO_HEADER_MIN_HEIGHT;+const sourceLocationIconStyle: CSSProperties = {+ flexShrink: 0,+ height: 13,+ width: 13,+};++const renderReactIcon = (color: string) => {+ return <ReactIcon color={color} style={sourceLocationIconStyle} />;+};+export const CurrentComposition = () => {const video = Internals.useVideo();const {compositions} = useContext(Internals.CompositionManager);@@ -46,6 +69,26 @@ export const CurrentComposition = () => {source: resolvedCompositionLocation.source,};}, [resolvedCompositionLocation]);+ const compositionFile = validatedLocation?.source ?? null;+ const compositionId = currentComposition?.id ?? null;+ const compositionComponentInfo = useCachedCompositionComponentInfo({+ compositionFile,+ compositionId,+ });+ const componentLocation: OriginalPosition | null =+ compositionComponentInfo?.location ?? null;++ useEffect(() => {+ if (compositionFile === null || compositionId === null) {+ return;+ }++ preloadCompositionComponentInfo({+ compositionFile,+ compositionId,+ });+ }, [compositionFile, compositionId]);+const openFileLocation = useCallback(() => {if (!validatedLocation) {return;@@ -55,6 +98,29 @@ export const CurrentComposition = () => {showNotification((err as Error).message, 2000);});}, [validatedLocation]);+ const openComponentLocation = useCallback(() => {+ if (!componentLocation) {+ return;+ }++ openOriginalPositionInEditor(componentLocation).catch((err) => {+ showNotification((err as Error).message, 2000);+ });+ }, [componentLocation]);+ const renderCompositionIcon = useCallback(+ (color: string) => {+ if (!video) {+ return null;+ }++ return isCompositionStill(video) ? (+ <StillIcon color={color} style={sourceLocationIconStyle} />+ ) : (+ <FilmIcon color={color} style={sourceLocationIconStyle} />+ );+ },+ [video],+ );return (<InspectorInfoHeader>@@ -70,6 +136,13 @@ export const CurrentComposition = () => {location={validatedLocation}canOpen={validatedLocation !== null}onOpen={openFileLocation}+ renderIcon={renderCompositionIcon}+ />+ <InspectorSourceLocation+ location={componentLocation}+ canOpen={componentLocation !== null}+ onOpen={openComponentLocation}+ renderIcon={renderReactIcon}/><InspectorInfoSubtitle>{video.width}x{video.height}diff --git a/packages/studio/src/components/InspectorSourceLocation.tsx b/packages/studio/src/components/InspectorSourceLocation.tsxindex b959ca19ce..2f10719d36 100644--- a/packages/studio/src/components/InspectorSourceLocation.tsx+++ b/packages/studio/src/components/InspectorSourceLocation.tsx@@ -10,7 +10,9 @@ const sourceLocationStyle: React.CSSProperties = {backgroundColor: BACKGROUND,border: 'none',boxSizing: 'border-box',- display: 'block',+ display: 'flex',+ alignItems: 'center',+ gap: 4,fontFamily: 'sans-serif',fontSize: 12,height: 18,@@ -26,11 +28,24 @@ const sourceLocationStyle: React.CSSProperties = {width: 'fit-content',};+const sourceLocationLabelStyle: React.CSSProperties = {+ color: 'inherit',+ display: 'block',+ fontFamily: 'sans-serif',+ fontSize: 12,+ lineHeight: '18px',+ minWidth: 0,+ overflow: 'hidden',+ textOverflow: 'ellipsis',+ whiteSpace: 'nowrap',+};+export const InspectorSourceLocation: React.FC<{readonly location: OriginalPosition | null;readonly canOpen: boolean;readonly onOpen: () => void;-}> = ({location, canOpen, onOpen}) => {+ readonly renderIcon?: (color: string) => React.ReactNode;+}> = ({location, canOpen, onOpen, renderIcon}) => {const [hovered, setHovered] = useState(false);const validLocation = useMemo((): OriginalPosition | null => {@@ -67,6 +82,7 @@ export const InspectorSourceLocation: React.FC<{cursor: canOpen ? 'pointer' : 'default',};}, [canOpen, hovered]);+ const color = hovered ? LIGHT_COLOR : LIGHT_TEXT;const onClick = useCallback(() => {if (!canOpen) {@@ -89,7 +105,8 @@ export const InspectorSourceLocation: React.FC<{onPointerEnter={() => setHovered(true)}onPointerLeave={() => setHovered(false)}>- {label}+ {renderIcon ? renderIcon(color) : null}+ <span style={sourceLocationLabelStyle}>{label}</span></button>);};diff --git a/packages/studio/src/icons/react.tsx b/packages/studio/src/icons/react.tsxnew file mode 100644index 0000000000..9901af8d95--- /dev/null+++ b/packages/studio/src/icons/react.tsx@@ -0,0 +1,17 @@+import type {SVGProps} from 'react';+import React from 'react';++export const ReactIcon: React.FC<+ SVGProps<SVGSVGElement> & {+ readonly color: string;+ }+> = ({color, ...props}) => {+ return (+ <svg {...props} xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640">+ <path+ fill={color}+ d="M392.8 65.2C375.8 60.3 358.1 70.2 353.2 87.2L225.2 535.2C220.3 552.2 230.2 569.9 247.2 574.8C264.2 579.7 281.9 569.8 286.8 552.8L414.8 104.8C419.7 87.8 409.8 70.1 392.8 65.2zM457.4 201.3C444.9 213.8 444.9 234.1 457.4 246.6L530.8 320L457.4 393.4C444.9 405.9 444.9 426.2 457.4 438.7C469.9 451.2 490.2 451.2 502.7 438.7L598.7 342.7C611.2 330.2 611.2 309.9 598.7 297.4L502.7 201.4C490.2 188.9 469.9 188.9 457.4 201.4zM182.7 201.3C170.2 188.8 149.9 188.8 137.4 201.3L41.4 297.3C28.9 309.8 28.9 330.1 41.4 342.6L137.4 438.6C149.9 451.1 170.2 451.1 182.7 438.6C195.2 426.1 195.2 405.8 182.7 393.3L109.3 320L182.6 246.6C195.1 234.1 195.1 213.8 182.6 201.3z"+ />+ </svg>+ );+};