Skip to content

🎥 Make videos programmatically with React

restore expanded state

JonnyBurger135cf7331c22
diff --git a/packages/studio/src/components/Timeline/TimelineListItem.tsx b/packages/studio/src/components/Timeline/TimelineListItem.tsx
index 546acadcc2..6901983443 100644
--- a/packages/studio/src/components/Timeline/TimelineListItem.tsx
+++ b/packages/studio/src/components/Timeline/TimelineListItem.tsx
@@ -25,8 +25,8 @@ import {useResolvedStack} from './use-resolved-stack';
export const INDENT = 10;
-const useSubscribedNodePath = (sequence: TSequence): NodePathsState | null => {
- const {overrideIdToNodePathMappings: subscriptionStates} = useContext(
+const useNodePath = (sequence: TSequence): NodePathsState | null => {
+ const {overrideIdToNodePathMappings} = useContext(
Internals.OverrideIdsToNodePathsGettersContext,
);
const overrideId = sequence.controls?.overrideId ?? null;
@@ -34,7 +34,7 @@ const useSubscribedNodePath = (sequence: TSequence): NodePathsState | null => {
return null;
}
- return subscriptionStates[overrideId] ?? null;
+ return overrideIdToNodePathMappings[overrideId] ?? null;
};
export const TimelineListItem: React.FC<{
@@ -54,7 +54,7 @@ export const TimelineListItem: React.FC<{
const {expandedTracks, toggleTrack} = useContext(ExpandedTracksContext);
const originalLocation = useResolvedStack(sequence.stack ?? null);
- const nodePathState = useSubscribedNodePath(sequence);
+ const nodePathState = useNodePath(sequence);
const validatedLocation = useMemo(() => {
if (
diff --git a/packages/studio/src/components/Timeline/sequence-props-subscription-store.ts b/packages/studio/src/components/Timeline/sequence-props-subscription-store.ts
index 49f571af42..7b7c14508a 100644
--- a/packages/studio/src/components/Timeline/sequence-props-subscription-store.ts
+++ b/packages/studio/src/components/Timeline/sequence-props-subscription-store.ts
@@ -18,7 +18,7 @@ type Entry = {
promise: Promise<SubscribeResult>;
fileName: string;
clientId: string;
- apply: ApplyResult | null;
+ applyOnce: ApplyResult | null;
};
const entries = new Map<Key, Entry>();
@@ -29,14 +29,16 @@ export const acquireSequencePropsSubscription = ({
column,
schema,
clientId,
- apply,
+ applyOnce,
+ applyEach,
}: {
fileName: string;
line: number;
column: number;
schema: SequenceSchema;
clientId: string;
- apply: ApplyResult;
+ applyOnce: ApplyResult;
+ applyEach: ApplyResult;
}): {release: () => void} => {
const key = makeKey(fileName, line, column);
let entry = entries.get(key);
@@ -54,7 +56,7 @@ export const acquireSequencePropsSubscription = ({
promise,
fileName,
clientId,
- apply,
+ applyOnce,
};
entries.set(key, created);
entry = created;
@@ -62,12 +64,12 @@ export const acquireSequencePropsSubscription = ({
promise
.then((result) => {
const current = entries.get(key);
- if (current !== created || !current.apply) {
+ if (current !== created || !current.applyOnce) {
return;
}
- const cb = current.apply;
- current.apply = null;
+ const cb = current.applyOnce;
+ current.applyOnce = null;
cb(result);
})
.catch((err) => {
@@ -76,7 +78,7 @@ export const acquireSequencePropsSubscription = ({
return;
}
- current.apply = null;
+ current.applyOnce = null;
Internals.Log.error(err);
});
}
@@ -84,6 +86,10 @@ export const acquireSequencePropsSubscription = ({
entry.refCount++;
const acquired = entry;
+ acquired.promise.then(applyEach).catch(() => {
+ // Error already logged by the first acquirer.
+ });
+
let released = false;
return {
release: () => {
diff --git a/packages/studio/src/components/Timeline/use-sequence-props-subscription.ts b/packages/studio/src/components/Timeline/use-sequence-props-subscription.ts
index 5e20d49610..59f48ca1c6 100644
--- a/packages/studio/src/components/Timeline/use-sequence-props-subscription.ts
+++ b/packages/studio/src/components/Timeline/use-sequence-props-subscription.ts
@@ -60,7 +60,14 @@ export const useSequencePropsSubscription = (
column: locationColumn,
schema,
clientId,
- apply: (result) => {
+ applyOnce: (result) => {
+ if (!result.canUpdate) {
+ return;
+ }
+
+ setCodeValues(result.nodePath, result.props);
+ },
+ applyEach: (result) => {
if (!result.canUpdate) {
return;
}
@@ -69,7 +76,6 @@ export const useSequencePropsSubscription = (
nodePath: result.nodePath,
jsxInMapCallback: result.jsxInMapCallback,
});
- setCodeValues(result.nodePath, result.props);
},
});