Skip to content
Source
Sign inSign up
TanStack/db

Support persisted initialRender for Electric progressive collections #2202

Send to my agent
ClosedJose10go(GitHub profile, opens in a new tab) opened this issue 1 comment

Description:

Persisted progressive electric collections should render its cached data after a hard refresh while network sync continues.

initialRender: {
  strategy: 'network-first',
  networkTimeoutMs: 0,
}

This throws for syncMode: 'progressive' because Electric translates it to 'on-demand', which the persistence wrapper rejects. There is a documented restriction for on-demand collections. However, progressive collections eventually complete a full initial sync, so a previously completed, persisted snapshot should support this fallback.

Minimal reproduction

Versions: @tanstack/electric-db-collection@0.6.2, @tanstack/db-sqlite-persistence-core@0.4.11. Run this as an .mjs file with Node. No React, database, or running Electric server is needed to reproduce the configuration error.

import { electricCollectionOptions } from '@tanstack/electric-db-collection'
import { persistedCollectionOptions } from '@tanstack/db-sqlite-persistence-core'

persistedCollectionOptions({
  ...electricCollectionOptions({
    id: 'todos',
    syncMode: 'progressive',
    getKey: row => row.id,
    shapeOptions: {
      url: 'http://localhost:3000/v1/shape',
      params: { table: 'todos' },
    },
  }),
  persistence: {}, // Placeholder: throws before accessing persistence.
  initialRender: {
    strategy: 'network-first',
    networkTimeoutMs: 0,
  },
})

Produce Error: network-first initial rendering requires eager persistence syncMode

Expected behavior

For progressive collections with a previously completed persisted snapshot, allow initial rendering after local restoration, while network synchronization continues.

  1. 🎉 The fix for this issue has been released!

    Fixing PRs: https://github.com/TanStack/db/pull/2263

    Backfilled notification for published release candidates.

Sign in to join this conversation.