🎥 Make videos programmatically with React
Index Studio source remappings for large compositions
Jonny Burgera54b0bb9d5b4
diff --git a/packages/studio/src/components/Timeline/SequencePropsObserver.tsx b/packages/studio/src/components/Timeline/SequencePropsObserver.tsxindex 7e214f94ec..02da33c7e5 100644--- a/packages/studio/src/components/Timeline/SequencePropsObserver.tsx+++ b/packages/studio/src/components/Timeline/SequencePropsObserver.tsx@@ -88,6 +88,52 @@ export const SequencePropsObserver = () => {remapSelectionNodePaths(mutations);+ // Each edit can remap many siblings. Index paths once before matching+ // them against every mounted override ID.+ const indexedMutations = mutations.map((mutation) =>+ mutation.files.map((file) => {+ const byOldPath = new Map<string, (typeof file.remappings)[number]>();+ const byNewPath = new Map<string, (typeof file.remappings)[number]>();+ const insertedPaths = new Set<string>();+ const updatedPaths = new Set<string>();+ for (const remapping of file.remappings) {+ const oldPath =+ remapping.oldNodePath === null+ ? null+ : JSON.stringify(remapping.oldNodePath);+ const newPath =+ remapping.newNodePath === null+ ? null+ : JSON.stringify(remapping.newNodePath);++ // Preserve the first match when multiple remappings share a path.+ if (oldPath !== null && !byOldPath.has(oldPath)) {+ byOldPath.set(oldPath, remapping);+ }++ if (newPath !== null && !byNewPath.has(newPath)) {+ byNewPath.set(newPath, remapping);+ }++ if (oldPath === null && newPath !== null) {+ insertedPaths.add(newPath);+ }++ if (oldPath !== null && oldPath === newPath) {+ updatedPaths.add(oldPath);+ }+ }++ return {+ absolutePath: file.absolutePath,+ byOldPath,+ byNewPath,+ insertedPaths,+ updatedPaths,+ };+ }),+ );+const statusRemappings: SequencePropsStatusRemapping[] = [];const overrideUpdates: Array<{overrideId: string;@@ -105,8 +151,8 @@ export const SequencePropsObserver = () => {let runtimeNodePathNeedsRefresh = false;const previousNodePathString = JSON.stringify(previousNodePath.nodePath);- for (const mutation of mutations) {- for (const file of mutation.files) {+ for (const files of indexedMutations) {+ for (const file of files) {if (file.absolutePath !== previousNodePath.absolutePath) {continue;}@@ -115,33 +161,22 @@ export const SequencePropsObserver = () => {// Override IDs follow runtime instances, which may be reused when the// same JSX component takes over an old path. A different component remounts,// so move the old mapping with its source node and resubscribe instead.- const runtimeNodePathSource = file.remappings.find(- (item) =>- item.oldNodePath !== null &&- JSON.stringify(item.oldNodePath) === previousNodePathString,+ const runtimeNodePathSource = file.byOldPath.get(+ previousNodePathString,);- const runtimeNodePathDestination = file.remappings.find(- (item) =>- item.newNodePath !== null &&- JSON.stringify(item.newNodePath) === previousNodePathString,+ const runtimeNodePathDestination = file.byNewPath.get(+ previousNodePathString,);const replacementComponentMatches =runtimeNodePathSource?.oldJsxName === undefined ||runtimeNodePathDestination?.newJsxName === undefined ||runtimeNodePathSource.oldJsxName ===runtimeNodePathDestination.newJsxName;- const runtimeNodePathWasInserted = file.remappings.some(- (item) =>- item.oldNodePath === null &&- item.newNodePath !== null &&- JSON.stringify(item.newNodePath) === previousNodePathString,+ const runtimeNodePathWasInserted = file.insertedPaths.has(+ previousNodePathString,);- const runtimeNodePathWasUpdated = file.remappings.some(- (item) =>- item.oldNodePath !== null &&- item.newNodePath !== null &&- JSON.stringify(item.oldNodePath) === previousNodePathString &&- JSON.stringify(item.newNodePath) === previousNodePathString,+ const runtimeNodePathWasUpdated = file.updatedPaths.has(+ previousNodePathString,);if (runtimeNodePathSource) {runtimeNodePathExists = Boolean(@@ -160,11 +195,7 @@ export const SequencePropsObserver = () => {continue;}- const remapping = file.remappings.find(- (item) =>- item.oldNodePath !== null &&- JSON.stringify(item.oldNodePath) === JSON.stringify(nodePath),- );+ const remapping = file.byOldPath.get(JSON.stringify(nodePath));if (!remapping) {continue;}