Skip to content

Fix: Preserve reference image panel state and selection on recall#9010

Open
ufuksarp wants to merge 8 commits intoinvoke-ai:mainfrom
ufuksarp:preserve-ref-panel-state-on-recall
Open

Fix: Preserve reference image panel state and selection on recall#9010
ufuksarp wants to merge 8 commits intoinvoke-ai:mainfrom
ufuksarp:preserve-ref-panel-state-on-recall

Conversation

@ufuksarp
Copy link
Copy Markdown
Contributor

@ufuksarp ufuksarp commented Apr 2, 2026

Summary

Preserves reference image panel state and which reference image is selected when metadata recall replaces the reference list.

Note: This is my first PR for Invoke. I am not an experienced developer and I used Cursor mainly for this. Feedback and corrections are very welcome.

Related Issues / Discussions

Closes #8982

QA Instructions

  • Recall all on a gallery image that has several reference images in metadata.
  • Open the reference image panel and select a reference image that is not the first in the panel.
  • Pick a different gallery image whose metadata includes that same reference image, and recall all again.
  • Expect the panel to still be open and the same reference image to stay selected.
  • Repeat with the reference panel closed before recall, expect it to stay closed afterward.

Merge Plan

Only one file changes (refImagesSlice.ts). Nothing about this should complicate merging on its own.

Checklist

  • The PR has a short but descriptive title, suitable for a changelog
  • Tests added / updated (if applicable)
  • ❗Changes to a redux slice have a corresponding migration (not needed here)
  • Documentation added / updated (if applicable)
  • Updated What's New copy (if doing a release after this PR)

@github-actions github-actions bot added the frontend PRs that change frontend files label Apr 2, 2026
@Pfannkuchensack
Copy link
Copy Markdown
Collaborator

Nice fix — the priority order (ID match → fingerprint match → first entity fallback) is the right call, and it correctly handles the config variants that don't have a model field (flux2_reference_image, qwen_image_reference_image). A few small notes:

1. Unreachable fallback in the fingerprint key

const imageName = config.image?.original.image.image_name ?? config.image?.crop?.image.image_name ?? '';

Per the zCroppableImageWithDims schema in types.ts, original.image is not optional — whenever config.image is set, original.image.image_name is guaranteed to be a string. The crop?.image.image_name branch is therefore unreachable. Not a bug, just dead code. I'd simplify to:

const imageName = config.image?.original.image.image_name ?? '';

2. Edge case: panel open with no prior selection

If wasPanelOpen is true but previousSelectedId is null, the code falls through to state.selectedEntityId = firstEntity.id, i.e. it auto-selects the first entity. Looking at the other reducers (refImageAdded, refImageDeleted, refImageSelected), the invariant "panel open ⇒ a selection exists" appears to hold in practice, so this branch should be unreachable. Worth either a short comment explaining the invariant, or an explicit guard so the intent is obvious to future readers.

3. Fingerprint collision for empty configs

Two reference images of the same type with no model and no image produce identical fingerprints (e.g. "ip_adapter\0\0"). Very unlikely in a recall scenario, and the worst case is just selecting the "wrong" one of two interchangeable empties — so probably acceptable, but worth being aware of.

Simplify image-name fingerprint fallback, add an explicit guard for open-panel with null selection, and document the acceptable empty-config collision tradeoff.

Made-with: Cursor
@ufuksarp
Copy link
Copy Markdown
Contributor Author

ufuksarp commented Apr 20, 2026

Thanks for the feedback.

3. Fingerprint collision for empty configs

Two reference images of the same type with no model and no image produce identical fingerprints (e.g. "ip_adapter\0\0"). Very unlikely in a recall scenario, and the worst case is just selecting the "wrong" one of two interchangeable empties — so probably acceptable, but worth being aware of.

Yeah, I was aware of this. As you said, it’s very unlikely and the worst case is selecting the wrong one of the two, so I didn’t think it justified extra complexity and left a comment for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

frontend PRs that change frontend files v6.13.x

Projects

Status: 6.13.x Theme: MODELS

Development

Successfully merging this pull request may close these issues.

[enhancement]: Preserve reference panel's expanded/collapsed state on recall

3 participants