Skip to content

useLiveQuery pagination breaks on revisited pages when syncMode='on-demand' #1434

@thebigthing313

Description

@thebigthing313
  • I've validated the bug against the latest version of DB packages
  "dependencies": {
    "@tanstack/db": "^0.6.1",
    "@tanstack/query-core": "^5.95.2",
    "@tanstack/query-db-collection": "^1.0.32",
    "@tanstack/react-db": "^0.1.79",
    "@types/react": "^19.2.14",
    "@types/react-dom": "^19.2.3",
    "react": "^19.2.4",
    "react-dom": "^19.2.4",
    "typescript": "^6.0.2",
    "vite": "^6.3.5"
  }

Describe the bug
When using useLiveQuery with a paginated syncMode: 'on-demand' collection, navigating back to a previously-visited page causes subsequent page navigations throw errors.

Eager collections work fine.

To Reproduce
Steps to reproduce the behavior:

  1. Go to https://stackblitz.com/edit/vitejs-vite-c5zum7r4?file=src%2FBugDemo.tsx
  2. Follow steps on demo page.

Expected behavior
Navigating back to a previously-visited page should load its rows correctly, and subsequent navigations should continue to work normally.

Additional context
On the demo, after page load:
Clicking Page 2: No error.
Clicking Page 3: No error.
Clicking Page 2: Collection "live-query-4" sync cleanup function threw an error: Ordered snapshot was requested but no index was found. You have to call setOrderByIndex before requesting an ordered snapshot.
Clicking Page 4: Invalid collection status transition from "cleaned-up" to "ready" for collection "live-query-4"
Clicking Page 5: No error thrown, but no data either.
Clicking Page 4: Collection "live-query-7" sync cleanup function threw an error: Invalid collection status transition from "cleaned-up" to "ready" for collection "live-query-4", but data loads now.
Clicking Page 5: Three errors, all: Invalid collection status transition from "cleaned-up" to "ready" for collection "live-query-4"

Thank you for all your hard work with this awesome library :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions