Skip to content

🎥 Make videos programmatically with React

only listen when match

Jonny Burger3c27b45e4259
diff --git a/packages/studio/src/components/Timeline/use-resolved-stack-react-to-change.ts b/packages/studio/src/components/Timeline/use-resolved-stack-react-to-change.ts
index a6096cdd3a..21bb982b29 100644
--- a/packages/studio/src/components/Timeline/use-resolved-stack-react-to-change.ts
+++ b/packages/studio/src/components/Timeline/use-resolved-stack-react-to-change.ts
@@ -1,20 +1,36 @@
import type {EventSourceEvent} from '@remotion/studio-shared';
-import {useContext} from 'react';
-import {useState} from 'react';
-import {useEffect} from 'react';
+import {useContext, useEffect, useRef, useState} from 'react';
+import type {ResolvedStackLocation} from 'remotion';
import {StudioServerConnectionCtx} from '../../helpers/client-id';
import {useResolvedStack} from './use-resolved-stack';
// This case: https://github.com/remotion-dev/remotion/issues/7393
// A code change has been made and we cannot re-calculate the stack right away.
// In that case, we wait for fast refresh, wait for the new stack trace, triggering a new event.
-// TODO: Not all stacks are changing for every sequence, we shall not poll immediately
+
+const matchesLostNodePathEvent = (
+ event: Extract<EventSourceEvent, {type: 'lost-node-path'}>,
+ location: ResolvedStackLocation | null,
+): boolean => {
+ if (!location?.source || !location.line) {
+ return false;
+ }
+
+ return (
+ event.fileName === location.source &&
+ event.line === location.line &&
+ event.column === (location.column ?? 0)
+ );
+};
export const useResolveStackAndReactToChange = (
getStack: () => string | null,
) => {
const {subscribeToEvent} = useContext(StudioServerConnectionCtx);
const [stack, setStack] = useState<string | null>(() => getStack());
+ const resolvedLocation = useResolvedStack(stack);
+ const resolvedLocationRef = useRef(resolvedLocation);
+ resolvedLocationRef.current = resolvedLocation;
useEffect(() => {
let interval: Timer | null = null;
@@ -24,6 +40,10 @@ export const useResolveStackAndReactToChange = (
return;
}
+ if (!matchesLostNodePathEvent(event, resolvedLocationRef.current)) {
+ return;
+ }
+
const initialStack = getStack();
if (interval !== null) {
@@ -53,5 +73,5 @@ export const useResolveStackAndReactToChange = (
};
}, [subscribeToEvent, getStack]);
- return useResolvedStack(stack);
+ return resolvedLocation;
};