🎥 Make videos programmatically with React
Preserve inspector continuity while waiting to refresh subscriptions
JonnyBurger93ff013a7283
diff --git a/packages/studio/src/components/Timeline/SubscribeToNodePaths.tsx b/packages/studio/src/components/Timeline/SubscribeToNodePaths.tsxindex c600ead67c..0420fc120c 100644--- a/packages/studio/src/components/Timeline/SubscribeToNodePaths.tsx+++ b/packages/studio/src/components/Timeline/SubscribeToNodePaths.tsx@@ -15,7 +15,7 @@ export const SubscribeToNodePaths: FC<{readonly getStack: () => string | null;readonly effects: readonly EffectDefinition<unknown>[];}> = ({overrideId, componentIdentity, schema, getStack, effects}) => {- const {resolvedLocation, stack, preferMappedNodePath} =+ const {resolvedLocation, stack, preferMappedNodePath, stackIsResolved} =useResolveStackAndReactToChange(getStack, overrideId);const effectSubscriptions = useMemo<InteractivitySchema[]>(() => {@@ -31,7 +31,9 @@ export const SubscribeToNodePaths: FC<{componentIdentity,schema,effects: effectSubscriptions,- originalLocation: resolvedLocation,+ // The inspector can retain its old location during refresh, but subscribing+ // with it could target a different JSX node in the updated source.+ originalLocation: stackIsResolved ? resolvedLocation : null,preferMappedNodePath,stack,});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.tsindex b3949ec0d4..47b4a6a96f 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@@ -35,11 +35,19 @@ export const useResolveStackAndReactToChange = (preferMappedNodePath: true,}));const resolvedLocationFromStack = useResolvedStack(stackState.stack);- // A new stack must be resolved before subscribing. Reusing the previous- // location can subscribe to a different JSX node in the updated source.- const resolvedLocation = hasResolvedStack(stackState.stack)+ const stackIsResolved = hasResolvedStack(stackState.stack);+ const lastResolvedLocation = useRef(resolvedLocationFromStack);+ if (stackIsResolved) {+ lastResolvedLocation.current = resolvedLocationFromStack;+ }++ // Keep the inspector mounted while resolving the refreshed stack. Source+ // subscriptions must wait for stackIsResolved before using this location.+ const resolvedLocation = stackIsResolved? resolvedLocationFromStack- : null;+ : stackState.preferMappedNodePath+ ? null+ : lastResolvedLocation.current;const resolvedLocationRef = useRef(resolvedLocation);resolvedLocationRef.current = resolvedLocation;const getStackRef = useRef(getStack);@@ -134,6 +142,7 @@ export const useResolveStackAndReactToChange = (return {preferMappedNodePath: stackState.preferMappedNodePath,resolvedLocation,+ stackIsResolved,stack: stackState.stack,};};