Skip to content

🎥 Make videos programmatically with React

Add stack traces to Composition and improve studio menu bar

Jonny Burger6bb6cdbae134
diff --git a/packages/core/src/Composition.tsx b/packages/core/src/Composition.tsx
index 92c703e5f7..63ed3ea01a 100644
--- a/packages/core/src/Composition.tsx
+++ b/packages/core/src/Composition.tsx
@@ -136,7 +136,7 @@ const InnerComposition = <
defaultProps,
schema,
...compProps
-}: CompositionProps<Schema, Props>) => {
+}: CompositionProps<Schema, Props> & {stack?: string}) => {
const compManager = useContext(CompositionSetters);
const {registerComposition, unregisterComposition} = compManager;
@@ -200,6 +200,7 @@ const InnerComposition = <
parentFolderName: parentName,
schema: schema ?? null,
calculateMetadata: compProps.calculateMetadata ?? null,
+ stack: (compProps as {stack?: string}).stack ?? null,
} as TComposition<Schema, Props>);
return () => {
diff --git a/packages/core/src/CompositionManager.tsx b/packages/core/src/CompositionManager.tsx
index ccb95cd0b9..9babb97327 100644
--- a/packages/core/src/CompositionManager.tsx
+++ b/packages/core/src/CompositionManager.tsx
@@ -24,6 +24,7 @@ export type TComposition<
calculateMetadata: CalculateMetadataFunction<
InferProps<Schema, Props>
> | null;
+ stack: string | null;
} & PropsIfHasProps<Schema, Props>;
export type AnyComposition = TComposition<
diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts
index 947cdd8dda..5731755230 100644
--- a/packages/core/src/index.ts
+++ b/packages/core/src/index.ts
@@ -2,6 +2,7 @@ import './_check-rsc.js';
import './asset-types.js';
import {Clipper} from './Clipper.js';
import type {Codec} from './codec.js';
+import {Composition} from './Composition.js';
import type {
AnyCompMetadata,
AnyComposition,
@@ -258,6 +259,7 @@ export const Config = new Proxy(proxyObj, {
Sequence.displayName = 'Sequence';
addSequenceStackTraces(Sequence);
+addSequenceStackTraces(Composition);
export type _InternalTypes = {
AnyComposition: AnyComposition;
diff --git a/packages/core/src/test/wrap-sequence-context.tsx b/packages/core/src/test/wrap-sequence-context.tsx
index 2cecc9e9d1..23593d97c6 100644
--- a/packages/core/src/test/wrap-sequence-context.tsx
+++ b/packages/core/src/test/wrap-sequence-context.tsx
@@ -26,6 +26,7 @@ const mockCompositionContext: CompositionManagerContext = {
nonce: [[0, 0]],
calculateMetadata: null,
schema: null,
+ stack: null,
},
],
folders: [],
diff --git a/packages/player/src/SharedPlayerContext.tsx b/packages/player/src/SharedPlayerContext.tsx
index 8281e7cc41..c4b9e1f376 100644
--- a/packages/player/src/SharedPlayerContext.tsx
+++ b/packages/player/src/SharedPlayerContext.tsx
@@ -64,6 +64,7 @@ export const SharedPlayerContexts: React.FC<{
parentFolderName: null,
schema: null,
calculateMetadata: null,
+ stack: null,
},
],
folders: [],
diff --git a/packages/renderer/src/test/get-assets-for-markup.tsx b/packages/renderer/src/test/get-assets-for-markup.tsx
index d1d59c4f05..af922797b5 100644
--- a/packages/renderer/src/test/get-assets-for-markup.tsx
+++ b/packages/renderer/src/test/get-assets-for-markup.tsx
@@ -93,6 +93,7 @@ export const getAssetsForMarkup = async (
fps: config.fps,
height: config.height,
width: config.width,
+ stack: null,
},
],
canvasContent: {
diff --git a/packages/studio/src/components/MenuBuildIndicator.tsx b/packages/studio/src/components/MenuBuildIndicator.tsx
index d430ad8065..edbcfea9e2 100644
--- a/packages/studio/src/components/MenuBuildIndicator.tsx
+++ b/packages/studio/src/components/MenuBuildIndicator.tsx
@@ -1,7 +1,20 @@
-import React, {useContext, useEffect, useState} from 'react';
+import type {GitSource} from '@remotion/studio-shared';
+import React, {
+ useCallback,
+ useContext,
+ useEffect,
+ useMemo,
+ useState,
+} from 'react';
import {StudioServerConnectionCtx} from '../helpers/client-id';
+import {
+ getGitSourceBranchUrl,
+ getGitSourceName,
+} from '../helpers/get-git-menu-item';
+import {openInEditor} from '../helpers/open-in-editor';
import {Spacing} from './layout';
-import {OpenEditorButton} from './OpenEditorButton';
+import {MenuCompositionName} from './MenuCompositionName';
+import {showNotification} from './Notifications/NotificationCenter';
import {Spinner} from './Spinner';
const cwd: React.CSSProperties = {
@@ -26,11 +39,79 @@ const noSpinner: React.CSSProperties = {
width: spinnerSize,
};
+const projectNameLinkBase: React.CSSProperties = {
+ color: 'inherit',
+ textDecoration: 'none',
+ cursor: 'pointer',
+ fontSize: 'inherit',
+ textUnderlineOffset: 2,
+};
+
+const projectNameLink: React.CSSProperties = {
+ ...projectNameLinkBase,
+};
+
+const projectNameLinkHovered: React.CSSProperties = {
+ ...projectNameLinkBase,
+ textDecoration: 'underline',
+};
+
export const MenuBuildIndicator: React.FC = () => {
const [isBuilding, setIsBuilding] = useState(false);
+ const [projectNameHovered, setProjectNameHovered] = useState(false);
const ctx = useContext(StudioServerConnectionCtx).previewServerState;
- const showButton = window.remotion_editorName && ctx.type === 'connected';
+ const showEditorLink = window.remotion_editorName && ctx.type === 'connected';
+ const showGitLink = !showEditorLink && !!window.remotion_gitSource;
+
+ const handleProjectNameClick = useCallback(async () => {
+ if (showEditorLink) {
+ await openInEditor({
+ originalFileName: `${window.remotion_cwd}`,
+ originalLineNumber: 1,
+ originalColumnNumber: 1,
+ originalFunctionName: null,
+ originalScriptCode: null,
+ })
+ .then((res) => res.json())
+ .then(({success}) => {
+ if (!success) {
+ showNotification(
+ `Could not open ${window.remotion_editorName}`,
+ 2000,
+ );
+ }
+ })
+ .catch((err) => {
+ // eslint-disable-next-line no-console
+ console.error(err);
+ showNotification(
+ `Could not open ${window.remotion_editorName}`,
+ 2000,
+ );
+ });
+ } else if (showGitLink) {
+ window.open(
+ getGitSourceBranchUrl(window.remotion_gitSource as GitSource),
+ '_blank',
+ );
+ }
+ }, [showEditorLink, showGitLink]);
+
+ const projectNameTitle = useMemo(() => {
+ if (showEditorLink) {
+ return `Open in ${window.remotion_editorName}`;
+ }
+
+ if (showGitLink) {
+ return `Open ${getGitSourceName(window.remotion_gitSource as GitSource)} Repo`;
+ }
+
+ return undefined;
+ }, [showEditorLink, showGitLink]);
+
+ const isClickable = showEditorLink || showGitLink;
+
useEffect(() => {
window.remotion_isBuilding = () => {
setIsBuilding(true);
@@ -48,7 +129,7 @@ export const MenuBuildIndicator: React.FC = () => {
return (
<div style={cwd} title={window.remotion_cwd}>
- {showButton ? <Spacing x={2} /> : null}
+ {isClickable ? <Spacing x={2} /> : null}
{isBuilding ? (
<div style={spinner}>
<Spinner duration={0.5} size={spinnerSize} />
@@ -56,14 +137,21 @@ export const MenuBuildIndicator: React.FC = () => {
) : (
<div style={noSpinner} />
)}
- {showButton ? <Spacing x={0.5} /> : null}
- {window.remotion_projectName}
- {showButton ? <Spacing x={0.25} /> : null}
- {showButton ? (
- <OpenEditorButton type="editor" />
- ) : window.remotion_gitSource ? (
- <OpenEditorButton type="git" />
- ) : null}
+ {isClickable ? <Spacing x={0.5} /> : null}
+ {isClickable ? (
+ <a
+ style={projectNameHovered ? projectNameLinkHovered : projectNameLink}
+ title={projectNameTitle}
+ onClick={handleProjectNameClick}
+ onPointerEnter={() => setProjectNameHovered(true)}
+ onPointerLeave={() => setProjectNameHovered(false)}
+ >
+ {window.remotion_projectName}
+ </a>
+ ) : (
+ window.remotion_projectName
+ )}
+ <MenuCompositionName />
</div>
);
};
diff --git a/packages/studio/src/components/MenuCompositionName.tsx b/packages/studio/src/components/MenuCompositionName.tsx
new file mode 100644
index 0000000000..143e5b9e89
--- /dev/null
+++ b/packages/studio/src/components/MenuCompositionName.tsx
@@ -0,0 +1,105 @@
+import React, {useCallback, useContext, useMemo, useState} from 'react';
+import {Internals} from 'remotion';
+import {StudioServerConnectionCtx} from '../helpers/client-id';
+import {LIGHT_TEXT} from '../helpers/colors';
+import {openOriginalPositionInEditor} from '../helpers/open-in-editor';
+import {showNotification} from './Notifications/NotificationCenter';
+import {useResolvedStack} from './Timeline/use-resolved-stack';
+
+const baseStyle: React.CSSProperties = {
+ color: 'inherit',
+ textDecoration: 'none',
+ fontSize: 'inherit',
+ textUnderlineOffset: 2,
+};
+
+const compositionNameStyle: React.CSSProperties = {
+ ...baseStyle,
+ cursor: 'default',
+};
+
+const clickableStyle: React.CSSProperties = {
+ ...baseStyle,
+ cursor: 'pointer',
+};
+
+const clickableHoveredStyle: React.CSSProperties = {
+ ...clickableStyle,
+ textDecoration: 'underline',
+};
+
+const slashStyle: React.CSSProperties = {
+ color: LIGHT_TEXT,
+ marginInline: 4,
+ position: 'relative',
+ top: 1,
+};
+
+export const MenuCompositionName: React.FC = () => {
+ const {canvasContent, compositions} = useContext(
+ Internals.CompositionManager,
+ );
+ const connectionStatus = useContext(StudioServerConnectionCtx)
+ .previewServerState.type;
+ const [opening, setOpening] = useState(false);
+ const [hovered, setHovered] = useState(false);
+
+ const composition = useMemo(() => {
+ if (canvasContent === null || canvasContent.type !== 'composition') {
+ return null;
+ }
+
+ return (
+ compositions.find((c) => c.id === canvasContent.compositionId) ?? null
+ );
+ }, [canvasContent, compositions]);
+
+ const resolvedLocation = useResolvedStack(composition?.stack ?? null);
+
+ const canOpen =
+ resolvedLocation &&
+ window.remotion_editorName &&
+ connectionStatus === 'connected';
+
+ const handleClick = useCallback(async () => {
+ if (!canOpen || !resolvedLocation) {
+ return;
+ }
+
+ setOpening(true);
+ try {
+ await openOriginalPositionInEditor(resolvedLocation);
+ } catch (err) {
+ showNotification((err as Error).message, 2000);
+ } finally {
+ setOpening(false);
+ }
+ }, [canOpen, resolvedLocation]);
+
+ if (!composition) {
+ return null;
+ }
+
+ return (
+ <>
+ <span style={slashStyle}>/</span>
+ <a
+ style={
+ canOpen && !opening
+ ? hovered
+ ? clickableHoveredStyle
+ : clickableStyle
+ : compositionNameStyle
+ }
+ title={
+ canOpen ? `Open in ${window.remotion_editorName}` : composition.id
+ }
+ onClick={handleClick}
+ onPointerEnter={() => setHovered(true)}
+ onPointerLeave={() => setHovered(false)}
+ >
+ {composition.id}
+ </a>
+ </>
+ );
+};
diff --git a/packages/studio/src/components/OpenEditorButton.tsx b/packages/studio/src/components/OpenEditorButton.tsx
deleted file mode 100644
index f049bafdbb..0000000000
--- a/packages/studio/src/components/OpenEditorButton.tsx
+++ /dev/null
@@ -1,104 +0,0 @@
-import type {GitSource} from '@remotion/studio-shared';
-import {useCallback, useMemo, useState} from 'react';
-import {LIGHT_TEXT} from '../helpers/colors';
-import {
- getGitSourceBranchUrl,
- getGitSourceName,
-} from '../helpers/get-git-menu-item';
-import {openInEditor} from '../helpers/open-in-editor';
-import {showNotification} from './Notifications/NotificationCenter';
-
-const svgStyle: React.CSSProperties = {
- width: 11,
- height: 11,
-};
-
-const buttonStyle: React.CSSProperties = {
- border: 'none',
- height: '20px',
- display: 'flex',
- paddingInline: '6px',
- justifyContent: 'center',
- alignItems: 'center',
-};
-
-export const OpenEditorButton: React.FC<{
- type: 'git' | 'editor';
-}> = ({type}) => {
- const [hovered, setHovered] = useState<boolean>(false);
-
- const svgFillColor = useMemo(() => {
- return hovered ? 'white' : LIGHT_TEXT;
- }, [hovered]);
-
- const handleClick = useCallback(async () => {
- if (type === 'editor') {
- await openInEditor({
- originalFileName: `${window.remotion_cwd}`,
- originalLineNumber: 1,
- originalColumnNumber: 1,
- originalFunctionName: null,
- originalScriptCode: null,
- })
- .then((res) => res.json())
- .then(({success}) => {
- if (!success) {
- showNotification(
- `Could not open ${window.remotion_editorName}`,
- 2000,
- );
- }
- })
- .catch((err) => {
- // eslint-disable-next-line no-console
- console.error(err);
- showNotification(
- `Could not open ${window.remotion_editorName}`,
- 2000,
- );
- });
- }
-
- if (type === 'git') {
- if (!window.remotion_gitSource) {
- throw new Error('No git source');
- }
-
- window.open(getGitSourceBranchUrl(window.remotion_gitSource), '_blank');
- }
- }, [type]);
-
- const buttonTooltip =
- type === 'git'
- ? `Open ${getGitSourceName(window.remotion_gitSource as GitSource)} Repo`
- : `Open in ${window.remotion_editorName}`;
- const openInEditorSvg = (
- <svg viewBox="0 0 512 512" style={svgStyle}>
- <path
- fill={svgFillColor}
- d="M320 0c-17.7 0-32 14.3-32 32s14.3 32 32 32h82.7L201.4 265.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L448 109.3V192c0 17.7 14.3 32 32 32s32-14.3 32-32V32c0-17.7-14.3-32-32-32H320zM80 32C35.8 32 0 67.8 0 112V432c0 44.2 35.8 80 80 80H400c44.2 0 80-35.8 80-80V320c0-17.7-14.3-32-32-32s-32 14.3-32 32V432c0 8.8-7.2 16-16 16H80c-8.8 0-16-7.2-16-16V112c0-8.8 7.2-16 16-16H192c17.7 0 32-14.3 32-32s-14.3-32-32-32H80z"
- />
- </svg>
- );
-
- const onPointerEnter = useCallback(() => {
- setHovered(true);
- }, []);
-
- const onPointerLeave = useCallback(() => {
- setHovered(false);
- }, []);
-
- return (
- <button
- title={buttonTooltip}
- type="button"
- onPointerEnter={onPointerEnter}
- onPointerLeave={onPointerLeave}
- style={buttonStyle}
- onClick={handleClick}
- >
- {openInEditorSvg}
- </button>
- );
-};
diff --git a/packages/studio/src/components/Timeline/TimelineStack/index.tsx b/packages/studio/src/components/Timeline/TimelineStack/index.tsx
index 1322cee5c0..d5e162b7bd 100644
--- a/packages/studio/src/components/Timeline/TimelineStack/index.tsx
+++ b/packages/studio/src/components/Timeline/TimelineStack/index.tsx
@@ -199,7 +199,8 @@ export const TimelineStack: React.FC<{
color: opening && isCompact ? VERY_LIGHT_TEXT : LIGHT_COLOR,
userSelect: 'none',
WebkitUserSelect: 'none',
- borderBottom: hoverEffect ? '1px solid #fff' : 'none',
+ textDecoration: hoverEffect ? 'underline' : 'none',
+ textUnderlineOffset: 2,
cursor: hoverEffect ? 'pointer' : undefined,
};
}, [titleHoverable, isCompact, opening, titleHovered]);
diff --git a/packages/studio/src/test/folder-tree.test.ts b/packages/studio/src/test/folder-tree.test.ts
index 9dfedc0981..52b1b5bd48 100644
--- a/packages/studio/src/test/folder-tree.test.ts
+++ b/packages/studio/src/test/folder-tree.test.ts
@@ -37,6 +37,7 @@ test('Should create a good folder tree with 1 item inside and 1 item outside', a
parentFolderName: null,
calculateMetadata: null,
schema: obj,
+ stack: null,
},
{
component,
@@ -51,6 +52,7 @@ test('Should create a good folder tree with 1 item inside and 1 item outside', a
parentFolderName: null,
calculateMetadata: null,
schema: obj,
+ stack: null,
},
],
[
@@ -81,6 +83,7 @@ test('Should create a good folder tree with 1 item inside and 1 item outside', a
width: 1080,
schema: obj,
calculateMetadata: null,
+ stack: null,
},
key: 'my-comp',
type: 'composition',
@@ -105,6 +108,7 @@ test('Should create a good folder tree with 1 item inside and 1 item outside', a
width: 1080,
schema: obj,
calculateMetadata: null,
+ stack: null,
},
key: 'second-comp',
type: 'composition',
@@ -131,6 +135,7 @@ test('Should handle nested folders well', async () => {
parentFolderName: 'my-third-folder/my-second-folder',
calculateMetadata: null,
schema: obj,
+ stack: null,
},
],
[
@@ -188,6 +193,7 @@ test('Should handle nested folders well', async () => {
nonce: [[0, 0]],
width: 1080,
schema: obj,
+ stack: null,
},
key: 'my-comp',
type: 'composition',
diff --git a/packages/test-utils/src/composition-manager-context.ts b/packages/test-utils/src/composition-manager-context.ts
index a045fece15..27ee023aa1 100644
--- a/packages/test-utils/src/composition-manager-context.ts
+++ b/packages/test-utils/src/composition-manager-context.ts
@@ -39,6 +39,7 @@ export const makeMockCompositionManagerContext =
fps: 30,
height: 100,
width: 100,
+ stack: null,
},
],
canvasContent: {