🎥 Make videos programmatically with React
Keep source props aligned during optimistic sequence deletion
JonnyBurgerc596d1a37390
diff --git a/packages/studio/src/components/Timeline/SequencePropsObserver.tsx b/packages/studio/src/components/Timeline/SequencePropsObserver.tsxindex f11e2a9052..bd52076f15 100644--- a/packages/studio/src/components/Timeline/SequencePropsObserver.tsx+++ b/packages/studio/src/components/Timeline/SequencePropsObserver.tsx@@ -106,8 +106,8 @@ export const SequencePropsObserver = () => {continue;}- // Prop statuses follow source nodes to their new paths. Override IDs- // normally follow React's runtime instances, which may be reused when the+ // Source nodes and React's runtime instances can move independently.+ // 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(@@ -179,12 +179,18 @@ export const SequencePropsObserver = () => {}const nextNodePath = wasDeleted ? null : {...previousNodePath, nodePath};+ const nodePathChanged =+ JSON.stringify(nodePath) !== previousNodePathString;const previousStatusKey =Internals.makeSequencePropsSubscriptionKey(previousNodePath);statusRemappings.push({previousNodePath,nodePath: nextNodePath,- result: propStatusesRef.current[previousStatusKey] ?? null,+ // A reused runtime instance still renders the old JSX until Refresh.+ // Let it use its JSX values instead of a shifted sibling's source props.+ result: nodePathChanged+ ? null+ : (propStatusesRef.current[previousStatusKey] ?? null),});overrideUpdates.push({@@ -193,7 +199,9 @@ export const SequencePropsObserver = () => {});if (!wasDeleted &&- (!runtimeNodePathExists || runtimeNodePathNeedsRefresh)+ (nodePathChanged ||+ !runtimeNodePathExists ||+ runtimeNodePathNeedsRefresh)) {overrideIdsToRefresh.add(overrideId);}diff --git a/packages/studio/src/components/Timeline/sequence-props-subscription-store.ts b/packages/studio/src/components/Timeline/sequence-props-subscription-store.tsindex e168a29664..909d071b03 100644--- a/packages/studio/src/components/Timeline/sequence-props-subscription-store.ts+++ b/packages/studio/src/components/Timeline/sequence-props-subscription-store.ts@@ -163,12 +163,18 @@ export const acquireSequencePropsSubscription = ({entry.refCount++;const acquired = entry;+ let released = false;- acquired.promise.then(applyEach).catch(() => {- // Error already logged by the first acquirer.- });+ acquired.promise+ .then((result) => {+ if (!released) {+ applyEach(result);+ }+ })+ .catch(() => {+ // Error already logged by the first acquirer.+ });- let released = false;return {release: () => {if (released) {diff --git a/packages/studio/src/components/Timeline/use-sequence-props-subscription.ts b/packages/studio/src/components/Timeline/use-sequence-props-subscription.tsindex 86250c2264..7f987336a4 100644--- a/packages/studio/src/components/Timeline/use-sequence-props-subscription.ts+++ b/packages/studio/src/components/Timeline/use-sequence-props-subscription.ts@@ -47,6 +47,7 @@ export const useSequencePropsSubscription = ({);const {previewServerState: state} = useContext(StudioServerConnectionCtx);+ const pendingDeletions = Internals.usePendingSequenceDeletions();const [refreshToken, setRefreshToken] = useState(0);const previousNodePathRef = useRef<SequencePropsSubscriptionKey | null>(null);const overrideIdToNodePathMappingsRef = useRef(overrideIdToNodePathMappings);@@ -85,7 +86,10 @@ export const useSequencePropsSubscription = ({}, [overrideId]);useEffect(() => {+ // Optimistic deletion can remount siblings with stacks from the old source.+ // Wait for HMR before resolving those locations against the updated file.if (+ pendingDeletions.size > 0 ||!clientId ||!locationSource ||!shouldSubscribeToSourceFile(locationSource) ||@@ -162,6 +166,7 @@ export const useSequencePropsSubscription = ({migrateExpandedTracksForSubscriptionKey,overrideId,preferMappedNodePath,+ pendingDeletions,refreshToken,schema,setPropStatuses,