🎥 Make videos programmatically with React
`@remotion/studio`: Resolve multi-sequence agent context only after the menu item is clicked
Cursor Agent83f550024c4b
diff --git a/packages/studio/src/components/Timeline/TimelineSequence.tsx b/packages/studio/src/components/Timeline/TimelineSequence.tsxindex 94cc9b423a..7c415ca560 100644--- a/packages/studio/src/components/Timeline/TimelineSequence.tsx+++ b/packages/studio/src/components/Timeline/TimelineSequence.tsx@@ -1041,21 +1041,20 @@ const TimelineSequenceInner: React.FC<{}if (selectedSequenceNodePathInfos !== null) {- return getSequencesContextForAgents({- nodePathInfos: selectedSequenceNodePathInfos,- overrideIdsToNodePaths: overrideIdToNodePathMappingsRef.current,- sequences,- }).then((contextForAgents) =>- getMultiSequenceContextMenuItems({- contextForAgents,- deleteDisabled: !previewInteractive,- duplicateDisabled: !previewInteractive,- splitDisabled: !previewInteractive,- onDeleteSelectedSequences,- onDuplicateSelectedSequences,- onSplitSelectedSequences,- }),- );+ return getMultiSequenceContextMenuItems({+ getContextForAgents: () =>+ getSequencesContextForAgents({+ nodePathInfos: selectedSequenceNodePathInfos,+ overrideIdsToNodePaths: overrideIdToNodePathMappingsRef.current,+ sequences,+ }),+ deleteDisabled: !previewInteractive,+ duplicateDisabled: !previewInteractive,+ splitDisabled: !previewInteractive,+ onDeleteSelectedSequences,+ onDuplicateSelectedSequences,+ onSplitSelectedSequences,+ });}const splitMenuItem = getSequenceSplitMenuItem({diff --git a/packages/studio/src/components/Timeline/TimelineSequenceItem.tsx b/packages/studio/src/components/Timeline/TimelineSequenceItem.tsxindex fff17601c2..3bff2ac619 100644--- a/packages/studio/src/components/Timeline/TimelineSequenceItem.tsx+++ b/packages/studio/src/components/Timeline/TimelineSequenceItem.tsx@@ -1246,21 +1246,20 @@ const TimelineSequenceItemInner: React.FC<{}if (selectedSequenceNodePathInfos !== null) {- return getSequencesContextForAgents({- nodePathInfos: selectedSequenceNodePathInfos,- overrideIdsToNodePaths: overrideIdToNodePathMappingsRef.current,- sequences: sequencesRef.current,- }).then((contextForAgents) =>- getMultiSequenceContextMenuItems({- contextForAgents,- deleteDisabled: !previewInteractive,- duplicateDisabled: !previewInteractive,- splitDisabled: !previewInteractive,- onDeleteSelectedSequences,- onDuplicateSelectedSequences,- onSplitSelectedSequences,- }),- );+ return getMultiSequenceContextMenuItems({+ getContextForAgents: () =>+ getSequencesContextForAgents({+ nodePathInfos: selectedSequenceNodePathInfos,+ overrideIdsToNodePaths: overrideIdToNodePathMappingsRef.current,+ sequences: sequencesRef.current,+ }),+ deleteDisabled: !previewInteractive,+ duplicateDisabled: !previewInteractive,+ splitDisabled: !previewInteractive,+ onDeleteSelectedSequences,+ onDuplicateSelectedSequences,+ onSplitSelectedSequences,+ });}const splitMenuItem = getSequenceSplitMenuItem({diff --git a/packages/studio/src/components/Timeline/get-sequence-context-menu-items.ts b/packages/studio/src/components/Timeline/get-sequence-context-menu-items.tsindex c3229e8f03..a24654d3e0 100644--- a/packages/studio/src/components/Timeline/get-sequence-context-menu-items.ts+++ b/packages/studio/src/components/Timeline/get-sequence-context-menu-items.ts@@ -120,7 +120,7 @@ const copyImageToClipboard = async (element: Element): Promise<void> => {};export const getMultiSequenceContextMenuItems = ({- contextForAgents,+ getContextForAgents,deleteDisabled,duplicateDisabled,splitDisabled,@@ -128,7 +128,7 @@ export const getMultiSequenceContextMenuItems = ({onDuplicateSelectedSequences,onSplitSelectedSequences,}: {- readonly contextForAgents: string | null;+ readonly getContextForAgents: () => Promise<string | null>;readonly deleteDisabled: boolean;readonly duplicateDisabled: boolean;readonly splitDisabled: boolean;@@ -137,7 +137,41 @@ export const getMultiSequenceContextMenuItems = ({readonly onSplitSelectedSequences: () => void;}): ComboboxValue[] => {return [- getCopyContextForAgentsMenuItem({contextForAgents}),+ {+ type: 'item',+ id: 'copy-context-for-agents',+ keyHint: null,+ label: 'Copy context for agents',+ leftItem: null,+ disabled: false,+ onClick: () => {+ // Passing a pending Blob keeps the write tied to the click, which+ // browsers require even though the context is resolved afterwards.+ navigator.clipboard+ .write([+ new ClipboardItem({+ 'text/plain': getContextForAgents().then((contextForAgents) => {+ if (!contextForAgents) {+ throw new Error(+ 'No source location found for the selected sequences',+ );+ }++ return new Blob([contextForAgents], {type: 'text/plain'});+ }),+ }),+ ])+ .catch((err) => {+ showNotification(+ `Could not copy to clipboard: ${(err as Error).message}`,+ 2000,+ );+ });+ },+ quickSwitcherLabel: null,+ subMenu: null,+ value: 'copy-context-for-agents',+ },{type: 'divider',id: 'copy-context-for-agents-divider',