Skip to content

feat: widen element types to Element and accept undefined refs#156

Merged
metonym merged 2 commits into
masterfrom
metonym/pasted-text-review-v4
Jul 5, 2026
Merged

feat: widen element types to Element and accept undefined refs#156
metonym merged 2 commits into
masterfrom
metonym/pasted-text-review-v4

Conversation

@metonym

@metonym metonym commented Jul 5, 2026

Copy link
Copy Markdown
Owner

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.

- 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
render Bot temporarily deployed to metonym/pasted-text-review-v4 - svelte-intersection-observer PR #156 July 5, 2026 20:28 Destroyed
@metonym
metonym merged commit cf52db0 into master Jul 5, 2026
3 checks passed
@metonym
metonym deleted the metonym/pasted-text-review-v4 branch July 5, 2026 20:30
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