Skip to content

Ensure duplicate snap events are not registered on the same feature#17054

Merged
ahocevar merged 1 commit into
openlayers:mainfrom
megawac:ensure-duplicate-snap-events-removed
Aug 27, 2025
Merged

Ensure duplicate snap events are not registered on the same feature#17054
ahocevar merged 1 commit into
openlayers:mainfrom
megawac:ensure-duplicate-snap-events-removed

Conversation

@megawac

@megawac megawac commented Aug 27, 2025

Copy link
Copy Markdown
Contributor

Issue Description

If a Snap is watching a collection and a feature is added to the collection which already exists in it, the Snap will register event listeners to the feature twice. Later, if the Snap is removed, via map.removeInteraction(snap), a rogue event listener will still exist which can cause JS errors. The error in my case would cause the entire map stack to crash in addFeature as this.getMap() will be null.

This was a bug in my application but was quite difficult to track down and can lead to memory leaks.

Workaround

This ensures any events registered to a feature are cleaned up if snap attempts to bind to the feature again.

@github-actions

Copy link
Copy Markdown

📦 Preview the website for this branch here: https://deploy-preview-17054--ol-site.netlify.app/.

@megawac megawac force-pushed the ensure-duplicate-snap-events-removed branch from 140a53c to 1e1c628 Compare August 27, 2025 15:39

@ahocevar ahocevar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @megawac

@ahocevar ahocevar merged commit ed117ba into openlayers:main Aug 27, 2025
8 checks passed
@megawac megawac deleted the ensure-duplicate-snap-events-removed branch August 27, 2025 20:26
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.

2 participants