Skip to content

fix(image): unregisterPreviewUrl never removes an entry from the map - #8171

Open
MILLERMARRU wants to merge 1 commit into
tusen-ai:mainfrom
MILLERMARRU:fix/image-group-unregister-guard
Open

fix(image): unregisterPreviewUrl never removes an entry from the map#8171
MILLERMARRU wants to merge 1 commit into
tusen-ai:mainfrom
MILLERMARRU:fix/image-group-unregister-guard

Conversation

@MILLERMARRU

Copy link
Copy Markdown

Summary

n-image-group's unregisterPreviewUrl had an inverted guard, so it never actually removed an entry from registeredImageUrlMap on unmount.

return function unregisterPreviewUrl() {
  if (!registeredImageUrlMap.value.has(sid)) {
    registeredImageUrlMap.value.delete(sid)
  }
}

Map.prototype.delete() is a no-op when the key is already absent, so this only calls delete() in exactly the case where it does nothing (key already gone), and skips it in the normal unmount case where the key is actually present. So any n-image rendered inside an n-image-group leaves its URL registered in registeredImageUrlMap forever, even after the component unmounts, growing the map with stale entries for images that no longer exist in the DOM.

Fixes #8170

Fix

One-line inversion of the condition:

return function unregisterPreviewUrl() {
  if (registeredImageUrlMap.value.has(sid)) {
    registeredImageUrlMap.value.delete(sid)
  }
}

Scope

This is separate from #8158/#8168 (the registerImageUrl re-registration guard using the wrong key), which is already being fixed in that other PR. This one only touches the unregister path in the same function.

I didn't add a new unit test since registeredImageUrlMap isn't exposed on the component's public instance for a black-box assertion, and imageId is a module-level uuid++ counter (never reused across mounts), so there's no externally-observable symptom to assert on without reaching into internals. Happy to add one if there's a preferred pattern for asserting on this kind of internal state in this codebase.

Map.prototype.delete() is a no-op on a missing key, so guarding the
delete call with `!has(sid)` only fires in exactly the case where it
does nothing, and skips it whenever the key is actually present. An
n-image inside an n-image-group never actually gets removed from
registeredImageUrlMap on unmount.

Fixes tusen-ai#8170
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

n-image-group: unregisterPreviewUrl never removes an entry, inverted has()/delete() guard

1 participant