Skip to content

🎥 Make videos programmatically with React

Cache rotation-mode canvas candidates before layout

JonnyBurger18394700509e
diff --git a/packages/studio/src/components/SelectedOutlineOverlay.tsx b/packages/studio/src/components/SelectedOutlineOverlay.tsx
index 8fd30beef8..9ce93b1840 100644
--- a/packages/studio/src/components/SelectedOutlineOverlay.tsx
+++ b/packages/studio/src/components/SelectedOutlineOverlay.tsx
@@ -912,6 +912,46 @@ const SelectedOutlineOverlayUnmemoized: React.FC<
sequences,
]);
+ const selectedRotationKey = selectedRotationInfo?.sequenceKey ?? null;
+ const getSelectableOutlinesForCanvas = useMemo(() => {
+ if (selectedRotationKey === null) {
+ return getSelectableOutlines;
+ }
+
+ let candidates: SelectableOutlines | null = null;
+ return (timelinePosition: number) => {
+ if (candidates === null) {
+ const outlines = getSelectableOutlines(null);
+ const rotatingSequenceIds = new Set(
+ outlines
+ .filter((target) => target.key === selectedRotationKey)
+ .map((target) => target.sequence.id),
+ );
+ const parentBySequenceId = new Map(
+ sequences.map((sequence) => [sequence.id, sequence.parent]),
+ );
+ // Resolve ancestry on first demand, not on each frame or hover update.
+ candidates = outlines.filter((target) => {
+ let parentId = target.sequence.parent;
+ while (parentId !== null) {
+ if (rotatingSequenceIds.has(parentId)) {
+ return false;
+ }
+
+ parentId = parentBySequenceId.get(parentId) ?? null;
+ }
+
+ return true;
+ });
+ }
+
+ return getCanvasVisibleOutlineTargets({
+ targets: candidates,
+ timelinePosition,
+ });
+ };
+ }, [getSelectableOutlines, selectedRotationKey, sequences]);
+
const calculateOutlineTargetsForCurrentState =
useCallback<CalculateOutlineTargets>(
(options) =>
@@ -1091,7 +1131,7 @@ const SelectedOutlineOverlayUnmemoized: React.FC<
draggingOutline={draggingOutline}
getAllDragTargets={getAllDragTargets}
getLatestOutlineTargetByKey={getLatestOutlineTargetByKey}
- getSelectableOutlines={getSelectableOutlines}
+ getSelectableOutlines={getSelectableOutlinesForCanvas}
hoveredTimelineNodePathKey={hoveredTimelineNodePathKey}
measureAllOutlines={measureAllOutlines}
onDraggingChange={onDraggingChange}
diff --git a/packages/studio/src/components/SelectedOutlineRenderer.tsx b/packages/studio/src/components/SelectedOutlineRenderer.tsx
index 025fabf4e1..8853900738 100644
--- a/packages/studio/src/components/SelectedOutlineRenderer.tsx
+++ b/packages/studio/src/components/SelectedOutlineRenderer.tsx
@@ -114,33 +114,6 @@ const SelectedOutlineRendererUnmemoized: React.FC<{
[getContextMenuOpenByKey],
);
const hoverController = useContext(TimelineSequenceHoverContext);
- const selectableOutlineTargets = useMemo(() => {
- const rotatingSequenceIds = new Set(
- outlineTargets
- .filter((target) => target.selectedForRotation)
- .map((target) => target.sequence.id),
- );
- if (rotatingSequenceIds.size === 0) {
- return outlineTargets;
- }
-
- const parentBySequenceId = new Map(
- sequences.map((sequence) => [sequence.id, sequence.parent]),
- );
- // Descendants must not intercept hover or dragging until rotation mode ends.
- return outlineTargets.filter((target) => {
- let parentId = target.sequence.parent;
- while (parentId !== null) {
- if (rotatingSequenceIds.has(parentId)) {
- return false;
- }
-
- parentId = parentBySequenceId.get(parentId) ?? null;
- }
-
- return true;
- });
- }, [outlineTargets, sequences]);
const {
outlinesForRendering,
outlinesByKey,
@@ -148,7 +121,7 @@ const SelectedOutlineRendererUnmemoized: React.FC<{
hoveredNodePathKey,
} = useCanvasOutlines({
contentRoot: Internals.portalNode(),
- targets: selectableOutlineTargets,
+ targets: outlineTargets,
sequences,
hoverController,
freezeOrder: dragging,