Skip to content

🎥 Make videos programmatically with React

`@remotion/studio-server`: Avoid scanning JSX siblings during source-path lookups

Jonny Burger8e4673a09e61
diff --git a/packages/codemods/src/sequence-props/import-agnostic-node-path.ts b/packages/codemods/src/sequence-props/import-agnostic-node-path.ts
index 5200e7dab4..f5cd6df954 100644
--- a/packages/codemods/src/sequence-props/import-agnostic-node-path.ts
+++ b/packages/codemods/src/sequence-props/import-agnostic-node-path.ts
@@ -230,8 +230,17 @@ const transformNodePathIndices = ({
continue;
}
- const mappedIndex =
- direction === 'to-agnostic'
+ // Only statement lists can contain imports, frame hooks, or font loaders.
+ // JSX children and other arrays keep their original indices.
+ const canContainIgnoredNodes =
+ arrayContext.property === 'body' &&
+ (arrayContext.parent.type === 'Program' ||
+ arrayContext.parent.type === 'BlockStatement');
+ const mappedIndex = !canContainIgnoredNodes
+ ? Number.isInteger(segment) && segment >= 0 && segment < current.length
+ ? segment + 0 // Match the scanned index when the input is -0.
+ : null
+ : direction === 'to-agnostic'
? getAgnosticIndex({
items: current as Node[],
actualIndex: segment,
diff --git a/packages/studio-server/src/helpers/import-agnostic-node-path.ts b/packages/studio-server/src/helpers/import-agnostic-node-path.ts
index 5200e7dab4..f5cd6df954 100644
--- a/packages/studio-server/src/helpers/import-agnostic-node-path.ts
+++ b/packages/studio-server/src/helpers/import-agnostic-node-path.ts
@@ -230,8 +230,17 @@ const transformNodePathIndices = ({
continue;
}
- const mappedIndex =
- direction === 'to-agnostic'
+ // Only statement lists can contain imports, frame hooks, or font loaders.
+ // JSX children and other arrays keep their original indices.
+ const canContainIgnoredNodes =
+ arrayContext.property === 'body' &&
+ (arrayContext.parent.type === 'Program' ||
+ arrayContext.parent.type === 'BlockStatement');
+ const mappedIndex = !canContainIgnoredNodes
+ ? Number.isInteger(segment) && segment >= 0 && segment < current.length
+ ? segment + 0 // Match the scanned index when the input is -0.
+ : null
+ : direction === 'to-agnostic'
? getAgnosticIndex({
items: current as Node[],
actualIndex: segment,