Skip to content

Conversation

@nathanstitt
Copy link

@nathanstitt nathanstitt commented Dec 9, 2025

When collections with syncMode: 'on-demand' are joined, the where clause sent to the server via loadSubset often can contain duplicate values in the 'in' condition. This occurs when the active side of the join has multiple rows with the same join key (e.g., multiple posts by the same user).

Before: userId IN (1, 1, 1, 2, 2)
After: userId IN (1, 2)

I discovered this when developing a pocketbase adapter where it was crumbling under requests like:

image

I also see that DB isn't de-duplicating requests like:

useLiveQuery(q.from({ books: booksCollection }).where(({ books }) => inArray(books.id, [1,1,1,1,1])),

Will also send the where with duplicated values to the collection. To me that's acceptable though because it's what the caller requested, but I can add deduplication to it if you'd like.

Or maybe this PR is off-base and the collection adapter should be handling this? I did add deduplication to my library but I did find it surprising and others may as well.

🎯 Changes

✅ Checklist

  • I have followed the steps in the Contributing guide.
    ☝️ this link is broken db doesn't seem to have a CONTRIBUTING.md at all
  • I have tested this code locally with pnpm test:pr.
    ☝️ there is not a package.json script for test:pr, but I have ran with pnpm test

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

I did not add a changelog because I'd consider this a simple bug fix not worth noting. happy to do so if you'd like

When collections with syncMode: 'on-demand' are joined, the where clause
sent to the server via loadSubset contained duplicate values in the 'in'
condition. This occurred when the active side of a join had multiple rows
with the same join key (e.g., multiple posts by the same user).

Before: userId IN (1, 1, 1, 2, 2)
After:  userId IN (1, 2)
@changeset-bot
Copy link

changeset-bot bot commented Dec 9, 2025

⚠️ No Changeset found

Latest commit: 3cb848a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@robertf224
Copy link

Relatedly I also noticed:

  • it passes along undefined so collection implementations have to filter those out
  • it will sometimes pass an empty array which should always return nothing

Think it prob makes sense to handle these upstream rather than pushing to collection implementations

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.

2 participants