feat: widen element types to Element and accept undefined refs#156
Merged
Conversation
- Observe any Element (SVG included), matching the native API; root now accepts Element | Document | null as the platform does. - Accept undefined alongside null for element/elements and in the Multiple map key types: bind:this types as `T | undefined` in Svelte 5, so every consumer hit this mismatch. Runtime guards normalized to treat null/undefined uniformly. Type-level change only for existing HTMLElement users — no runtime behavior change for previously-valid code.
…-review-v4 # Conflicts: # tests/unit/IntersectionObserver.test.ts
render
Bot
temporarily deployed
to
metonym/pasted-text-review-v4 - svelte-intersection-observer PR #156
July 5, 2026 20:28
Destroyed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Widens the public element types across every primitive: the intersect action, intersectAttachment, createIntersectionGroup, createIntersectionObserver, and both IntersectionObserver and MultipleIntersectionObserver components. HTMLElement becomes Element (so SVG elements and other non-HTML elements can be observed, matching what the native IntersectionObserver API actually accepts), and root now accepts Element | Document | null. element/elements and the Multiple map key types also accept undefined alongside null, since bind:this resolves to T | undefined in Svelte 5 runes mode and every consumer was already hitting this mismatch.
The runtime IntersectionObserver.svelte effect now normalizes element to null once at the top so a bind:this ref resolving to undefined doesn't produce a spurious observe/unobserve transition against the previous target. MultipleIntersectionObserver.svelte's filters already used truthiness checks, so no runtime change was needed there. This is a type-level widening only, existing code using HTMLElement and null continues to work identically; the main risk is any consumer relying on strict HTMLElement-only typing via toEqualTypeOf-style assertions in their own code, since the public interfaces are now broader unions.