Conversation
🦋 Changeset detectedLatest commit: 002ea39 The changes in this PR will be included in the next version bump. This PR includes changesets to release 14 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Hey TanStack team, my first contribution here. I didn't include the generated docs as they generate a lot of changes. What's the general rule: include generated docs in the PR or create a follow-up PR for docs only? |
Hi @Jastrzebowski, changes to docs should be made in a separate PR because the docs are built and updated by CI when merged into main. So we typically have an implementation PR and a separate docs PR and we only merge the docs PR when the corresponding implementation is released. |
kevin-dp
left a comment
There was a problem hiding this comment.
The implementation looks great and it's definitely valuable for query collections.
I'm a bit hesitant though because meta is only used for query collections yet it is added to the public query builder API but isn't applicable to other collection types. It also complicates the TanStack DB core implementation while being related only to query collections.
For these reasons, i'd rather have meta on the queryCollectionOptions only.
@samwillis @KyleAMathews any thoughts on this?
🎯 Changes
Summary
.meta()method to pass dynamic runtime context (tenant IDs, scopes, feature flags) to query functionsDiscussion and issues related with passing meta in queries:
Problem
Applications need to pass runtime context to their query functions — such as tenant IDs for multi-tenancy, authorisation scopes, or feature flags — without embedding these values in query predicates. Previously, there was no way to attach this metadata to queries, forcing developers to either hardcode context or use workarounds.
Additionally, when different runtime contexts share the same predicates, caching and deduplication logic must account for meta differences, otherwise, queries from different tenants or users with identical predicates would incorrectly share cache entries, causing data isolation bugs.
Approach
The
.meta()method accepts arbitrary context data and integrates seamlessly with the query builder, following the same chainable pattern as existing methods like.limit(). Query-level metadata is merged with collection-level metadata (with query-level taking precedence).Meta is included in the cache key serialisation, ensuring that queries with identical predicates but different runtime contexts receive separate cache entries. The
isPredicateSubset()deduplication logic also checks meta equality, preventing data corruption in multi-tenant scenarios where two requests with the same predicates but different tenant scopes would otherwise reuse cached data from the wrong tenant.The implementation includes tests that validate meta preservation throughout the query lifecycle, correct merging semantics, proper cache key differentiation, and deduplication behaviour.
Documentation covers usage in live queries and extends the existing
metadocumentation for collections.✅ Checklist
pnpm test.🚀 Release Impact