Skip to content

fix(snap): disconnect element observers when unsubscribing - #566

Open
hakarrr wants to merge 2 commits into
darkroomengineering:mainfrom
hakarrr:fix/snap-unsubscribe-observers
Open

hakarrr wants to merge 2 commits into
darkroomengineering:mainfrom
hakarrr:fix/snap-unsubscribe-observers

Conversation

@hakarrr

@hakarrr hakarrr commented Oct 27, 2026

Copy link
Copy Markdown

What & why

The unsubscribe callback returned by addElement() deletes the SnapElement from the map without calling its destroy() method. Its body and element ResizeObservers remain connected. Calling Snap.destroy() later does not clean them up either, because the removed element is no longer in the map. The same happens through addElements().

Destroy the element before deleting its map entry. The optional lookup makes repeat unsubscribe safe, and the existing deletion return value is preserved. Other registered elements stay active.

Found during lifecycle testing of the snap plugin; there is no separate issue. This is independent of the horizontal alignment fix in #565.

How to verify

bun test packages/snap/tests/unsubscribe.test.js
bun run build
bunx biome check packages/snap/src/snap.ts packages/snap/tests/unsubscribe.test.js

The three regressions cover single unsubscribe followed by destroy, group unsubscribe while another element remains registered, and repeated unsubscribe. All three fail against the base and pass with this change. Build and the focused Biome check pass.

Also checked the built browser bundle in Chromium using real ResizeObservers (subclassed only to record disconnect() calls), a real DOM element, and a minimal Lenis event stub. After remove(); snap.destroy(), both observers remain connected on the base and both are disconnected with the fix. No dependencies added.

Checklist

  • PR is focused on a single logical change
  • Linked the related issue (or explained why there isn't one)
  • Lint/format/tests pass locally (focused commands above)
  • Updated docs/types where relevant (no API change)

hakarrr and others added 2 commits October 27, 2026 13:01
Co-authored-by: generaltony007 <144252170+GeneralTony007@users.noreply.github.com>
Co-authored-by: generaltony007 <144252170+GeneralTony007@users.noreply.github.com>
@hakarrr
hakarrr requested a review from a team as a code owner October 27, 2026 07:34
@hakarrr
hakarrr requested review from Mekwek and vanvasten October 27, 2026 07:34
@vercel

vercel Bot commented Oct 27, 2026

Copy link
Copy Markdown

@hakarrr is attempting to deploy a commit to the Darkroom Team on Vercel.

A member of the Team first needs to authorize it.

@Mekwek
Mekwek removed their request for review November 7, 2026 04:00

This branch has not been deployed

No deployments
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.

1 participant