dify icon indicating copy to clipboard operation
dify copied to clipboard

fix(web): re-fetch images on prop change without dropping their blob URLs

Open AlexMultiAgent opened this issue 4 months ago • 3 comments

ImagePreviewer never loads new images when the prop changes while the component stays mounted

web/app/components/datasets/common/image-previewer/index.tsx lines 97-112 — the loading useEffect has an empty dependency array but reads the images prop. So if the previewer instance is reused for a different document or a different set of images, the new images are never fetched. The user can land on a stuck loading state or a 'no image' placeholder while the actual images exist.

A naive fix that simply adds images to the dep array is also broken: the same useEffect returns a cleanup that revokes every cached blob URL and clears the entire cache, so on every change the cleanup would tear down URLs still needed by the new image list.

Steps to reproduce

  1. Open the image previewer on document A.
  2. Without unmounting the previewer, switch to document B.
  3. Observe: document B's images never load, and the cache for document A's URLs is wiped if the effect re-runs.

Expected

When the images prop changes, the previewer fetches the new set of images. Blob URLs of still-present images are reused, not revoked. Cleanup runs on unmount only.

Actual

The loading effect runs only once on mount. New images are not fetched. Any naive dep-array fix would also wipe cached blob URLs on every change, breaking subsequent previews.

Suggested fix

Split into two effects:

  • Loading effect with [images] deps, no cleanup.
  • Unmount-only effect with [] deps that handles isMounted.current and the cache cleanup.

AlexMultiAgent avatar Jul 24 '26 08:07 AlexMultiAgent

Hi! I'd like to work on this issue. I'm currently learning open source contribution and this looks like a great fit. I'll submit a PR soon! 🚀

eslam-ahmed43 avatar Jul 24 '26 08:07 eslam-ahmed43

I'd like to take this one. I re-checked that the defect is still on current main, that no open PR covers it, and prepared the smallest working patch with an offline check. Opening a focused PR from my fork now.

severus0044 avatar Nov 08 '26 09:11 severus0044

Hi @AlexMultiAgent, thanks for opening this issue.

Why this is being closed

The prop-change scenario and expected behavior are useful, but the report does not identify the tested version or commit, deployment, or the UI actions that keep the previewer mounted while changing images. The bug report template asks for version, deployment and reproduction context. This closure does not establish whether the observation is correct.

Next steps

Please add the exact version or commit and deployment, and provide a minimal UI or source-test reproduction with observed and expected results.

Once the context is available, a maintainer can reassess the report.

crazywoola avatar Nov 20 '26 04:11 crazywoola