π₯ Make videos programmatically with React
`@remotion/canvas`: Add `controller.overrides` and `controller.setSequenceNodePaths()` for editing mounted sequences outside the Studio
Jonny Burger3d9d3b252338
diff --git a/packages/browser-bundler/src/browser-module-scope.ts b/packages/browser-bundler/src/browser-module-scope.tsindex 6bc3d56ba0..986fe8667e 100644--- a/packages/browser-bundler/src/browser-module-scope.ts+++ b/packages/browser-bundler/src/browser-module-scope.ts@@ -6,10 +6,15 @@ import * as JSXRuntime from 'react/jsx-runtime';import * as Remotion from 'remotion';import * as RemotionNoReact from 'remotion/no-react';import * as RemotionVersion from 'remotion/version';+import {addSourceLocationsToJsxModules} from './source-location-jsx';-export const createBrowserModuleScope = (- additionalModules: ReadonlyMap<string, unknown> | null,-) => {+export const createBrowserModuleScope = ({+ additionalModules,+ addSourceLocations,+}: {+ additionalModules: ReadonlyMap<string, unknown> | null;+ addSourceLocations: boolean;+}) => {let root: React.FC | null = null;let registrations = 0;const registerRoot = (component: React.FC) => {@@ -30,12 +35,20 @@ export const createBrowserModuleScope = (root = component;};+ const jsxModules = addSourceLocations+ ? addSourceLocationsToJsxModules({+ react: React,+ jsxRuntime: JSXRuntime,+ jsxDevRuntime: JSXDevRuntime,+ })+ : {react: React, jsxRuntime: JSXRuntime, jsxDevRuntime: JSXDevRuntime};+const sharedModules = new Map<string, unknown>([- ['react', React],+ ['react', jsxModules.react],['react-dom', ReactDOM],['react-dom/client', ReactDOMClient],- ['react/jsx-runtime', JSXRuntime],- ['react/jsx-dev-runtime', JSXDevRuntime],+ ['react/jsx-runtime', jsxModules.jsxRuntime],+ ['react/jsx-dev-runtime', jsxModules.jsxDevRuntime],['remotion', {...Remotion, registerRoot}],['remotion/no-react', RemotionNoReact],['remotion/version', RemotionVersion],diff --git a/packages/browser-bundler/src/create-browser-bundle-runtime.ts b/packages/browser-bundler/src/create-browser-bundle-runtime.tsindex 991252219c..c6ac8ee11c 100644--- a/packages/browser-bundler/src/create-browser-bundle-runtime.ts+++ b/packages/browser-bundler/src/create-browser-bundle-runtime.ts@@ -133,9 +133,12 @@ export const createBrowserBundleRuntime = (): BrowserBundleRuntime => {);}- const initialScope = createBrowserModuleScope(- new Map([['react-refresh/runtime', refresh]]),- );+ // Development bundles carry JSX source locations, which let+ // authoring UIs trace mounted sequences back to their source.+ const initialScope = createBrowserModuleScope({+ additionalModules: new Map([['react-refresh/runtime', refresh]]),+ addSourceLocations: true,+ });Internals.setComponentIdentityResolver((component) => refresh.getFamilyByType(component) ?? component,);diff --git a/packages/browser-bundler/src/load-browser-bundle.ts b/packages/browser-bundler/src/load-browser-bundle.tsindex 09f88d5fe7..d3d1d3c8d5 100644--- a/packages/browser-bundler/src/load-browser-bundle.ts+++ b/packages/browser-bundler/src/load-browser-bundle.ts@@ -14,7 +14,10 @@ export const loadBrowserBundle = ({bundle}: {bundle: BrowserBundle}): FC => {);}- const scope = createBrowserModuleScope(null);+ const scope = createBrowserModuleScope({+ additionalModules: null,+ addSourceLocations: false,+ });scope.evaluate(bundle.code);return scope.getRoot();};diff --git a/packages/browser-bundler/src/source-location-jsx.ts b/packages/browser-bundler/src/source-location-jsx.tsnew file mode 100644index 0000000000..2e8bde1995--- /dev/null+++ b/packages/browser-bundler/src/source-location-jsx.ts@@ -0,0 +1,129 @@+import type * as React from 'react';+import type * as JSXDevRuntime from 'react/jsx-dev-runtime';+import type * as JSXRuntime from 'react/jsx-runtime';+import {Internals} from 'remotion';++type JsxFactory =+ | typeof React.createElement+ | typeof JSXRuntime.jsx+ | typeof JSXDevRuntime.jsxDEV;++type JsxSource = {+ fileName?: unknown;+ lineNumber?: unknown;+ columnNumber?: unknown;+};++// Mirrors the Studio bundler: Remotion components receive the source+// location of their JSX element so mounted sequences can be traced back to+// their source node. The development JSX transform passes the location as+// the fifth argument of jsxDEV(); other factories fall back to a stack trace.+const withSourceLocation = <T extends JsxFactory>(+ factory: T,+ {+ isCreateElement,+ sourceArgumentIndex,+ }: {+ isCreateElement: boolean;+ sourceArgumentIndex: number | null;+ },+): T => {+ const componentsToAddStacksTo = Internals.getComponentsToAddStacksTo();+ const sequenceComponent = Internals.getSequenceComponent();+ const internalStackProp = Internals.REMOTION_INTERNAL_STACK_PROP;++ return new Proxy(factory, {+ apply(target, thisArg, argArray) {+ const [component, props, ...rest] = argArray as [+ unknown,+ Record<string, unknown> | null | undefined,+ ...unknown[],+ ];+ if (!componentsToAddStacksTo.includes(component)) {+ return Reflect.apply(target, thisArg, argArray);+ }++ const source =+ sourceArgumentIndex === null+ ? null+ : (argArray[sourceArgumentIndex] as JsxSource | null | undefined);+ const stack =+ source &&+ typeof source.fileName === 'string' &&+ typeof source.lineNumber === 'number' &&+ typeof source.columnNumber === 'number'+ ? Internals.makeOriginalSourceStack({+ fileName: source.fileName,+ lineNumber: source.lineNumber,+ columnNumber: source.columnNumber,+ })+ : new Error().stack;+ const newProps: Record<string, unknown> = props?.[internalStackProp]+ ? {...props}+ : {...(props ?? {}), [internalStackProp]: stack};+ if (component === sequenceComponent) {+ const children = isCreateElement+ ? rest.length === 0+ ? newProps.children+ : rest+ : newProps.children;+ newProps._remotionInternalSingleChildComponent =+ Internals.getSingleChildComponent(children as React.ReactNode);+ }++ return Reflect.apply(target, thisArg, [component, newProps, ...rest]);+ },+ });+};++type ModuleRecord = Record<string, unknown> & {default?: unknown};++// Shared module namespaces are frozen and may expose the CommonJS export as+// `default`. Copy them so both `import React` and `import * as React` see+// the wrapped factories without mutating the host's React.+const withOverrides = (+ module: ModuleRecord,+ overrides: Record<string, unknown>,+): ModuleRecord => {+ const wrapped: ModuleRecord = {...module, ...overrides};+ if (module.default !== null && typeof module.default === 'object') {+ wrapped.default = {...(module.default as ModuleRecord), ...overrides};+ }++ return wrapped;+};++export const addSourceLocationsToJsxModules = ({+ react,+ jsxRuntime,+ jsxDevRuntime,+}: {+ react: typeof React;+ jsxRuntime: typeof JSXRuntime;+ jsxDevRuntime: typeof JSXDevRuntime;+}) => {+ return {+ react: withOverrides(react as unknown as ModuleRecord, {+ createElement: withSourceLocation(react.createElement, {+ isCreateElement: true,+ sourceArgumentIndex: null,+ }),+ }),+ jsxRuntime: withOverrides(jsxRuntime as unknown as ModuleRecord, {+ jsx: withSourceLocation(jsxRuntime.jsx, {+ isCreateElement: false,+ sourceArgumentIndex: null,+ }),+ jsxs: withSourceLocation(jsxRuntime.jsxs, {+ isCreateElement: false,+ sourceArgumentIndex: null,+ }),+ }),+ jsxDevRuntime: withOverrides(jsxDevRuntime as unknown as ModuleRecord, {+ jsxDEV: withSourceLocation(jsxDevRuntime.jsxDEV, {+ isCreateElement: false,+ sourceArgumentIndex: 4,+ }),+ }),+ };+};diff --git a/packages/browser-studio/src/virtual-files.ts b/packages/browser-studio/src/virtual-files.tsindex 61d8d32ca7..a86352257d 100644--- a/packages/browser-studio/src/virtual-files.ts+++ b/packages/browser-studio/src/virtual-files.ts@@ -54,7 +54,6 @@ Internals.setComponentIdentityResolver((component) => {const componentsToAddStacksTo = Internals.getComponentsToAddStacksTo();const sequenceComponent = Internals.getSequenceComponent();const internalStackProp = Internals.REMOTION_INTERNAL_STACK_PROP;-const browserStudioOriginalSourcePrefix = 'browser-studio-original://';const originalCreateElement = React.createElement;@@ -75,14 +74,11 @@ export const enableProxy = (api, isCreateElement, sourceArgumentIndex) => {typeof source.fileName === 'string' &&typeof source.lineNumber === 'number' &&typeof source.columnNumber === 'number'- ? 'Error\\n at browserStudioOriginal (' +- browserStudioOriginalSourcePrefix +- encodeURIComponent(source.fileName) +- ':' +- source.lineNumber +- ':' +- source.columnNumber +- ')'+ ? Internals.makeOriginalSourceStack({+ fileName: source.fileName,+ lineNumber: source.lineNumber,+ columnNumber: source.columnNumber,+ }): new Error().stack;const newProps = props?.[internalStackProp]? {...props}diff --git a/packages/bundler/src/setup-sequence-stack-traces.ts b/packages/bundler/src/setup-sequence-stack-traces.tsindex b11658b954..0a09ded2f9 100644--- a/packages/bundler/src/setup-sequence-stack-traces.ts+++ b/packages/bundler/src/setup-sequence-stack-traces.ts@@ -10,7 +10,6 @@ type ReactRefreshRuntime = {const componentsToAddStacksTo = Internals.getComponentsToAddStacksTo();const sequenceComponent = Internals.getSequenceComponent();const internalStackProp = Internals.REMOTION_INTERNAL_STACK_PROP;-const studioOriginalSourcePrefix = 'studio-original://';const originalCreateElement = React.createElement;const originalJsx = JsxRuntime.jsx;@@ -69,7 +68,11 @@ const enableProxy = <typeof source.fileName === 'string' &&typeof source.lineNumber === 'number' &&typeof source.columnNumber === 'number'- ? `Error\n at remotionOriginalSource (${studioOriginalSourcePrefix}${encodeURIComponent(getSourceFileName(source.fileName))}:${source.lineNumber}:${source.columnNumber})`+ ? Internals.makeOriginalSourceStack({+ fileName: getSourceFileName(source.fileName),+ lineNumber: source.lineNumber,+ columnNumber: source.columnNumber,+ }): new Error().stack;const newProps = props?.[internalStackProp]? {...props}diff --git a/packages/canvas/src/canvas-controller.ts b/packages/canvas/src/canvas-controller.tsindex d127c36cc8..e0830d1b9d 100644--- a/packages/canvas/src/canvas-controller.ts+++ b/packages/canvas/src/canvas-controller.ts@@ -1,13 +1,38 @@+import type React from 'react';import {useState} from 'react';-import type {TSequence} from 'remotion';+import type {+ DragOverrideValue,+ OverrideIdToNodePaths,+ SequencePropsSubscriptionKey,+ TSequence,+} from 'remotion';+import {Internals} from 'remotion';import {calculateTimeline} from './calculate-timeline';-import type {TimelineTrackData} from './get-timeline-sequence-sort-key';+import type {+ SequenceNodePathInfo,+ TimelineTrackData,+} from './get-timeline-sequence-sort-key';import {createCanvasHoverController, type CanvasHoverController} from './hover';import {createCanvasSelectionController,type CanvasSelectionController,} from './selection';+type VisualModeSetters = React.ContextType<+ typeof Internals.VisualModeSettersContext+>;++export type CanvasOverridesController = {+ /** Preview a prop value on the mounted sequence without changing the source. */+ readonly set: (+ nodePathInfo: SequenceNodePathInfo,+ key: string,+ value: DragOverrideValue,+ ) => void;+ /** Remove every override of the sequence. */+ readonly clear: (nodePathInfo: SequenceNodePathInfo) => void;+};+export type CanvasController = {readonly timeline: {readonly getSnapshot: () => readonly TimelineTrackData[];@@ -15,11 +40,24 @@ export type CanvasController = {};readonly selection: CanvasSelectionController;readonly hover: CanvasHoverController;+ readonly overrides: CanvasOverridesController;+ /**+ * Map `track.sequence.controls.overrideId` values to the source nodes the+ * sequences were mounted from. Populates `nodePathInfo` on the timeline.+ */+ readonly setSequenceNodePaths: (+ nodePaths: Record<string, SequencePropsSubscriptionKey>,+ ) => void;};type CanvasControllerInternals = {readonly setSequences: (sequences: TSequence[]) => void;readonly clear: () => void;+ readonly nodePaths: {+ readonly getSnapshot: () => OverrideIdToNodePaths;+ readonly subscribe: (listener: () => void) => () => void;+ };+ readonly setVisualModeSetters: (setters: VisualModeSetters | null) => void;};const controllerInternals = new WeakMap<@@ -27,9 +65,35 @@ const controllerInternals = new WeakMap<CanvasControllerInternals>();+const nodePathsAreEqual = (+ previous: OverrideIdToNodePaths,+ next: OverrideIdToNodePaths,+): boolean => {+ const previousIds = Object.keys(previous);+ if (previousIds.length !== Object.keys(next).length) {+ return false;+ }++ return previousIds.every((overrideId) => {+ const previousNodePath = previous[overrideId];+ const nextNodePath = next[overrideId];+ return (+ nextNodePath !== undefined &&+ Internals.makeSequencePropsSubscriptionKey(previousNodePath) ===+ Internals.makeSequencePropsSubscriptionKey(nextNodePath) &&+ JSON.stringify(previousNodePath.videoConfigValues) ===+ JSON.stringify(nextNodePath.videoConfigValues)+ );+ });+};+export const createCanvasController = (): CanvasController => {let timelineSnapshot: readonly TimelineTrackData[] = [];+ let sequences: TSequence[] = [];+ let nodePaths: OverrideIdToNodePaths = {};+ let visualModeSetters: VisualModeSetters | null = null;const timelineListeners = new Set<() => void>();+ const nodePathListeners = new Set<() => void>();const updateTimelineSnapshot = (nextSnapshot: readonly TimelineTrackData[],@@ -40,6 +104,15 @@ export const createCanvasController = (): CanvasController => {}};+ const recalculateTimeline = () => {+ updateTimelineSnapshot(+ calculateTimeline({+ sequences,+ overrideIdsToNodePaths: nodePaths,+ }),+ );+ };+const controller: CanvasController = {timeline: {getSnapshot: () => timelineSnapshot,@@ -50,21 +123,54 @@ export const createCanvasController = (): CanvasController => {},selection: createCanvasSelectionController(),hover: createCanvasHoverController(),+ overrides: {+ set: (nodePathInfo, key, value) => {+ visualModeSetters?.setDragOverrides(+ nodePathInfo.sequenceSubscriptionKey,+ key,+ value,+ );+ },+ clear: (nodePathInfo) => {+ visualModeSetters?.clearDragOverrides(+ nodePathInfo.sequenceSubscriptionKey,+ );+ },+ },+ setSequenceNodePaths: (nextNodePaths) => {+ if (nodePathsAreEqual(nodePaths, nextNodePaths)) {+ return;+ }++ nodePaths = {...nextNodePaths};+ for (const listener of nodePathListeners) {+ listener();+ }++ recalculateTimeline();+ },};controllerInternals.set(controller, {- setSequences: (sequences) => {- updateTimelineSnapshot(- calculateTimeline({- sequences,- overrideIdsToNodePaths: {},- }),- );+ setSequences: (nextSequences) => {+ sequences = nextSequences;+ recalculateTimeline();},clear: () => {+ sequences = [];updateTimelineSnapshot([]);controller.hover.clear(null);},+ nodePaths: {+ getSnapshot: () => nodePaths,+ subscribe: (listener) => {+ nodePathListeners.add(listener);+ return () => nodePathListeners.delete(listener);+ },+ },+ setVisualModeSetters: (setters) => {+ visualModeSetters = setters;+ },});return controller;diff --git a/packages/canvas/src/canvas.tsx b/packages/canvas/src/canvas.tsxindex 33b10a02e5..c83a7ce9f6 100644--- a/packages/canvas/src/canvas.tsx+++ b/packages/canvas/src/canvas.tsx@@ -1,13 +1,21 @@import type {PlayerProps, PlayerRef} from '@remotion/player';import {Player, PlayerInternals} from '@remotion/player';import type {RefObject} from 'react';-import React, {forwardRef, useCallback, useEffect, useMemo} from 'react';+import React, {+ forwardRef,+ useCallback,+ useContext,+ useEffect,+ useMemo,+} from 'react';import type {AnyZodObject, TSequence} from 'remotion';+import {Internals} from 'remotion';import type {CanvasController} from './canvas-controller';import {getCanvasControllerInternals} from './canvas-controller';import {CanvasOutlineOverlay} from './canvas-outline-overlay';import type {CanvasSequenceNodePathResolver} from './sequence-node-path';import {getCanvasSequenceNodePathInfo} from './sequence-node-path';+import {useSyncExternalStore} from './use-sync-external-store';export type CanvasProps<Schema extends AnyZodObject,@@ -20,6 +28,22 @@ export type CanvasProps<readonly resolveSequenceNodePathInfo?: CanvasSequenceNodePathResolver;};+// Rendered inside the Player so the controller can reach the Visual Mode+// override setters of the mounted composition.+const CanvasVisualModeBridge: React.FC<{+ readonly controller: CanvasController;+}> = ({controller}) => {+ const setters = useContext(Internals.VisualModeSettersContext);+ const internals = getCanvasControllerInternals(controller);++ useEffect(() => {+ internals.setVisualModeSetters(setters);+ return () => internals.setVisualModeSetters(null);+ }, [internals, setters]);++ return null;+};+const CanvasFn = <Schema extends AnyZodObject,Props extends Record<string, unknown>,@@ -37,33 +61,54 @@ const CanvasFn = <(sequences: TSequence[]) => internals.setSequences(sequences),[internals],);+ const nodePaths = useSyncExternalStore(+ internals.nodePaths.subscribe,+ internals.nodePaths.getSnapshot,+ internals.nodePaths.getSnapshot,+ );+ const nodePathGetters = useMemo(+ () => ({overrideIdToNodePathMappings: nodePaths}),+ [nodePaths],+ );useEffect(() => {return () => internals.clear();}, [internals]);const overlay = useMemo(- () =>- showOutlines ? (- <CanvasOutlineOverlay- controller={controller}- resolveSequenceNodePathInfo={resolveSequenceNodePathInfo}- />- ) : null,+ () => (+ <>+ <CanvasVisualModeBridge controller={controller} />+ {showOutlines ? (+ <CanvasOutlineOverlay+ controller={controller}+ resolveSequenceNodePathInfo={resolveSequenceNodePathInfo}+ />+ ) : null}+ </>+ ),[controller, resolveSequenceNodePathInfo, showOutlines],);return React.createElement(- PlayerInternals.TimelineSequenceObserverContext.Provider,- {value: onTimelineSequenceChange},+ Internals.EnableInteractivityProvider,+ null,React.createElement(- PlayerInternals.CanvasOverlayContext.Provider,- {value: overlay},+ Internals.OverrideIdsToNodePathsGettersContext.Provider,+ {value: nodePathGetters},React.createElement(- Player as React.ComponentType,- {- ...(playerProps as Record<string, unknown>),- ref,- } as Record<string, unknown>,+ PlayerInternals.TimelineSequenceObserverContext.Provider,+ {value: onTimelineSequenceChange},+ React.createElement(+ PlayerInternals.CanvasOverlayContext.Provider,+ {value: overlay},+ React.createElement(+ Player as React.ComponentType,+ {+ ...(playerProps as Record<string, unknown>),+ ref,+ } as Record<string, unknown>,+ ),+ ),),),);diff --git a/packages/canvas/src/index.ts b/packages/canvas/src/index.tsindex 70e0f3c5c8..defaf7fba7 100644--- a/packages/canvas/src/index.ts+++ b/packages/canvas/src/index.ts@@ -4,15 +4,24 @@ export const CanvasInternals = internals;export {Canvas} from './canvas';export type {CanvasProps} from './canvas';export {createCanvasController, useCanvasController} from './canvas-controller';-export type {CanvasController} from './canvas-controller';+export type {+ CanvasController,+ CanvasOverridesController,+} from './canvas-controller';export {createCanvasHoverController,useCanvasHover,useCanvasSequenceHover,} from './hover';export type {CanvasHover, CanvasHoverController} from './hover';-export {getCanvasSequenceNodePathInfo} from './sequence-node-path';-export type {CanvasSequenceNodePathResolver} from './sequence-node-path';+export {+ getCanvasSequenceNodePathInfo,+ getCanvasSequenceSourceLocation,+} from './sequence-node-path';+export type {+ CanvasSequenceNodePathResolver,+ CanvasSequenceSourceLocation,+} from './sequence-node-path';export {createCanvasSelectionController,getCanvasSelectionItemKey,diff --git a/packages/canvas/src/sequence-node-path.ts b/packages/canvas/src/sequence-node-path.tsindex 3b1c55f4c8..6523b16635 100644--- a/packages/canvas/src/sequence-node-path.ts+++ b/packages/canvas/src/sequence-node-path.ts@@ -1,3 +1,4 @@+import {Internals} from 'remotion';import type {SequenceNodePathInfo,TimelineTrackData,@@ -8,6 +9,37 @@ export type CanvasSequenceNodePathResolver = (index: number,) => SequenceNodePathInfo | null;+export type CanvasSequenceSourceLocation = {+ /** The file the JSX element was compiled from. */+ fileName: string;+ /** 1-based line of the JSX element. */+ line: number;+ /** 0-based column of the JSX element, matching `getJsxNodes()` from @remotion/codemods. */+ column: number;+};++/**+ * Where the sequence's JSX element was written, if the bundler recorded it.+ * Reads the mounted sequence's current stack, so call it again after a+ * Fast Refresh update to observe moved elements.+ */+export const getCanvasSequenceSourceLocation = (+ track: TimelineTrackData,+): CanvasSequenceSourceLocation | null => {+ const location = Internals.parseOriginalSourceStack(+ track.sequence.getStack(),+ );+ if (!location) {+ return null;+ }++ return {+ fileName: location.fileName,+ line: location.line,+ column: Math.max(0, location.column - 1),+ };+};+/** Resolve a source identity when available, otherwise use the mounted instance. */export const getCanvasSequenceNodePathInfo = (track: TimelineTrackData,diff --git a/packages/core/src/enable-sequence-stack-traces.ts b/packages/core/src/enable-sequence-stack-traces.tsindex 01f7ae549b..d10b7624a6 100644--- a/packages/core/src/enable-sequence-stack-traces.ts+++ b/packages/core/src/enable-sequence-stack-traces.ts@@ -11,6 +11,49 @@ let componentIdentityResolver: ComponentIdentityResolver | null = null;export const REMOTION_INTERNAL_STACK_PROP = '_remotionInternalStack';+// Bundlers that know where a JSX element was written encode its source+// location as a synthetic stack frame, so consumers can skip symbolication.+const ORIGINAL_SOURCE_STACK_PREFIX = 'studio-original://';+const originalSourceStackPattern =+ /\(studio-original:\/\/([^\s:)]*):(\d+):(\d+)\)/;++export type OriginalSourceLocation = {+ fileName: string;+ line: number;+ column: number;+};++export const makeOriginalSourceStack = ({+ fileName,+ lineNumber,+ columnNumber,+}: {+ fileName: string;+ lineNumber: number;+ columnNumber: number;+}): string => {+ return `Error\n at remotionOriginalSource (${ORIGINAL_SOURCE_STACK_PREFIX}${encodeURIComponent(fileName)}:${lineNumber}:${columnNumber})`;+};++export const parseOriginalSourceStack = (+ stack: string | null,+): OriginalSourceLocation | null => {+ if (!stack) {+ return null;+ }++ const match = stack.match(originalSourceStackPattern);+ if (!match) {+ return null;+ }++ return {+ fileName: decodeURIComponent(match[1]),+ line: Number(match[2]),+ column: Number(match[3]),+ };+};+export const getComponentsToAddStacksTo = () => componentsToAddStacksTo;export const addSequenceStackTraces = (component: unknown) => {diff --git a/packages/core/src/internals.ts b/packages/core/src/internals.tsindex 5b9fbb14c0..9f77d96406 100644--- a/packages/core/src/internals.ts+++ b/packages/core/src/internals.ts@@ -69,8 +69,11 @@ import {getSequenceComponent,getSingleChildComponent,getStackForControls,+ makeOriginalSourceStack,+ parseOriginalSourceStack,REMOTION_INTERNAL_STACK_PROP,setComponentIdentityResolver,+ type OriginalSourceLocation,} from './enable-sequence-stack-traces.js';import {findPropsToDelete} from './find-props-to-delete.js';import {@@ -286,7 +289,10 @@ import {evaluateVolume} from './volume-prop.js';import {warnAboutTooHighVolume} from './volume-safeguard.js';import type {WatchRemotionStaticFilesPayload} from './watch-static-file.js';import {WATCH_REMOTION_STATIC_FILES} from './watch-static-file.js';-import {DisableInteractivityProvider} from './with-interactivity-schema.js';+import {+ DisableInteractivityProvider,+ EnableInteractivityProvider,+} from './with-interactivity-schema.js';import {RemotionContextProvider,useRemotionContexts,@@ -388,6 +394,7 @@ export const Internals = {CanUseRemotionHooksProvider,CanUseRemotionHooks,DisableInteractivityProvider,+ EnableInteractivityProvider,PrefetchProvider,DurationsContextProvider,IsPlayerContextProvider,@@ -417,6 +424,8 @@ export const Internals = {getSequenceComponent,getSingleChildComponent,getStackForControls,+ makeOriginalSourceStack,+ parseOriginalSourceStack,REMOTION_INTERNAL_STACK_PROP,setComponentIdentityResolver,CurrentScaleContext,@@ -514,6 +523,7 @@ export type {JsxComponentIdentity,LoggingContextValue,MediaVolumeContextValue,+ OriginalSourceLocation,OverrideIdsToNodePathsGettersContext,OverrideIdsToNodePathsSettersContext,OverrideIdToNodePaths,diff --git a/packages/core/src/use-schema.ts b/packages/core/src/use-schema.tsindex 29123995bc..a239e2da64 100644--- a/packages/core/src/use-schema.ts+++ b/packages/core/src/use-schema.ts@@ -313,7 +313,16 @@ export const computeEffectiveSchemaValuesDotNotation = ({let value: unknown;if (status === null) {- value = currentValue[key];+ // Without a source status (for example outside the Studio), an+ // override still previews on top of the runtime value.+ const dragOverride = resolveDragOverrideValue({+ dragOverrideValue: overrideValues[key],+ frame,+ });+ value =+ dragOverride.type === 'resolved'+ ? dragOverride.value+ : currentValue[key];} else if (isKeyframedStatus(status)) {if (field?.type === 'array' || field?.keyframable === false) {value = currentValue[key];diff --git a/packages/core/src/with-interactivity-schema.ts b/packages/core/src/with-interactivity-schema.tsindex b506ec2916..fe959055f2 100644--- a/packages/core/src/with-interactivity-schema.ts+++ b/packages/core/src/with-interactivity-schema.ts@@ -183,6 +183,20 @@ export const DisableInteractivityProvider: React.FC<{);};+// Authoring surfaces outside the Studio, such as @remotion/canvas, opt into+// populating `controls` and applying Visual Mode overrides.+const EnableInteractivityContext = createContext(false);++export const EnableInteractivityProvider: React.FC<{+ readonly children: React.ReactNode;+}> = ({children}) => {+ return React.createElement(+ EnableInteractivityContext.Provider,+ {value: true},+ children,+ );+};+export const withInteractivitySchema = <S extends InteractivitySchema,Props extends object,@@ -207,9 +221,10 @@ export const withInteractivitySchema = <const env = useRemotionEnvironment();const canUseRemotionHooks = useContext(CanUseRemotionHooks);const disableInteractivity = useContext(DisableInteractivityContext);+ const enableInteractivity = useContext(EnableInteractivityContext);if (- !env.isStudio ||+ (!env.isStudio && !enableInteractivity) ||env.isRendering ||!canUseRemotionHooks ||disableInteractivitydiff --git a/packages/docs/docs/browser-bundler/create-browser-bundle-runtime.mdx b/packages/docs/docs/browser-bundler/create-browser-bundle-runtime.mdxindex f072218146..87e85b6cab 100644--- a/packages/docs/docs/browser-bundler/create-browser-bundle-runtime.mdx+++ b/packages/docs/docs/browser-bundler/create-browser-bundle-runtime.mdx@@ -71,6 +71,12 @@ The returned root registers compositions; it is not the video component for theCalling [`getBrowserComposition()`](/docs/browser-bundler/get-browser-composition) again for every edit creates fresh component wrappers and does not preserve that tree.+## Source locations<AvailableFrom v="4.0.529" />++Development bundles record the file, line and column of every JSX element. The runtime forwards this location to Remotion's built-in elements and to components wrapped with [`Interactive.withSchema()`](/docs/interactive-with-schema) when the bundle renders them. Rendering the composition with [`<Canvas>`](/docs/canvas/canvas) exposes the location of each mounted sequence through [`getCanvasSequenceSourceLocation()`](/docs/canvas/get-canvas-sequence-source-location), so an editor can map a track to its source node.++Only the bundle's own JSX carries locations. Elements created by dependencies resolved over HTTP do not, and their location is `null`. The host's React is not modified.+## Return valueA `BrowserBundleRuntime` with the following methods. Use one runtime per preview document.diff --git a/packages/docs/docs/browser-bundler/create-browser-bundler.mdx b/packages/docs/docs/browser-bundler/create-browser-bundler.mdxindex 6024293904..8a4de1a73a 100644--- a/packages/docs/docs/browser-bundler/create-browser-bundler.mdx+++ b/packages/docs/docs/browser-bundler/create-browser-bundler.mdx@@ -99,7 +99,7 @@ The total download size in bytes, or `null` if the size is not yet known. Only cA `string` or `URL` pointing to the browser bundler's prebuilt module worker on the same origin as your app. By default, the package resolves its worker relative to its own module URL.-Use this when you serve the packaged worker at a custom location. The URL must point to the browser bundler worker, not to your virtual project's entry point. Host its adjacent WebAssembly and supporting worker assets too, preserving their filenames and relative paths. See [host bundler support](/docs/browser-bundler#host-bundler-support).+Use this when you serve the packaged worker at a custom location. The URL must point to the browser bundler worker, not to your virtual project's entry point. Host its adjacent WebAssembly and supporting worker assets too, preserving their filenames and relative paths. See [host bundler support](/docs/browser-bundler#host-bundler-support) and [serving the compiler as static files](/docs/browser-bundler#serving-the-compiler-as-static-files).## Return valuediff --git a/packages/docs/docs/browser-bundler/index.mdx b/packages/docs/docs/browser-bundler/index.mdxindex 9032173857..b386f31777 100644--- a/packages/docs/docs/browser-bundler/index.mdx+++ b/packages/docs/docs/browser-bundler/index.mdx@@ -44,13 +44,79 @@ The compiler downloads a sizable WebAssembly binary and can use significant memoThe package ships a prebuilt compiler worker together with its WebAssembly binary and supporting worker asset. Your app's bundler must handle `new Worker(new URL(..., import.meta.url))` and emit the assets referenced with `new URL(..., import.meta.url)`. Serve those emitted assets alongside your app.-Alternatively, use [`workerUrl`](/docs/browser-bundler/create-browser-bundler#workerurl) to host the packaged worker and its adjacent assets at a custom same-origin location. Preserve the packaged filenames and relative paths. This overrides the main worker URL, not the requirement to deploy its supporting assets.+Alternatively, use [`workerUrl`](/docs/browser-bundler/create-browser-bundler#workerurl) to host the packaged worker and its adjacent assets at a custom same-origin location. Preserve the packaged filenames and relative paths. This overrides the main worker URL, not the requirement to deploy its supporting assets. See [serving the compiler as static files](#serving-the-compiler-as-static-files) for a setup that does not depend on the host bundler.Other bundlers and deployment configurations are not guaranteed to work without additional setup. Call these APIs on the client, not during server rendering.-### Next.js with webpack+### Next.js-The initial Next.js integration uses webpack for development and production builds, not Turbopack:+For TypeScript projects, use `"moduleResolution": "bundler"` in `tsconfig.json` so imports from `@remotion/browser-bundler/runtime` resolve through the package's exports.++Add the cross-origin isolation headers to the routes that use the compiler, including the compiler assets. This example uses `/browser-bundler` as the page route; replace it with your route.++```js title="next.config.mjs"+/** @type {import('next').NextConfig} */+const nextConfig = {+ async headers() {+ return ['/browser-bundler', '/_next/:path*', '/compiler/:path*'].map(+ (source) => ({+ source,+ headers: [+ {key: 'Cross-Origin-Opener-Policy', value: 'same-origin'},+ {key: 'Cross-Origin-Embedder-Policy', value: 'require-corp'},+ ],+ }),+ );+ },+};++export default nextConfig;+```++If other pages are served without these headers, use full-page navigation when entering or leaving this route. Next.js client-side navigation does not change the current document's cross-origin isolation. A normal `<a>` link performs a full-page navigation.++#### Serving the compiler as static files<AvailableFrom v="4.0.529" />++The recommended setup works with Turbopack and webpack, in the App Router and the Pages Router: copy the compiler assets into `public/` and point [`workerUrl`](/docs/browser-bundler/create-browser-bundler#workerurl) at them. The worker resolves its WebAssembly binary and supporting worker relative to its own URL, so the Next.js bundler does not process them.++```js title="scripts/copy-compiler.mjs"+import {copyFile, mkdir} from 'node:fs/promises';+import {createRequire} from 'node:module';+import path from 'node:path';++const require = createRequire(import.meta.url);+const dist = path.join(+ path.dirname(require.resolve('@remotion/browser-bundler/package.json')),+ 'dist',+);+const target = path.join(process.cwd(), 'public', 'compiler');++await mkdir(target, {recursive: true});+for (const asset of [+ 'browser-bundler-worker.js',+ 'rspack.wasm32-wasi.wasm',+ 'wasi-worker-browser.mjs',+]) {+ await copyFile(path.join(dist, asset), path.join(target, asset));+}+```++Run the script before `next dev` and `next build`, and ignore `public/compiler` in version control. Then create the bundler with the served worker:++```ts twoslash title="compiler.ts"+// @moduleResolution: bundler+import {createBrowserBundler} from '@remotion/browser-bundler';++const bundler = createBrowserBundler({+ workerUrl: new URL('/compiler/browser-bundler-worker.js', window.location.origin),+});+```++Without `workerUrl`, the package falls back to `new Worker(new URL('./browser-bundler-worker.js', import.meta.url))`, which makes the Next.js bundler process the worker and its assets. In the App Router, the supporting worker is then transpiled and fails to start with `Cannot use 'import.meta' outside a module`, and Turbopack warns about a module format mismatch.++#### Bundling the compiler with webpack++In the Pages Router with webpack, the compiler assets can be bundled by Next.js instead. Use webpack for development and production builds, not Turbopack:```json title="package.json (scripts)"{@@ -61,22 +127,11 @@ The initial Next.js integration uses webpack for development and production buil}```-For TypeScript projects, use `"moduleResolution": "bundler"` in `tsconfig.json` so imports from `@remotion/browser-bundler/runtime` resolve through the package's exports.--Merge these headers and webpack rules into your configuration. This example uses `/browser-bundler` as the page route; replace it with your route.+Merge these rules into your configuration:```js title="next.config.mjs"/** @type {import('next').NextConfig} */const nextConfig = {- async headers() {- return ['/browser-bundler', '/_next/:path*'].map((source) => ({- source,- headers: [- {key: 'Cross-Origin-Opener-Policy', value: 'same-origin'},- {key: 'Cross-Origin-Embedder-Policy', value: 'require-corp'},- ],- }));- },webpack(config) {config.module.rules.push({test: /browser-bundler-worker\.js$/, parser: {url: true}},@@ -90,11 +145,9 @@ const nextConfig = {export default nextConfig;```-If other pages are served without these headers, use full-page navigation when entering or leaving this route. Next.js client-side navigation does not change the current document's cross-origin isolation. A normal `<a>` link performs a full-page navigation.-Next.js normally makes asset URLs relative. The supporting worker starts from a `blob:` URL, so its `importScripts()` call needs an absolute script URL. The scoped `parser: {url: true}` rule preserves that behavior for the packaged compiler worker without changing URL handling throughout your app.-This configuration is specific to webpack. Check that the emitted worker and WebAssembly URLs remain accessible in your deployment.+This configuration does not work in the App Router, where the supporting worker is passed through the React Refresh loader before the `asset/resource` rule applies. Use the static files setup above instead.## Trusted code onlydiff --git a/packages/docs/docs/canvas/canvas.mdx b/packages/docs/docs/canvas/canvas.mdxindex c7f87460c3..149747e513 100644--- a/packages/docs/docs/canvas/canvas.mdx+++ b/packages/docs/docs/canvas/canvas.mdx@@ -9,6 +9,8 @@ crumb: '@remotion/canvas'Renders a Remotion composition using [`<Player>`](/docs/player/player), registers its timeline tracks, and optionally overlays selection outlines.+Unlike a plain `<Player>`, the Canvas enables the interactivity of the mounted elements: each track exposes its [`controls`](/docs/canvas/create-canvas-controller#sequencecontrols) and the controller can [preview prop values](/docs/canvas/create-canvas-controller#overrides) without changing the source.+:::warning_Experimental API_: This package is not stable. Its public API may change without a major version bump.@@ -51,7 +53,7 @@ Clicking empty canvas space or pressing Escape while the overlay is focused clea### resolveSequenceNodePathInfo?-A `CanvasSequenceNodePathResolver` called with a [`TimelineTrackData`](/docs/canvas/create-canvas-controller#timeline) and its index. It returns a `SequenceNodePathInfo` identity or `null` to make the track unselectable. The default is [`getCanvasSequenceNodePathInfo()`](/docs/canvas/get-canvas-sequence-node-path-info).+A `CanvasSequenceNodePathResolver` called with a [`TimelineTrackData`](/docs/canvas/create-canvas-controller#timeline) and its index. It returns a `SequenceNodePathInfo` identity or `null` to make the track unselectable. The default is [`getCanvasSequenceNodePathInfo()`](/docs/canvas/get-canvas-sequence-node-path-info), which uses the identities registered with [`setSequenceNodePaths()`](/docs/canvas/create-canvas-controller#setsequencenodepaths).Use the same resolver when constructing selection items for the layer list. Keep its function identity stable where possible, for example with `useCallback()`.diff --git a/packages/docs/docs/canvas/create-canvas-controller.mdx b/packages/docs/docs/canvas/create-canvas-controller.mdxindex de47ed4671..5ae9147bb5 100644--- a/packages/docs/docs/canvas/create-canvas-controller.mdx+++ b/packages/docs/docs/canvas/create-canvas-controller.mdx@@ -28,7 +28,13 @@ The function takes no arguments.An external store of `readonly TimelineTrackData[]`. Subscribe with `timeline.subscribe(listener)` and read with `timeline.getSnapshot()`. In React, pass both to `useSyncExternalStore()` as shown in the [overview](/docs/canvas#basic-example). Tracks are populated while the composition is mounted and cleared when `<Canvas>` unmounts.-Each track includes `sequence` registration data, `depth`, `nodePathInfo`, and timing fields such as `cascadedStart`, `localStart`, `keyframeDisplayOffset`, `keyframePlaybackRate`, and `sequenceFrameOffset`. The sequence's `from` and `duration` are its visible timeline range. `nodePathInfo` may be `null` when no source identity was registered.+Each track includes `sequence` registration data, `depth`, `nodePathInfo`, and timing fields such as `cascadedStart`, `localStart`, `keyframeDisplayOffset`, `keyframePlaybackRate`, and `sequenceFrameOffset`. The sequence's `from` and `duration` are its visible timeline range. `nodePathInfo` is `null` until a source identity is registered with [`setSequenceNodePaths()`](#setsequencenodepaths).++#### sequence.controls<AvailableFrom v="4.0.529" />++The interactivity data of the mounted element, or `null` for elements that do not register any. The `<Canvas>` populates it for built-in elements and for components wrapped with [`Interactive.withSchema()`](/docs/interactive-with-schema).++`schema` is the element's interactivity schema, describing the editable props, their types, ranges and defaults. `runtimeValues` is a store of the current prop values in dot notation, for example `style.opacity`; read it with `getSnapshot()` and `subscribe()`. `supportsEffects` tells whether effects can be added to the element, `componentIdentity` identifies the component and `overrideId` identifies the JSX element the sequence was created from. Sequences rendered from the same element, for example in a `.map()` loop, share an `overrideId`.### selection@@ -54,6 +60,50 @@ A `CanvasSelectionController` with `getSnapshot()` and `subscribe(listener)` forA `CanvasHoverController` with `getSnapshot()`, `subscribe(listener)`, `setHoveredSequence(valueOrUpdater)`, and `clear(source)`. Use [`useCanvasSequenceHover()`](/docs/canvas/use-canvas-sequence-hover) for a layer row or [`useCanvasHover()`](/docs/canvas/use-canvas-hover) to read the current hover. `clear('canvas')` or `clear('timeline')` only clears hover from that source; `clear(null)` clears either source.+### setSequenceNodePaths()<AvailableFrom v="4.0.529" />++`setSequenceNodePaths(nodePaths)` tells the Canvas which source node each mounted sequence was created from. `nodePaths` is a `Record<string, SequencePropsSubscriptionKey>` keyed by `track.sequence.controls.overrideId`. Import the `SequencePropsSubscriptionKey` type from `remotion`; its `absolutePath` and `nodePath` identify the JSX node, as returned by [`getJsxNodes()`](/docs/codemods/get-jsx-nodes). Pass empty arrays for `sequenceKeys` and `effectKeys`, and `track.sequence.controls.videoConfigValues` or `null` for `videoConfigValues`.++Afterwards, the affected tracks carry a `nodePathInfo` with that `sequenceSubscriptionKey`. Tracks rendered from the same source node are numbered through `index` and `numberOfSequencesWithThisNodePath`. [`getCanvasSequenceNodePathInfo()`](/docs/canvas/get-canvas-sequence-node-path-info) returns the registered identity, so selection and hover stay attached to the source node across remounts.++Passing an unchanged mapping is a no-op, so the function may be called from a `timeline` subscription. Call it again after the source changed. [`getCanvasSequenceSourceLocation()`](/docs/canvas/get-canvas-sequence-source-location) shows how to derive the mapping from the compiled source locations.++### overrides<AvailableFrom v="4.0.529" />++Preview prop values on mounted sequences without changing the source. Overrides are applied to sequences that have a `nodePathInfo`, so register node paths first. They are kept while the composition stays mounted and are not persisted; write the final value to the source, for example with [`updateJsxNodeProps()`](/docs/codemods/update-jsx-node-props), and clear the override once the update has been applied.++#### set()++`set(nodePathInfo, key, value)` overrides one prop of the sequence identified by `nodePathInfo`, a `SequenceNodePathInfo` from a track or a selection item. `key` is a key of the element's interactivity schema in dot notation, such as `'style.translate'`, `'from'` or `'durationInFrames'`.++`value` is either `{type: 'static', value}` to show a fixed value, or `{type: 'keyframed', status}` where `status` is a keyframed prop status as returned by [`getJsxNodeProps()`](/docs/codemods/get-jsx-node-props) with the keyframes you want to preview. A keyframed override is evaluated at the current frame.++```tsx twoslash title="Scrubbing a value"+// @moduleResolution: bundler+import type {CanvasController, SequenceNodePathInfo} from '@remotion/canvas';+declare const controller: CanvasController;+declare const nodePathInfo: SequenceNodePathInfo;+declare const persist: (value: number) => Promise<void>;+// ---cut---+export const onScrub = (value: number) => {+ controller.overrides.set(nodePathInfo, 'style.opacity', {+ type: 'static',+ value,+ });+};++export const onScrubEnd = async (value: number) => {+ await persist(value);+ controller.overrides.clear(nodePathInfo);+};+```++The `runtimeValues` of the track keep reporting the values from the source while an override is active.++#### clear()++`clear(nodePathInfo)` removes every override of the sequence.+## Compatibility<CompatibilityTable chrome firefox safari nodejs="" bun="" serverlessFunctions="" clientSideRendering={false} serverSideRendering player studio="" hideServers />@@ -63,3 +113,4 @@ A `CanvasHoverController` with `getSnapshot()`, `subscribe(listener)`, `setHover- [`<Canvas>`](/docs/canvas/canvas)- [`useCanvasController()`](/docs/canvas/use-canvas-controller)- [`useCanvasSelection()`](/docs/canvas/use-canvas-selection)+- [`getCanvasSequenceSourceLocation()`](/docs/canvas/get-canvas-sequence-source-location)diff --git a/packages/docs/docs/canvas/get-canvas-sequence-source-location.mdx b/packages/docs/docs/canvas/get-canvas-sequence-source-location.mdxnew file mode 100644index 0000000000..21f9ead57a--- /dev/null+++ b/packages/docs/docs/canvas/get-canvas-sequence-source-location.mdx@@ -0,0 +1,91 @@+---+image: /generated/articles-docs-canvas-get-canvas-sequence-source-location.png+title: getCanvasSequenceSourceLocation()+crumb: '@remotion/canvas'+---++# getCanvasSequenceSourceLocation()<AvailableFrom v="4.0.529" />++Returns where the JSX element of a timeline track was written, if the bundler recorded it. Use it to look up the source node of a mounted sequence, for example with [`getJsxNodes()`](/docs/codemods/get-jsx-nodes) from [`@remotion/codemods`](/docs/codemods), and pass the result to [`controller.setSequenceNodePaths()`](/docs/canvas/create-canvas-controller#setsequencenodepaths).++:::warning++_Experimental API_: This package is not stable. Its public API may change without a major version bump.++:::++```ts twoslash title="resolve-node-paths.ts"+// @moduleResolution: bundler+import type {CanvasController} from '@remotion/canvas';+import type {CodemodProject} from '@remotion/codemods';+declare const controller: CanvasController;+declare const project: CodemodProject;+// ---cut---+import {getCanvasSequenceSourceLocation} from '@remotion/canvas';+import {getJsxNodes} from '@remotion/codemods';+import type {SequencePropsSubscriptionKey} from 'remotion';++export const resolveNodePaths = () => {+ const nodePaths: Record<string, SequencePropsSubscriptionKey> = {};+ for (const track of controller.timeline.getSnapshot()) {+ const overrideId = track.sequence.controls?.overrideId;+ const location = getCanvasSequenceSourceLocation(track);+ if (!overrideId || !location) {+ continue;+ }++ const node = getJsxNodes({project, filePath: location.fileName}).find(+ (candidate) =>+ candidate.location?.line === location.line &&+ candidate.location.column === location.column,+ );+ if (node) {+ nodePaths[overrideId] = {+ absolutePath: node.filePath,+ nodePath: node.nodePath,+ sequenceKeys: [],+ effectKeys: [],+ videoConfigValues: track.sequence.controls?.videoConfigValues ?? null,+ };+ }+ }++ controller.setSequenceNodePaths(nodePaths);+};+```++Source locations are available for projects compiled with [`createBrowserBundler()`](/docs/browser-bundler/create-browser-bundler) using [`enableFastRefresh`](/docs/browser-bundler/create-browser-bundler#enablefastrefresh) and executed with [`createBrowserBundleRuntime()`](/docs/browser-bundler/create-browser-bundle-runtime). Other bundlers do not record them, and the function returns `null`.++The function reads the mounted sequence's current location. After applying a Fast Refresh update that moved elements, call it again instead of caching the result.++## Parameter++### track++A `TimelineTrackData` from [`controller.timeline`](/docs/canvas/create-canvas-controller#timeline).++## Return value++A `CanvasSequenceSourceLocation`, or `null` if the location is unknown.++### fileName++The path of the file the JSX element was compiled from, as seen by the bundler. For a virtual project, this is the project-relative path with a leading slash, such as `/src/Video.tsx`.++### line++The 1-based line of the JSX element.++### column++The 0-based column of the JSX element. This matches the `location` of [`getJsxNodes()`](/docs/codemods/get-jsx-nodes).++## Compatibility++<CompatibilityTable chrome firefox safari nodejs="" bun="" serverlessFunctions="" clientSideRendering={false} serverSideRendering player studio="" hideServers />++## See also++- [`createCanvasController()`](/docs/canvas/create-canvas-controller)+- [`getCanvasSequenceNodePathInfo()`](/docs/canvas/get-canvas-sequence-node-path-info)+- [`getJsxNodes()`](/docs/codemods/get-jsx-nodes)diff --git a/packages/docs/docs/canvas/index.mdx b/packages/docs/docs/canvas/index.mdxindex 2788865536..3ff9b95bc3 100644--- a/packages/docs/docs/canvas/index.mdx+++ b/packages/docs/docs/canvas/index.mdx@@ -120,10 +120,18 @@ The timeline contains registered [`<Sequence>`](/docs/sequence) and other sequen## Selection identity-The built-in [`getCanvasSequenceNodePathInfo()`](/docs/canvas/get-canvas-sequence-node-path-info) uses a source identity when available. Otherwise it falls back to a mounted sequence ID, which can change after a remount. If your editor tracks source nodes, pass a custom `resolveSequenceNodePathInfo` to `<Canvas>` and use the same resolver for layer items. Return `null` for tracks that should not be selectable.+The built-in [`getCanvasSequenceNodePathInfo()`](/docs/canvas/get-canvas-sequence-node-path-info) uses a source identity when available. Otherwise it falls back to a mounted sequence ID, which can change after a remount.++If your editor has the source code, register the source node of each sequence with [`setSequenceNodePaths()`](/docs/canvas/create-canvas-controller#setsequencenodepaths). For projects compiled with [`@remotion/browser-bundler`](/docs/browser-bundler), [`getCanvasSequenceSourceLocation()`](/docs/canvas/get-canvas-sequence-source-location) returns the file and position of each sequence's JSX element, which [`getJsxNodes()`](/docs/codemods/get-jsx-nodes) maps to a node path. Alternatively, pass a custom `resolveSequenceNodePathInfo` to `<Canvas>` and use the same resolver for layer items. Return `null` for tracks that should not be selectable.An outline requires a registered DOM element. A `<Sequence layout="none">` has no outline of its own.+## Editing++The Canvas exposes the [`controls`](/docs/canvas/create-canvas-controller#sequencecontrols) of each mounted element: its interactivity schema and current prop values. Use them to build an inspector, and write changes to the source with [`@remotion/codemods`](/docs/codemods).++While a value is being dragged, [`controller.overrides`](/docs/canvas/create-canvas-controller#overrides) previews it on the canvas immediately. Persist the final value when the gesture ends, then clear the override.+## APIsimport {TableOfContents} from './table-of-contents';diff --git a/packages/docs/docs/canvas/table-of-contents.tsx b/packages/docs/docs/canvas/table-of-contents.tsxindex b2800b3101..a3193086a9 100644--- a/packages/docs/docs/canvas/table-of-contents.tsx+++ b/packages/docs/docs/canvas/table-of-contents.tsx@@ -42,6 +42,10 @@ export const TableOfContents: React.FC = () => {<strong>getCanvasSequenceNodePathInfo()</strong><div>Resolve a timeline track's selection identity</div></TOCItem>+ <TOCItem link="/docs/canvas/get-canvas-sequence-source-location">+ <strong>getCanvasSequenceSourceLocation()</strong>+ <div>Find where a timeline track's JSX element was written</div>+ </TOCItem><TOCItem link="/docs/canvas/get-canvas-selection-item-key"><strong>getCanvasSelectionItemKey()</strong><div>Compare selection items by identity</div>diff --git a/packages/docs/sidebars.ts b/packages/docs/sidebars.tsindex 16fca64474..33ffa1ad23 100644--- a/packages/docs/sidebars.ts+++ b/packages/docs/sidebars.ts@@ -2065,6 +2065,7 @@ const sidebars: SidebarsConfig = {'canvas/use-canvas-sequence-hover','canvas/use-canvas-hover','canvas/get-canvas-sequence-node-path-info',+ 'canvas/get-canvas-sequence-source-location','canvas/get-canvas-selection-item-key',],},diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.tsindex 7365cd454e..7c24ccac31 100644--- a/packages/docs/src/data/articles.ts+++ b/packages/docs/src/data/articles.ts@@ -693,6 +693,15 @@ export const articles = [noAi: false,slug: 'canvas/get-canvas-sequence-node-path-info',},+ {+ id: 'canvas/get-canvas-sequence-source-location',+ title: 'getCanvasSequenceSourceLocation()',+ relativePath: 'docs/canvas/get-canvas-sequence-source-location.mdx',+ compId: 'articles-docs-canvas-get-canvas-sequence-source-location',+ crumb: '@remotion/canvas',+ noAi: false,+ slug: 'canvas/get-canvas-sequence-source-location',+ },{id: 'canvas/index',title: '@remotion/canvas',diff --git a/packages/docs/static/generated/articles-docs-canvas-get-canvas-sequence-source-location.png b/packages/docs/static/generated/articles-docs-canvas-get-canvas-sequence-source-location.pngnew file mode 100644index 0000000000..00c83c145cBinary files /dev/null and b/packages/docs/static/generated/articles-docs-canvas-get-canvas-sequence-source-location.png differdiff --git a/packages/studio/src/components/Timeline/TimelineStack/get-stack.ts b/packages/studio/src/components/Timeline/TimelineStack/get-stack.tsindex 1cd0e50b8d..5b7c89bf9b 100644--- a/packages/studio/src/components/Timeline/TimelineStack/get-stack.ts+++ b/packages/studio/src/components/Timeline/TimelineStack/get-stack.ts@@ -1,4 +1,5 @@import {TraceMap, type SourceMapInput} from '@jridgewell/trace-mapping';+import {Internals} from 'remotion';import {getOriginalPosition} from '../../../error-overlay/react-overlay/utils/get-source-map';import {getLocationOfFunctionCall,@@ -9,8 +10,6 @@ const traceMapCache: Partial<Record<string, TraceMap>> = {};const traceMapPromises: Partial<Record<string, Promise<TraceMap>>> = {};const traceMapsByOriginalSource = new Map<string, TraceMap>();const sourceMapFilesCache = new WeakMap<TraceMap, Record<string, string>>();-const browserStudioOriginalSourcePrefix = 'browser-studio-original://';-const studioOriginalSourcePrefix = 'studio-original://';const getSourceMapCache = (fileName: string): Promise<TraceMap> => {if (traceMapCache[fileName]) {@@ -82,18 +81,13 @@ export const getOriginalLocationFromStack = async (return null;}- const originalSourcePrefix = [- browserStudioOriginalSourcePrefix,- studioOriginalSourcePrefix,- ].find((prefix) => location.fileName.startsWith(prefix));-- if (originalSourcePrefix) {+ // Bundlers that record the JSX source location skip symbolication.+ const originalSource = Internals.parseOriginalSourceStack(stack);+ if (originalSource) {return {- column: location.columnNumber,- line: location.lineNumber,- source: decodeURIComponent(- location.fileName.slice(originalSourcePrefix.length),- ),+ column: originalSource.column,+ line: originalSource.line,+ source: originalSource.fileName,};}diff --git a/packages/template-vibe-code/README.md b/packages/template-vibe-code/README.mdindex 6f742dc1ae..eb862e7690 100644--- a/packages/template-vibe-code/README.md+++ b/packages/template-vibe-code/README.md@@ -46,7 +46,7 @@ npx remotion render # render it with the CLI```- `src/app` β the Next.js App Router page and the dev-only `/api/project` route that saves files to disk.-- `src/editor` β the editor UI. `state/` holds the reducer (files, history, layout, playback settings), `hooks/` connect the preview iframe, the compiler and the player, `model/` contains the pure logic (composition parsing, layer β source matching, schemas) and `components/` the panels.+- `src/editor` β the editor UI. `state/` holds the reducer (files, history, layout, playback settings), `hooks/` connect the preview iframe, the compiler and the player, `model/` contains the pure logic (composition parsing, layer β source resolution, schemas) and `components/` the panels.- `src/preview` β the code that runs inside the preview iframe. It is bundled separately by `scripts/build-preview.mjs` (esbuild) because Fast Refresh needs a development build of React, which Next.js does not ship to the browser. `bridge.ts` defines the API the editor uses to talk to the iframe. The same script copies the compiler worker and WebAssembly files to `public/compiler`.- `src/remotion` β the Remotion project.@@ -58,9 +58,13 @@ Fast Refresh requires the React Refresh runtime to be installed before React DOMThe browser bundler compiles with WebAssembly and shared memory, which requires the page to be [cross-origin isolated](https://web.dev/articles/coop-coep). `next.config.mjs` sets the `Cross-Origin-Opener-Policy` and `Cross-Origin-Embedder-Policy` headers. Every cross-origin resource you load (fonts, images, scripts) needs to either support CORS or send a `Cross-Origin-Resource-Policy` header.-### How layers are matched to code+### How layers are linked to code-The Canvas reports the sequences that are mounted at runtime, but not where they were written. The editor matches them to JSX elements heuristically: first by the `name` prop, then by element type in source order. Give your layers unique `name` props to make the mapping robust β this is also what the Remotion Studio [recommends](https://www.remotion.dev/docs/studio/interactivity-best-practices). Layers that cannot be matched are shown but not editable.+The browser bundler records where every JSX element was written, and the Canvas exposes that location for each mounted sequence through [`getCanvasSequenceSourceLocation()`](https://www.remotion.dev/docs/canvas/get-canvas-sequence-source-location). The editor looks the location up in the compiled files with `getJsxNodes()` and registers the resulting node paths with [`controller.setSequenceNodePaths()`](https://www.remotion.dev/docs/canvas/create-canvas-controller#setsequencenodepaths), so selection, the timeline and the inspector all refer to the same source node β also for elements rendered in a `.map()` loop. Elements created by dependencies have no source location and are shown but not editable.++### Live previews++Dragging a value in the inspector or a track in the timeline does not rewrite the source on every pointer move. The editor previews the value on the canvas with [`controller.overrides`](https://www.remotion.dev/docs/canvas/create-canvas-controller#overrides) and writes it with a codemod once the gesture ends. The preview stays in place until the recompiled project is running, so the canvas never flashes the old value.## Commandsdiff --git a/packages/template-vibe-code/src/editor/Editor.tsx b/packages/template-vibe-code/src/editor/Editor.tsxindex 4b97193db6..db5e3b18a9 100644--- a/packages/template-vibe-code/src/editor/Editor.tsx+++ b/packages/template-vibe-code/src/editor/Editor.tsx@@ -63,6 +63,10 @@ export const Editor: React.FC<{const iframeRef = useRef<HTMLIFrameElement | null>(null);const project = useMemo(() => toCodemodProject(state.files), [state.files]);+ const compiledProject = useMemo(+ () => (state.appliedFiles ? toCodemodProject(state.appliedFiles) : project),+ [project, state.appliedFiles],+ );const compositionFile = useMemo(() => findCompositionFile(project),[project],@@ -139,7 +143,7 @@ export const Editor: React.FC<{() => host?.getSnapshot().composition ?? null,() => null,);- const layers = useLayers({ host, project, mainFile });+ const layers = useLayers({ host, compiledProject });const selection = useMemo(() =>@@ -231,6 +235,16 @@ export const Editor: React.FC<{context: { state, host, layers, compositions, fps: compositionFps },});+ // Previewed values are released once the preview runs the committed source+ // or the compilation failed, so they never linger over stale output.+ const previewUpToDate = state.appliedFiles === state.files;+ const compileFailed = state.compile.type === "error";+ useEffect(() => {+ if (previewUpToDate || compileFailed) {+ actions.releasePreviews();+ }+ }, [actions, compileFailed, previewUpToDate]);+useEffect(() => {if (state.notices.length === 0) {return;diff --git a/packages/template-vibe-code/src/editor/components/Inspector/LayerActions.tsx b/packages/template-vibe-code/src/editor/components/Inspector/LayerActions.tsxindex 36d040b1a3..4d0fab9730 100644--- a/packages/template-vibe-code/src/editor/components/Inspector/LayerActions.tsx+++ b/packages/template-vibe-code/src/editor/components/Inspector/LayerActions.tsx@@ -37,14 +37,14 @@ import {DropdownMenuTrigger,} from "@/components/ui/dropdown-menu";import { getNodeReference, type Layer } from "../../model/layers";-import { getSchemaForTag, hasTimingProps } from "../../model/schemas";+import { getLayerSchema, hasTimingProps } from "../../model/schemas";import { useEditor } from "../../state/editor-context";import { ToolbarButton } from "../TopBar";export const useLayerCommands = (layer: Layer) => {const { actions } = useEditor();const node = getNodeReference(layer.selectionItem);- const schema = layer.source ? getSchemaForTag(layer.source.tagName) : null;+ const schema = getLayerSchema(layer);const source = layer.source;return {diff --git a/packages/template-vibe-code/src/editor/components/Inspector/LayerInspector.tsx b/packages/template-vibe-code/src/editor/components/Inspector/LayerInspector.tsxindex 92eb2a78e3..9b2d519c00 100644--- a/packages/template-vibe-code/src/editor/components/Inspector/LayerInspector.tsx+++ b/packages/template-vibe-code/src/editor/components/Inspector/LayerInspector.tsx@@ -15,7 +15,7 @@ import {fieldGroupOrder,getFieldGroup,getFieldLabel,- getSchemaForTag,+ getLayerSchema,getVisibleFields,type FieldGroup,} from "../../model/schemas";@@ -64,9 +64,12 @@ const PropEditor: React.FC<{readonly field: VisibleField["field"];readonly status: PropStatus | undefined;readonly onUpdate: (updates: SequencePropUpdate[]) => void;-}> = ({ fieldKey, field, status, onUpdate }) => {+ /** Shows a value on the canvas while it is being dragged. */+ readonly onPreview: (values: Record<string, unknown>) => void;+}> = ({ fieldKey, field, status, onUpdate, onPreview }) => {const label = getFieldLabel(fieldKey, field);const ariaLabel = label;+ const preview = (value: unknown) => onPreview({ [fieldKey]: value });if (status && status.status !== "static") {return (@@ -118,6 +121,7 @@ const PropEditor: React.FC<{integer={field.integer}allowEmptyonCommit={(value) => commit(value === null ? undefined : value)}+ onLiveChange={preview}/></FieldRow>);@@ -150,6 +154,9 @@ const PropEditor: React.FC<{onCommit={(x) =>commit(serializeTranslate({ x: x ?? 0, y: current.y }))}+ onLiveChange={(x) =>+ preview(serializeTranslate({ x, y: current.y }))+ }/><NumberFieldariaLabel={`${label} Y`}@@ -159,6 +166,9 @@ const PropEditor: React.FC<{onCommit={(y) =>commit(serializeTranslate({ x: current.x, y: y ?? 0 }))}+ onLiveChange={(y) =>+ preview(serializeTranslate({ x: current.x, y }))+ }/></FieldRow>);@@ -174,6 +184,7 @@ const PropEditor: React.FC<{max={field.max}step={field.step ?? 0.01}onCommit={(value) => commit(value ?? 1)}+ onLiveChange={preview}/></FieldRow>);@@ -187,6 +198,7 @@ const PropEditor: React.FC<{unit="Β°"step={field.step ?? 1}onCommit={(value) => commit(serializeRotation(value ?? 0))}+ onLiveChange={(value) => preview(serializeRotation(value))}/></FieldRow>);@@ -202,6 +214,7 @@ const PropEditor: React.FC<{max={field.max}step={field.step ?? 1}onCommit={(value) => commit(value ?? 0)}+ onLiveChange={preview}/></FieldRow>);@@ -216,6 +229,7 @@ const PropEditor: React.FC<{typeof schemaDefault === "string" ? schemaDefault : undefined}onCommit={(value) => commit(value === "" ? undefined : value)}+ onLiveChange={preview}/></FieldRow>);@@ -304,7 +318,7 @@ export const LayerInspector: React.FC<{ readonly layer: Layer }> = ({const { project, actions, composition } = useEditor();const node = getNodeReference(layer.selectionItem);const source = layer.source;- const schema = source ? getSchemaForTag(source.tagName) : null;+ const schema = getLayerSchema(layer);const displayName = layer.track.sequence.displayName;const label = getLayerLabel(layer);@@ -375,9 +389,12 @@ export const LayerInspector: React.FC<{ readonly layer: Layer }> = ({const onUpdate = (updates: SequencePropUpdate[]) => {if (node) {- void actions.updateNodeProps(node, updates, schema);+ void actions.commitLayerProps(layer, updates, schema);}};+ const onPreview = (values: Record<string, unknown>) => {+ actions.previewLayerProps(layer, values);+ };return (<div className="flex flex-col gap-4 p-3">@@ -406,9 +423,7 @@ export const LayerInspector: React.FC<{ readonly layer: Layer }> = ({{node ? (<TextFieldariaLabel="Layer name"- value={- source?.name ?? (displayName.startsWith("<") ? "" : displayName)- }+ value={displayName.startsWith("<") ? "" : displayName}placeholder={label}onCommit={(name) => void actions.renameNode(node, name)}/>@@ -420,10 +435,9 @@ export const LayerInspector: React.FC<{ readonly layer: Layer }> = ({<LayerActionBar layer={layer} />) : (<p className="text-muted-foreground bg-muted/50 rounded-md p-2 text-[11px] leading-relaxed">- This layer could not be matched to a JSX element in the source code,- so it cannot be edited here. Layers are matched by their{" "}- <code className="font-mono">name</code> prop first and by element type- in source order second β give it a unique name to link it.+ This layer is not linked to a JSX element in the source code, so it+ cannot be edited here. Elements rendered by dependencies do not carry+ a source location.</p>)}{source && !schema ? (@@ -445,6 +459,7 @@ export const LayerInspector: React.FC<{ readonly layer: Layer }> = ({field={field}status={statuses?.[key]}onUpdate={onUpdate}+ onPreview={onPreview}/>))}</section>diff --git a/packages/template-vibe-code/src/editor/components/Inspector/fields.tsx b/packages/template-vibe-code/src/editor/components/Inspector/fields.tsxindex 62b07bf118..48426ed168 100644--- a/packages/template-vibe-code/src/editor/components/Inspector/fields.tsx+++ b/packages/template-vibe-code/src/editor/components/Inspector/fields.tsx@@ -56,8 +56,8 @@ export const StatusBadge: React.FC<{/*** A numeric input whose label can be dragged horizontally to scrub the value,- * like in motion graphics tools. Commits while dragging (throttled) and on- * blur / Enter.+ * like in motion graphics tools. While dragging, `onLiveChange` previews the+ * value; the value is committed when the drag ends and on blur / Enter.*/export const NumberField: React.FC<{readonly value: number | null;@@ -83,13 +83,17 @@ export const NumberField: React.FC<{unit,disabled,onCommit,+ onLiveChange,ariaLabel,className,allowEmpty = false,}) => {const [draft, setDraft] = useState<string | null>(null);- const dragRef = useRef<{ startX: number; startValue: number } | null>(null);- const lastCommit = useRef(0);+ const dragRef = useRef<{+ startX: number;+ startValue: number;+ previewed: boolean;+ } | null>(null);const normalize = (raw: number) => {let next = raw;@@ -131,7 +135,11 @@ export const NumberField: React.FC<{onPointerDown={(event) => {if (disabled) return;event.preventDefault();- dragRef.current = { startX: event.clientX, startValue: value ?? 0 };+ dragRef.current = {+ startX: event.clientX,+ startValue: value ?? 0,+ previewed: false,+ };event.currentTarget.setPointerCapture(event.pointerId);}}onPointerMove={(event) => {@@ -141,10 +149,9 @@ export const NumberField: React.FC<{const multiplier = event.shiftKey ? 10 : event.altKey ? 0.1 : 1;const next = normalize(drag.startValue + pixels * step * multiplier);setDraft(String(next));- const now = Date.now();- if (now - lastCommit.current > 150) {- lastCommit.current = now;- onCommit(next);+ if (onLiveChange) {+ drag.previewed = true;+ onLiveChange(next);}}}onPointerUp={(event) => {@@ -156,7 +163,9 @@ export const NumberField: React.FC<{const multiplier = event.shiftKey ? 10 : event.altKey ? 0.1 : 1;const next = normalize(drag.startValue + pixels * step * multiplier);setDraft(null);- if (next !== value) {+ // A previewed value is committed even if it ends up unchanged so+ // that the preview is released.+ if (next !== value || drag.previewed) {onCommit(next);}}}@@ -309,9 +318,10 @@ export const ColorField: React.FC<{readonly disabled?: boolean;readonly ariaLabel: string;readonly onCommit: (value: string) => void;-}> = ({ value, placeholder, disabled, ariaLabel, onCommit }) => {+ readonly onLiveChange?: (value: string) => void;+}> = ({ value, placeholder, disabled, ariaLabel, onCommit, onLiveChange }) => {const hex = toHexColor(value || placeholder || "") ?? "#000000";- const lastCommit = useRef(0);+ const previewed = useRef(false);return (<div className="flex min-w-0 flex-1 items-center gap-1.5">@@ -335,14 +345,17 @@ export const ColorField: React.FC<{className="absolute inset-0 size-full cursor-pointer opacity-0"value={hex}onChange={(event) => {- const now = Date.now();- if (now - lastCommit.current > 150) {- lastCommit.current = now;- onCommit(event.target.value);+ // The picker fires continuously while a color is being chosen.+ // Preview it and commit once the picker closes.+ if (onLiveChange) {+ previewed.current = true;+ onLiveChange(event.target.value);}}}onBlur={(event) => {- if (event.target.value !== toHexColor(value)) {+ const wasPreviewed = previewed.current;+ previewed.current = false;+ if (wasPreviewed || event.target.value !== toHexColor(value)) {onCommit(event.target.value);}}}diff --git a/packages/template-vibe-code/src/editor/components/Timeline/Timeline.tsx b/packages/template-vibe-code/src/editor/components/Timeline/Timeline.tsxindex 8363071e55..5e94a48853 100644--- a/packages/template-vibe-code/src/editor/components/Timeline/Timeline.tsx+++ b/packages/template-vibe-code/src/editor/components/Timeline/Timeline.tsx@@ -24,12 +24,13 @@ import React, {} from "react";import { cn } from "@/lib/utils";import { usePlaybackFrame } from "../../hooks/use-playback";+import { getErrorMessage } from "../../hooks/use-preview-host";import {getLayerLabel,getNodeReference,type Layer,} from "../../model/layers";-import { getSchemaForTag, hasTimingProps } from "../../model/schemas";+import { getLayerSchema, hasTimingProps } from "../../model/schemas";import { clamp, formatTimecode } from "../../model/values";import { useEditor } from "../../state/editor-context";import { fallbackSelectionController } from "../../state/fallback-selection";@@ -46,6 +47,10 @@ type DragState = {mode: "move" | "start" | "end";startX: number;deltaFrames: number;+ // Timeline geometry when the drag started. The preview moves the sequence+ // live, so the bar is drawn from these values instead of the live track.+ startFrom: number;+ startDuration: number;};const getTickInterval = (pxPerFrame: number, fps: number) => {@@ -135,18 +140,20 @@ const TrackRow = memo(function TrackRow({"timeline",);const { sequence, depth } = layer.track;- const schema = layer.source ? getSchemaForTag(layer.source.tagName) : null;+ const schema = getLayerSchema(layer);const editable = layer.source !== null && hasTimingProps(schema);const isDragging = drag?.layerId === sequence.id;const delta = isDragging ? drag.deltaFrames : 0;- const from = sequence.from + (isDragging && drag.mode !== "end" ? delta : 0);+ const baseFrom = isDragging ? drag.startFrom : sequence.from;+ const baseDuration = isDragging ? drag.startDuration : sequence.duration;+ const from = baseFrom + (isDragging && drag.mode !== "end" ? delta : 0);const duration = Math.max(1,isDragging && drag.mode === "start"- ? sequence.duration - delta+ ? baseDuration - delta: isDragging && drag.mode === "end"- ? sequence.duration + delta- : sequence.duration,+ ? baseDuration + delta+ : baseDuration,);const label = getLayerLabel(layer);const select = (event: React.MouseEvent) =>@@ -199,7 +206,7 @@ const TrackRow = memo(function TrackRow({{!layer.source ? (<spanclassName="text-muted-foreground-dim shrink-0 text-[9px] uppercase"- title="Could not find this layer in the source code. Give it a unique name to make it editable."+ title="This layer has no source location, so it cannot be edited here.">no source</span>@@ -353,6 +360,8 @@ export const Timeline: React.FC = () => {mode,startX: event.clientX,deltaFrames: 0,+ startFrom: layer.track.sequence.from,+ startDuration: layer.track.sequence.duration,};dragRef.current = start;const target = event.currentTarget as HTMLElement;@@ -363,6 +372,69 @@ export const Timeline: React.FC = () => {// pointer either way.}+ // The props as written in the source. Dragging previews and then+ // commits these values shifted by the dragged distance.+ const node = getNodeReference(layer.selectionItem);+ let sourceFrom = 0;+ let sourceDuration = layer.track.sequence.duration;+ let blocked: string | null = null;+ if (node) {+ try {+ const { props } = getJsxNodeProps({+ project,+ node,+ keys: ["from", "durationInFrames"],+ });+ const fromStatus = props.from;+ const durationStatus = props.durationInFrames;+ if (fromStatus?.status === "computed" && mode !== "end") {+ blocked = `The "from" prop of ${getLayerLabel(layer)} is computed. Edit it in the code instead.`;+ } else if (durationStatus?.status === "computed" && mode !== "move") {+ blocked = `The "durationInFrames" prop of ${getLayerLabel(layer)} is computed. Edit it in the code instead.`;+ }++ if (+ fromStatus?.status === "static" &&+ typeof fromStatus.codeValue === "number"+ ) {+ sourceFrom = fromStatus.codeValue;+ }++ if (+ durationStatus?.status === "static" &&+ typeof durationStatus.codeValue === "number"+ ) {+ sourceDuration = durationStatus.codeValue;+ }+ } catch (error) {+ blocked = getErrorMessage(error);+ }+ }++ const getUpdates = (deltaFrames: number) =>+ mode === "move"+ ? [{ key: "from", value: sourceFrom + deltaFrames, defaultValue: 0 }]+ : mode === "end"+ ? [+ {+ key: "durationInFrames",+ value: Math.max(1, sourceDuration + deltaFrames),+ defaultValue: null,+ },+ ]+ : [+ {+ key: "from",+ value: sourceFrom + deltaFrames,+ defaultValue: 0,+ },+ {+ key: "durationInFrames",+ value: Math.max(1, sourceDuration - deltaFrames),+ defaultValue: null,+ },+ ];+const onMove = (move: PointerEvent) => {const current = dragRef.current;if (!current) {@@ -372,9 +444,21 @@ export const Timeline: React.FC = () => {const deltaFrames = Math.round((move.clientX - current.startX) / pxPerFrame,);+ if (deltaFrames === current.deltaFrames) {+ return;+ }+const next = { ...current, deltaFrames };dragRef.current = next;setDrag(deltaFrames === 0 ? null : next);+ if (node && blocked === null) {+ actions.previewLayerProps(+ layer,+ Object.fromEntries(+ getUpdates(deltaFrames).map(({ key, value }) => [key, value]),+ ),+ );+ }};const onUp = () => {@@ -384,82 +468,21 @@ export const Timeline: React.FC = () => {const current = dragRef.current;dragRef.current = null;setDrag(null);- if (!current || current.deltaFrames === 0 || !layer.source) {+ if (!current || current.deltaFrames === 0 || !node || !layer.source) {+ actions.cancelLayerPreview(layer);return;}- const node = getNodeReference(layer.selectionItem);- const schema = getSchemaForTag(layer.source.tagName);- if (!node) {+ if (blocked !== null) {+ actions.notifyError(new Error(blocked));return;}- try {- const { props } = getJsxNodeProps({- project,- node,- keys: ["from", "durationInFrames"],- });- const fromStatus = props.from;- const durationStatus = props.durationInFrames;- if (fromStatus?.status === "computed" && current.mode !== "end") {- throw new Error(- `The "from" prop of ${getLayerLabel(layer)} is computed. Edit it in the code instead.`,- );- }-- if (- durationStatus?.status === "computed" &&- current.mode !== "move"- ) {- throw new Error(- `The "durationInFrames" prop of ${getLayerLabel(layer)} is computed. Edit it in the code instead.`,- );- }-- const currentFrom =- fromStatus?.status === "static" &&- typeof fromStatus.codeValue === "number"- ? fromStatus.codeValue- : 0;- const currentDuration =- durationStatus?.status === "static" &&- typeof durationStatus.codeValue === "number"- ? durationStatus.codeValue- : layer.track.sequence.duration;- const updates =- current.mode === "move"- ? [- {- key: "from",- value: currentFrom + current.deltaFrames,- defaultValue: 0,- },- ]- : current.mode === "end"- ? [- {- key: "durationInFrames",- value: Math.max(1, currentDuration + current.deltaFrames),- defaultValue: null,- },- ]- : [- {- key: "from",- value: currentFrom + current.deltaFrames,- defaultValue: 0,- },- {- key: "durationInFrames",- value: Math.max(1, currentDuration - current.deltaFrames),- defaultValue: null,- },- ];- void actions.updateNodeProps(node, updates, schema);- } catch (error) {- actions.notifyError(error);- }+ void actions.commitLayerProps(+ layer,+ getUpdates(current.deltaFrames),+ getLayerSchema(layer),+ );};window.addEventListener("pointermove", onMove);@@ -686,8 +709,8 @@ export const Timeline: React.FC = () => {})}>- Some layers could not be matched to the source code. Give them a- unique <code>name</code> prop to edit them here.+ Some layers have no source location and cannot be edited here. They+ are rendered by dependencies or by code the compiler did not process.</button>) : null}</div>diff --git a/packages/template-vibe-code/src/editor/hooks/use-compiler.ts b/packages/template-vibe-code/src/editor/hooks/use-compiler.tsindex 833549f82e..6d61e689a3 100644--- a/packages/template-vibe-code/src/editor/hooks/use-compiler.ts+++ b/packages/template-vibe-code/src/editor/hooks/use-compiler.ts@@ -147,6 +147,7 @@ export const useCompiler = ({// applied because the next Fast Refresh update builds on it.await host.applyBundle(bundle);session.hasBundle = true;+ dispatch({ type: "set-applied-files", files: nextFiles });const desired = selectionRef.current;if (desired && !sameSelection(desired, session.appliedSelection)) {session.appliedSelection = desired;diff --git a/packages/template-vibe-code/src/editor/hooks/use-editor-actions.ts b/packages/template-vibe-code/src/editor/hooks/use-editor-actions.tsindex 37032bef80..b6f4a78a7f 100644--- a/packages/template-vibe-code/src/editor/hooks/use-editor-actions.ts+++ b/packages/template-vibe-code/src/editor/hooks/use-editor-actions.ts@@ -1,6 +1,10 @@"use client";-import type { CanvasSelectionInteraction } from "@remotion/canvas";+import {+ getCanvasSelectionItemKey,+ type CanvasSelectionInteraction,+ type SequenceNodePathInfo,+} from "@remotion/canvas";import {addComponent,addComposition,@@ -35,8 +39,8 @@ import type {} from "@/preview/bridge";import type { CompositionInfo } from "../model/compositions";import { formatSource } from "../model/format";-import { areSiblingNodes, type Layer } from "../model/layers";-import { getFileName, toCodemodProject } from "../model/project";+import { areSiblingNodes, getNodeReference, type Layer } from "../model/layers";+import { filesAreEqual, getFileName, toCodemodProject } from "../model/project";import { resolveProjectPathInput } from "@/lib/project-paths";import type { PlaybackStore } from "./use-playback";import { getErrorMessage } from "./use-preview-host";@@ -94,7 +98,13 @@ export const useEditorActions = ({const applyCodemod = async (run: (project: CodemodProject) => Promise<CodemodResult> | CodemodResult,- { clearSelection = false }: { clearSelection?: boolean } = {},+ {+ clearSelection = false,+ onApplied,+ }: {+ clearSelection?: boolean;+ onApplied?: (changed: boolean) => void;+ } = {},) => {try {const project = getProject();@@ -110,11 +120,13 @@ export const useEditorActions = ({}}+ const changed = !filesAreEqual(project.files, files);dispatch({ type: "set-files", files, coalesceKey: null });if (clearSelection) {ref.current.host?.controller.selection.clear();}+ onApplied?.(changed);return true;} catch (error) {notifyError(error);@@ -122,6 +134,15 @@ export const useEditorActions = ({}};+ // Values previewed on the canvas through overrides. They stay in place+ // until the preview has compiled the committed source, so the canvas does+ // not flash the old value while the bundler works.+ const pendingPreviews = new Map<string, SequenceNodePathInfo>();+ const clearPreview = (layer: Layer) => {+ pendingPreviews.delete(getCanvasSelectionItemKey(layer.selectionItem));+ ref.current.host?.controller.overrides.clear(layer.nodePathInfo);+ };+const getPlayer = () => playback.getPlayer();const seek = (frame: number) => {@@ -378,6 +399,79 @@ export const ${componentName}: React.FC = () => {},}),),+ /**+ * Shows prop values on the canvas without touching the source, e.g.+ * while a value is being scrubbed. Commit them with `commitLayerProps`.+ */+ previewLayerProps: (layer: Layer, values: Record<string, unknown>) => {+ const controller = ref.current.host?.controller;+ if (!controller || layer.track.nodePathInfo === null) {+ return;+ }++ for (const [key, value] of Object.entries(values)) {+ controller.overrides.set(layer.nodePathInfo, key, {+ type: "static",+ value,+ });+ }++ pendingPreviews.set(+ getCanvasSelectionItemKey(layer.selectionItem),+ layer.nodePathInfo,+ );+ },+ /** Drops a preview without writing to the source. */+ cancelLayerPreview: (layer: Layer) => clearPreview(layer),+ /** Writes previewed values to the source and releases the preview. */+ commitLayerProps: async (+ layer: Layer,+ updates: SequencePropUpdate[],+ schema: InteractivitySchema | null,+ ) => {+ const node = getNodeReference(layer.selectionItem);+ if (!node) {+ clearPreview(layer);+ return false;+ }++ const ok = await applyCodemod(+ (project) =>+ updateJsxNodeProps({+ project,+ node,+ updates,+ schema: schema ?? undefined,+ videoConfig: {+ width: ref.current.compositionWidth,+ height: ref.current.compositionHeight,+ fps: ref.current.compositionFps,+ durationInFrames: ref.current.compositionDurationInFrames,+ },+ }),+ {+ onApplied: (changed) => {+ if (!changed) {+ clearPreview(layer);+ }+ },+ },+ );+ if (!ok) {+ clearPreview(layer);+ }++ return ok;+ },+ /** Called once the preview shows the committed source again. */+ releasePreviews: () => {+ const controller = ref.current.host?.controller;+ for (const nodePathInfo of pendingPreviews.values()) {+ controller?.overrides.clear(nodePathInfo);+ }++ pendingPreviews.clear();+ },renameNode: (node: JsxNodeReference, name: string) =>applyCodemod((project) =>updateJsxNodeProps({diff --git a/packages/template-vibe-code/src/editor/hooks/use-layers.ts b/packages/template-vibe-code/src/editor/hooks/use-layers.tsindex 83582f88d1..2b941334ce 100644--- a/packages/template-vibe-code/src/editor/hooks/use-layers.ts+++ b/packages/template-vibe-code/src/editor/hooks/use-layers.ts@@ -1,104 +1,54 @@"use client";-import type {- CanvasSequenceNodePathResolver,- TimelineTrackData,-} from "@remotion/canvas";+import type { TimelineTrackData } from "@remotion/canvas";import type { CodemodProject } from "@remotion/codemods";-import { useEffect, useMemo, useRef, useSyncExternalStore } from "react";+import { useEffect, useMemo, useSyncExternalStore } from "react";import type { PreviewHost } from "@/preview/bridge";import {buildLayers,- collectSourceNodes,- mapTracksToSources,+ resolveSequenceNodePaths,type Layer,- type SourceNode,} from "../model/layers";const emptyTracks: readonly TimelineTrackData[] = [];const noopSubscribe = () => () => {};/**- * Both the layer list in the editor and the selection outlines in the Canvas- * need to agree on the identity of every layer. Computing the layers from- * the same (tracks, source nodes) pair through a single memoized function- * guarantees they match, even though the Canvas asks for identities from- * inside the iframe.+ * Registers the source node of every mounted sequence with the Canvas and+ * derives the layer list from the resulting timeline.+ *+ * The source locations reported by the preview refer to the files that were+ * compiled last, so everything is resolved against `compiledProject`. While+ * an edit is being compiled, the layers keep describing what the preview+ * shows; they catch up as soon as the new bundle is running.*/-const createLayerCache = () => {- let cachedTracks: readonly TimelineTrackData[] | null = null;- let cachedNodes: readonly SourceNode[] | null = null;- let cachedMainFile: string | null = null;- let cachedLayers: Layer[] = [];-- return (- tracks: readonly TimelineTrackData[],- nodes: readonly SourceNode[],- mainFile: string | null,- ): Layer[] => {- if (- cachedTracks === tracks &&- cachedNodes === nodes &&- cachedMainFile === mainFile- ) {- return cachedLayers;- }-- cachedTracks = tracks;- cachedNodes = nodes;- cachedMainFile = mainFile;- cachedLayers = buildLayers(- tracks,- mapTracksToSources(tracks, nodes, mainFile),- );- return cachedLayers;- };-};-export const useLayers = ({host,- project,- mainFile,+ compiledProject,}: {host: PreviewHost | null;- project: CodemodProject;- mainFile: string | null;+ compiledProject: CodemodProject;}): Layer[] => {- const getLayers = useMemo(createLayerCache, []);const tracks = useSyncExternalStore(host?.controller.timeline.subscribe ?? noopSubscribe,() => host?.controller.timeline.getSnapshot() ?? emptyTracks,() => emptyTracks,);- const sourceNodes = useMemo(- () => collectSourceNodes(project, mainFile),- [mainFile, project],- );- const latest = useRef({ sourceNodes, mainFile });- latest.current = { sourceNodes, mainFile };useEffect(() => {if (!host) {return;}- const resolve: CanvasSequenceNodePathResolver = (track) => {- const layers = getLayers(- host.controller.timeline.getSnapshot(),- latest.current.sourceNodes,- latest.current.mainFile,- );- return (- layers.find((layer) => layer.track.sequence.id === track.sequence.id)- ?.nodePathInfo ?? null- );- };- host.setOptions({ resolveSequenceNodePathInfo: resolve });- return () => host.setOptions({ resolveSequenceNodePathInfo: null });- }, [getLayers, host]);+ // Registering node paths republishes the timeline. The Canvas ignores an+ // unchanged mapping, so the resulting update does not loop.+ host.controller.setSequenceNodePaths(+ resolveSequenceNodePaths(tracks, compiledProject),+ );+ }, [compiledProject, host, tracks]);return useMemo(- () => getLayers(tracks, sourceNodes, mainFile),- [getLayers, mainFile, sourceNodes, tracks],+ () => buildLayers(tracks, compiledProject),+ [compiledProject, tracks],);};diff --git a/packages/template-vibe-code/src/editor/model/layers.ts b/packages/template-vibe-code/src/editor/model/layers.tsindex 8a6e929254..8c54de2ba7 100644--- a/packages/template-vibe-code/src/editor/model/layers.ts+++ b/packages/template-vibe-code/src/editor/model/layers.ts@@ -1,248 +1,119 @@import {getCanvasSequenceNodePathInfo,+ getCanvasSequenceSourceLocation,type CanvasSelectionItem,type SequenceNodePathInfo,type TimelineTrackData,} from "@remotion/canvas";import {- getJsxNodeProps,getJsxNodes,type CodemodProject,type JsxNode,type JsxNodeReference,} from "@remotion/codemods";--/**- * A JSX element in the source code that registers a sequence at runtime.- * `name` is the static value of its `name` prop, if any.- */-export type SourceNode = JsxNode & {- name: string | null;- hasNameProp: boolean;-};+import type { SequencePropsSubscriptionKey } from "remotion";export type Layer = {track: TimelineTrackData;- source: SourceNode | null;+ /** The JSX element in the source code that registers this sequence. */+ source: JsxNode | null;nodePathInfo: SequenceNodePathInfo;selectionItem: Extract<CanvasSelectionItem, { type: "sequence" }>;};-// Elements from `remotion` that show up as a track in the timeline.-const layerTags = new Set([- "AbsoluteFill",- "Sequence",- "Series.Sequence",- "TransitionSeries.Sequence",- "Loop",- "Freeze",- "Img",- "Video",- "OffthreadVideo",- "Html5Video",- "Audio",- "Html5Audio",- "Solid",- "Gif",- "AnimatedImage",- "Lottie",- "ThreeCanvas",-]);--export const isLayerTag = (tagName: string) =>- layerTags.has(tagName) || tagName.startsWith("Interactive.");--// Elements register default names like "<AbsoluteFill>" when no `name` is set.-const getDefaultNameTags = (track: TimelineTrackData): string[] => {- const { displayName, type } = track.sequence;- if (type === "video") {- return ["Video", "OffthreadVideo", "Html5Video"];- }-- if (type === "audio") {- return ["Audio", "Html5Audio"];- }-- if (type === "image") {- return ["Img", "Gif", "AnimatedImage"];- }-- if (displayName.startsWith("<") && displayName.endsWith(">")) {- return [displayName.slice(1, -1)];- }-- if (displayName === "") {- return ["Sequence", "Series.Sequence", "TransitionSeries.Sequence"];- }-- return [];-};--const hasCustomName = (track: TimelineTrackData) => {- const { displayName } = track.sequence;- return (- displayName !== "" &&- !(displayName.startsWith("<") && displayName.endsWith(">"))- );-};--export const collectSourceNodes = (+const getJsxNodesSafe = (project: CodemodProject,- mainFile: string | null,-): SourceNode[] => {- const filePaths = Object.keys(project.files)- .filter((filePath) => /\.(tsx|jsx)$/.test(filePath))- .sort((a, b) => {- if (a === mainFile) return -1;- if (b === mainFile) return 1;- return a.localeCompare(b);- });-- const nodes: SourceNode[] = [];- for (const filePath of filePaths) {- let jsxNodes: JsxNode[];- try {- jsxNodes = getJsxNodes({ project, filePath });- } catch {- continue;- }-- for (const node of jsxNodes) {- if (!isLayerTag(node.tagName)) {- continue;- }-- let name: string | null = null;- let hasNameProp = false;- try {- const status = getJsxNodeProps({ project, node, keys: ["name"] }).props- .name;- if (status?.status === "static") {- hasNameProp = status.codeValue !== undefined;- name = typeof status.codeValue === "string" ? status.codeValue : null;- } else if (status) {- hasNameProp = true;- }- } catch {- // Keep the node without a name.- }+ filePath: string,+ cache: Map<string, JsxNode[]>,+): JsxNode[] => {+ const cached = cache.get(filePath);+ if (cached) {+ return cached;+ }- nodes.push({ ...node, name, hasNameProp });- }+ let nodes: JsxNode[] = [];+ try {+ nodes = getJsxNodes({ project, filePath });+ } catch {+ // Unknown or unparsable file: the layer stays without a source.}+ cache.set(filePath, nodes);return nodes;};/**- * Matches the sequences that are mounted in the preview to JSX elements in- * the source code.+ * Maps the sequences that are mounted in the preview to the JSX elements+ * they were compiled from.*- * The Canvas does not know where a sequence was written, so the editor- * matches them heuristically: first by the `name` prop, then by element type- * in source order. Give your layers unique names to make the mapping robust.+ * The browser bundler records the source location of every JSX element and+ * the Canvas exposes it per track. Looking the location up in the compiled+ * files yields the node path that the codemods operate on. The result is+ * keyed by `overrideId`, which sequences rendered from the same element (for+ * example in a `.map()` loop) share.*/-export const mapTracksToSources = (+export const resolveSequenceNodePaths = (tracks: readonly TimelineTrackData[],- nodes: readonly SourceNode[],- mainFile: string | null,-): Map<string, SourceNode | null> => {- const mapping = new Map<string, SourceNode | null>();- const used = new Set<SourceNode>();- // Elements rendered in a loop (e.g. `items.map()`) register several sibling- // sequences for a single JSX node. Remember the last match per parent so- // the siblings can share it.- const lastMatchByParent = new Map<string | null, SourceNode>();-- const orderByFile = (candidates: SourceNode[]) => [- ...candidates.filter((node) => node.filePath === mainFile),- ...candidates.filter((node) => node.filePath !== mainFile),- ];+ compiledProject: CodemodProject,+): Record<string, SequencePropsSubscriptionKey> => {+ const nodePaths: Record<string, SequencePropsSubscriptionKey> = {};+ const cache = new Map<string, JsxNode[]>();for (const track of tracks) {- const { displayName } = track.sequence;- // Siblings of a loop live under parents that map to the same JSX node.- const parentSource = track.sequence.parent- ? mapping.get(track.sequence.parent)- : null;- const parent = parentSource- ? getSourceKey(parentSource)- : track.sequence.parent;- let match: SourceNode | null = null;-- if (hasCustomName(track)) {- const sameName = orderByFile(- nodes.filter((node) => node.name === displayName),- );- match = sameName.find((node) => !used.has(node)) ?? sameName[0] ?? null;+ const overrideId = track.sequence.controls?.overrideId;+ if (!overrideId || overrideId in nodePaths) {+ continue;}- if (!match) {- const tags = getDefaultNameTags(track);- const candidates = orderByFile(- tags.length > 0- ? nodes.filter(- (node) => tags.includes(node.tagName) && node.name === null,- )- : nodes.filter((node) => node.hasNameProp && node.name === null),- );- match = candidates.find((node) => !used.has(node)) ?? null;- if (!match) {- const previous = lastMatchByParent.get(parent);- if (previous && candidates.includes(previous)) {- match = previous;- }- }+ const location = getCanvasSequenceSourceLocation(track);+ if (!location) {+ continue;}- if (match) {- used.add(match);- lastMatchByParent.set(parent, match);+ const candidates = getJsxNodesSafe(+ compiledProject,+ location.fileName,+ cache,+ ).filter((node) => node.location?.line === location.line);+ // Prefer the exact column; several elements on one line are rare.+ const node =+ candidates.find((item) => item.location?.column === location.column) ??+ candidates.at(-1);+ if (!node) {+ continue;}- mapping.set(track.sequence.id, match);+ nodePaths[overrideId] = {+ absolutePath: node.filePath,+ nodePath: node.nodePath,+ sequenceKeys: [],+ effectKeys: [],+ videoConfigValues: track.sequence.controls?.videoConfigValues ?? null,+ };}- return mapping;+ return nodePaths;};+const sameNodePath = (+ a: readonly (string | number)[],+ b: readonly (string | number)[],+) => a.length === b.length && a.every((segment, index) => segment === b[index]);+export const buildLayers = (tracks: readonly TimelineTrackData[],- mapping: Map<string, SourceNode | null>,+ project: CodemodProject,): Layer[] => {- const occurrences = new Map<string, number>();- const totals = new Map<string, number>();- for (const track of tracks) {- const source = mapping.get(track.sequence.id);- if (source) {- const key = getSourceKey(source);- totals.set(key, (totals.get(key) ?? 0) + 1);- }- }+ const cache = new Map<string, JsxNode[]>();return tracks.map((track): Layer => {- const source = mapping.get(track.sequence.id) ?? null;- let nodePathInfo: SequenceNodePathInfo;- if (source) {- const key = getSourceKey(source);- const index = occurrences.get(key) ?? 0;- occurrences.set(key, index + 1);- nodePathInfo = {- sequenceSubscriptionKey: {- absolutePath: source.filePath,- nodePath: source.nodePath,- sequenceKeys: [],- effectKeys: [],- videoConfigValues: null,- },- auxiliaryKeys: [],- index,- numberOfSequencesWithThisNodePath: totals.get(key) ?? 1,- supportsEffects: false,- };- } else {- nodePathInfo = getCanvasSequenceNodePathInfo(track);- }+ const nodePathInfo = getCanvasSequenceNodePathInfo(track);+ const key = track.nodePathInfo?.sequenceSubscriptionKey ?? null;+ const source = key+ ? (getJsxNodesSafe(project, key.absolutePath, cache).find((node) =>+ sameNodePath(node.nodePath, key.nodePath),+ ) ?? null)+ : null;return {track,@@ -253,9 +124,6 @@ export const buildLayers = (});};-export const getSourceKey = (node: JsxNodeReference) =>- `${node.filePath}:${JSON.stringify(node.nodePath)}`;-export const getNodeReference = (item: CanvasSelectionItem,): JsxNodeReference | null => {diff --git a/packages/template-vibe-code/src/editor/model/schemas.ts b/packages/template-vibe-code/src/editor/model/schemas.tsindex f61c82d582..d232a40553 100644--- a/packages/template-vibe-code/src/editor/model/schemas.ts+++ b/packages/template-vibe-code/src/editor/model/schemas.ts@@ -3,11 +3,13 @@ import {type InteractivitySchema,type InteractivitySchemaField,} from "remotion";+import type { Layer } from "./layers";-// The inspector is driven by the same schema fragments that Remotion Studio-// uses. `Interactive.*Schema` are public, so composing them per element type-// gives the editor real knowledge of which props exist, their ranges and-// their default values.+// The inspector is driven by the interactivity schema of the mounted element,+// which the Canvas reports through `track.sequence.controls`. This covers+// components made interactive with `Interactive.withSchema()` as well. The+// schemas composed below from the public `Interactive.*Schema` fragments are+// the fallback for elements that are not mounted, e.g. while hidden.const textContentSchema: InteractivitySchema = {children: {@@ -207,6 +209,14 @@ export const getSchemaForTag = (return null;};+/** The editable props of a layer, as reported by the mounted element. */+export const getLayerSchema = (layer: Layer): InteractivitySchema | null => {+ return (+ layer.track.sequence.controls?.schema ??+ (layer.source ? getSchemaForTag(layer.source.tagName) : null)+ );+};+export type FieldGroup =| "timing"| "content"diff --git a/packages/template-vibe-code/src/editor/state/editor-store.ts b/packages/template-vibe-code/src/editor/state/editor-store.tsindex 817a8e2f4c..1e23873e23 100644--- a/packages/template-vibe-code/src/editor/state/editor-store.ts+++ b/packages/template-vibe-code/src/editor/state/editor-store.ts@@ -52,6 +52,9 @@ export type LayoutSettings = {export type EditorState = {files: ProjectFiles;+ // The files of the last bundle that was applied to the preview. The+ // mounted sequences report source locations from these files.+ appliedFiles: ProjectFiles | null;savedFiles: ProjectFiles;past: ProjectFiles[];future: ProjectFiles[];@@ -93,6 +96,7 @@ export type EditorAction =| { type: "select-composition"; compositionId: string | null }| { type: "set-props-override"; props: Record<string, unknown> | null }| { type: "set-compile"; compile: CompileStatus }+ | { type: "set-applied-files"; files: ProjectFiles }| { type: "set-warnings"; warnings: string[] }| { type: "set-runtime-error"; message: string | null }| { type: "set-playback"; patch: Partial<PlaybackSettings> }@@ -122,6 +126,7 @@ export const createInitialState = ({activeFile: string | null;}): EditorState => ({files,+ appliedFiles: null,savedFiles: files,past: [],future: [],@@ -267,6 +272,8 @@ export const editorReducer = (case "set-compile":return { ...state, compile: action.compile };+ case "set-applied-files":+ return { ...state, appliedFiles: action.files };case "set-warnings":return { ...state, warnings: action.warnings };diff --git a/packages/template-vibe-code/src/preview/bridge.ts b/packages/template-vibe-code/src/preview/bridge.tsindex 55e5dba1e7..2294e95156 100644--- a/packages/template-vibe-code/src/preview/bridge.ts+++ b/packages/template-vibe-code/src/preview/bridge.ts@@ -7,10 +7,7 @@import type { BrowserBundle } from "@remotion/browser-bundler";import type { BrowserComposition } from "@remotion/browser-bundler/runtime";-import type {- CanvasController,- CanvasSequenceNodePathResolver,-} from "@remotion/canvas";+import type { CanvasController } from "@remotion/canvas";import type { PlayerRef } from "@remotion/player";import type {CanRenderMediaOnWebResult,@@ -29,7 +26,6 @@ export type PreviewOptions = {playbackRate: number;inFrame: number | null;outFrame: number | null;- resolveSequenceNodePathInfo: CanvasSequenceNodePathResolver | null;};export type PreviewCompositionSelection = {diff --git a/packages/template-vibe-code/src/preview/runtime.tsx b/packages/template-vibe-code/src/preview/runtime.tsxindex e328c1b81d..bf19fdd75c 100644--- a/packages/template-vibe-code/src/preview/runtime.tsx+++ b/packages/template-vibe-code/src/preview/runtime.tsx@@ -38,7 +38,6 @@ const defaultOptions: PreviewOptions = {playbackRate: 1,inFrame: null,outFrame: null,- resolveSequenceNodePathInfo: null,};const createPreviewStore = () => {@@ -160,9 +159,6 @@ const PreviewApp: React.FC<{ref={setPlayer}controller={controller}showOutlines={options.showOutlines}- resolveSequenceNodePathInfo={- options.resolveSequenceNodePathInfo ?? undefined- }component={composition.component}inputProps={composition.props}compositionWidth={composition.width}