Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

fix(webv2): disable reorder arrows the anchor pin would undo, and stabilise setNumFrames

Lincoln Steina32181461f3b
diff --git a/invokeai/frontend/webv2/src/features/video/ui/VideoReferenceListField.tsx b/invokeai/frontend/webv2/src/features/video/ui/VideoReferenceListField.tsx
index cf5d7815d7..cbf6de925e 100644
--- a/invokeai/frontend/webv2/src/features/video/ui/VideoReferenceListField.tsx
+++ b/invokeai/frontend/webv2/src/features/video/ui/VideoReferenceListField.tsx
@@ -67,8 +67,8 @@ const ReferenceCard = memo(function ReferenceCard({
collections,
disabled,
index,
- isFirst,
- isLast,
+ canMoveDown,
+ canMoveUp,
onMove,
onRemove,
onUpdate,
@@ -77,8 +77,8 @@ const ReferenceCard = memo(function ReferenceCard({
collections: ReferenceCollections;
disabled: boolean;
index: number;
- isFirst: boolean;
- isLast: boolean;
+ canMoveDown: boolean;
+ canMoveUp: boolean;
onMove: (index: number, direction: -1 | 1) => void;
onRemove: (index: number) => void;
onUpdate: (index: number, reference: VideoReferenceItem) => void;
@@ -189,7 +189,7 @@ const ReferenceCard = memo(function ReferenceCard({
<Stack gap="0">
<IconButton
aria-label={t('widgets.video.moveReferenceUp')}
- disabled={disabled || isFirst}
+ disabled={disabled || !canMoveUp}
size="2xs"
variant="ghost"
onClick={handleMoveUp}
@@ -198,7 +198,7 @@ const ReferenceCard = memo(function ReferenceCard({
</IconButton>
<IconButton
aria-label={t('widgets.video.moveReferenceDown')}
- disabled={disabled || isLast}
+ disabled={disabled || !canMoveDown}
size="2xs"
variant="ghost"
onClick={handleMoveDown}
@@ -246,6 +246,12 @@ export const VideoReferenceListField = memo(function VideoReferenceListField({
const [isLoading, setIsLoading] = useState(false);
const [errorMessage, setErrorMessage] = useState<string | null>(null);
+ // The continuity anchor is pinned last, so any move that would displace it is
+ // reverted the moment it is written -- the button fired a patch and the list
+ // came back unchanged. Present those as disabled rather than inert.
+ const anchorIndex = references.findIndex(
+ (reference) => reference.kind === 'video' && reference.fromSourceVideo === true
+ );
const videoCount = references.filter((reference) => reference.kind === 'video').length;
const imageCount = references.length - videoCount;
const canAddVideo = videoCount < maxVideos;
@@ -471,8 +477,8 @@ export const VideoReferenceListField = memo(function VideoReferenceListField({
collections={collections}
disabled={isInert}
index={index}
- isFirst={index === 0}
- isLast={index === references.length - 1}
+ canMoveDown={index < references.length - 1 && index + 1 !== anchorIndex}
+ canMoveUp={index > 0 && index !== anchorIndex}
reference={reference}
onMove={moveReference}
onRemove={removeReference}
diff --git a/invokeai/frontend/webv2/src/features/video/ui/VideoWidgetView.tsx b/invokeai/frontend/webv2/src/features/video/ui/VideoWidgetView.tsx
index 56c8a8298d..e9342de410 100644
--- a/invokeai/frontend/webv2/src/features/video/ui/VideoWidgetView.tsx
+++ b/invokeai/frontend/webv2/src/features/video/ui/VideoWidgetView.tsx
@@ -151,6 +151,22 @@ export const VideoWidgetView = () => {
);
const patch = useCallback((next: Partial<VideoWidgetValues>) => patchValues(next), [patchValues]);
+
+ // Always the newest normalized list. The reference field's add handlers
+ // `await` a gallery resolve before writing, and the Initial Video field and
+ // the Frames slider write references too — so an updater that resolved
+ // against a captured array would clobber whichever of those landed during
+ // the await, silently deleting the anchor or restoring a window the frame
+ // count had already re-derived.
+ // Synced in an effect rather than during render: this file's react-compiler
+ // rule forbids touching a ref while rendering, and a gallery resolve lands
+ // whole frames later, long after the commit.
+ const referencesRef = useRef(values.references);
+
+ useEffect(() => {
+ referencesRef.current = values.references;
+ }, [values.references]);
+
// Chakra's `Field.Root` hands its single `ids.control` to EVERY control
// inside it, and this Field holds three. Without an id of its own the
// switch's hidden input collides with the seed NumberInput, so the
@@ -271,10 +287,14 @@ export const VideoWidgetView = () => {
(numFrames: number) =>
patch(
referenceExtend
- ? { numFrames, references: applyReferenceExtendNumFrames(values.references, numFrames) }
+ ? { numFrames, references: applyReferenceExtendNumFrames(referencesRef.current, numFrames) }
: { numFrames }
),
- [patch, referenceExtend, values.references]
+ // Reads the list through the ref so the Frames control keeps a stable
+ // prop identity: depending on `values.references` re-created this on every
+ // panel patch, re-rendering the slider against the file's stable-identity
+ // contract. Safe because the re-derive is idempotent in `numFrames`.
+ [patch, referenceExtend]
);
const setSourceVideo = useCallback(
(sourceVideo: VideoSourceClip | null) => {
@@ -303,21 +323,6 @@ export const VideoWidgetView = () => {
},
[maxVideoReferences, patch, referenceExtend, t, values.numFrames, values.references]
);
- // Always the newest normalized list. The reference field's add handlers
- // `await` a gallery resolve before writing, and the Initial Video field and
- // the Frames slider write references too — so an updater that resolved
- // against a captured array would clobber whichever of those landed during
- // the await, silently deleting the anchor or restoring a window the frame
- // count had already re-derived.
- // Synced in an effect rather than during render: this file's react-compiler
- // rule forbids touching a ref while rendering, and a gallery resolve lands
- // whole frames later, long after the commit.
- const referencesRef = useRef(values.references);
-
- useEffect(() => {
- referencesRef.current = values.references;
- }, [values.references]);
-
// The single choke point for every list edit the reference field makes — add,
// remove, retrim, reorder — so pinning the continuity anchor here covers all
// of them. Request order is rotary order and the generation continues from