Skip to content
Source
Sign inSign up
TanStack/db

fix(electric): release the shape stream's visibility listener on cleanup #2257

MergedNabil372(GitHub profile, opens in a new tab)merged 15 commits intomain fromrefs/pull/2257/headmerged by KyleAMathews(GitHub profile, opens in a new tab)

Showing 18 changed files with 12 additions and 0 deletions (loading 16).

x
0 of 18 viewed, 18 left
5 additions and 0 deletions.changeset/electric-cleanup-stream-listeners.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/electric-db-collection': patch
+---
+​
+Release the shape stream's visibility listener when a sync run is cleaned up. The Electric client registers a `visibilitychange` listener for each `ShapeStream` (an `AppState` subscription on React Native, from `@electric-sql/client` 1.5.23) and removes it only in `unsubscribeAll()`, so aborting the stream left the listener behind, and the listener kept the stream reachable. An app that cleans up and recreates collections, or whose on-demand cache rotates its provider session, gained one retained stream each time.
7 additions and 0 deletionsdocs/collections/electric-collection.mdModified
View file
@@ -355,6 +355,13 @@
evidence from the replacement session. The replacement reloads demanded
subsets and does not treat acknowledgements from the retired session as current.
​
+Before constructing a replacement `ShapeStream`, Electric releases the
+adapter-owned resources of the retired provider session, including its
+subscriptions and host lifecycle listeners. The replacement starts after cache
+rotation completes. An HTTP request that ignores cancellation may still finish
+later; its response cannot publish rows or settle waits for the replacement
+session.
+​
Persisted resumes wait for the cached row baseline to finish hydrating. If the
persistence wrapper cannot verify hydration completion, Electric starts a fresh
snapshot instead of using the saved offset and handle. It warns once per options
docs/contributing/oracle-reviews/2026-10-26-pr-2257.mdAdded
View file