Skip to content

🎥 Make videos programmatically with React

`@remotion/studio`: Snapshot node path with a ref on location change

Jonny Burgercf01c21bb3f7
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 42dcbb60e6..9cde1d19fe 100644
--- a/packages/studio/src/components/Timeline/use-sequence-props-subscription.ts
+++ b/packages/studio/src/components/Timeline/use-sequence-props-subscription.ts
@@ -31,6 +31,10 @@ export const useSequencePropsSubscription = ({
const {previewServerState: state} = useContext(StudioServerConnectionCtx);
const previousNodePathRef = useRef<SequencePropsSubscriptionKey | null>(null);
+ const nodePathAtResubscribeRef = useRef<SequencePropsSubscriptionKey | null>(
+ null,
+ );
+ const previousLocationKeyRef = useRef<string | null>(null);
const clientId = state.type === 'connected' ? state.clientId : undefined;
const validatedLocation = useMemo(() => {
@@ -53,6 +57,17 @@ export const useSequencePropsSubscription = ({
const locationLine = validatedLocation?.line ?? null;
const locationColumn = validatedLocation?.column ?? null;
+ const locationKey =
+ locationSource !== null && locationLine !== null && locationColumn !== null
+ ? `${locationSource}\0${locationLine}\0${locationColumn}`
+ : null;
+
+ if (locationKey !== previousLocationKeyRef.current) {
+ previousLocationKeyRef.current = locationKey;
+ nodePathAtResubscribeRef.current =
+ overrideIdToNodePathMappings[overrideId] ?? null;
+ }
+
useEffect(() => {
if (
!clientId ||
@@ -64,9 +79,6 @@ export const useSequencePropsSubscription = ({
return;
}
- const nodePathAtResubscribe =
- overrideIdToNodePathMappings[overrideId] ?? null;
-
const {release} = acquireSequencePropsSubscription({
fileName: locationSource,
line: locationLine,
@@ -88,7 +100,7 @@ export const useSequencePropsSubscription = ({
const newNodePath = result.nodePath;
const previousNodePath =
- previousNodePathRef.current ?? nodePathAtResubscribe;
+ previousNodePathRef.current ?? nodePathAtResubscribeRef.current;
if (
previousNodePath &&
@@ -109,10 +121,6 @@ export const useSequencePropsSubscription = ({
return () => {
release();
};
- // overrideIdToNodePathMappings is read only to snapshot this override's node
- // path when location changes. Listing the full map would re-subscribe every
- // sequence whenever any other sequence's node path updates.
- // eslint-disable-next-line react-hooks/exhaustive-deps -- see above
}, [
clientId,
effects,