Skip to content

Prevent triggering subscribeChanges when long-polling request finishes with up-to-date #597

@evanob

Description

@evanob

I noticed in our app that every time a long-polling request finishes, it causes all associated queries on that collection to return a new data object. In React, this triggers a lot of unnecessary re-renders.

This appears to be because the snapshot version is bumped whenever subscribeChanges is called, even if the list of changes is empty.

const subscription = collectionRef.current.subscribeChanges(() => {
// Bump version on any change; getSnapshot will rebuild next time
versionRef.current += 1
onStoreChange()
})

When I patch @tanstack/react-db as below, the problem goes away.

Image

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