From 149ad4d7b55b27265ac253ecb6a22d238bd4f341 Mon Sep 17 00:00:00 2001 From: kisk Date: Tue, 27 Jan 2026 02:02:30 +0200 Subject: [PATCH 1/2] feat: forward structuralSharing to QueryObserver --- packages/query-db-collection/src/query.ts | 10 ++++++- .../query-db-collection/tests/query.test.ts | 26 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/packages/query-db-collection/src/query.ts b/packages/query-db-collection/src/query.ts index 6b3f83a90..ab47dc6a9 100644 --- a/packages/query-db-collection/src/query.ts +++ b/packages/query-db-collection/src/query.ts @@ -112,6 +112,13 @@ export interface QueryCollectionConfig< Array, TQueryKey >[`staleTime`] + structuralSharing?: QueryObserverOptions< + Array, + TError, + Array, + Array, + TQueryKey + >['structuralSharing'] /** * Metadata to pass to the query. @@ -543,6 +550,7 @@ export function queryCollectionOptions( onUpdate, onDelete, meta, + structuralSharing, ...baseCollectionConfig } = config @@ -717,7 +725,6 @@ export function queryCollectionOptions( queryKey: key, queryFn: queryFunction, meta: extendedMeta, - structuralSharing: true, notifyOnChangeProps: `all`, // Only include options that are explicitly defined to allow QueryClient defaultOptions to be used @@ -726,6 +733,7 @@ export function queryCollectionOptions( ...(retry !== undefined && { retry }), ...(retryDelay !== undefined && { retryDelay }), ...(staleTime !== undefined && { staleTime }), + ...(structuralSharing !== undefined && { structuralSharing }), } const localObserver = new QueryObserver< diff --git a/packages/query-db-collection/tests/query.test.ts b/packages/query-db-collection/tests/query.test.ts index 0a623de61..ffabe09ae 100644 --- a/packages/query-db-collection/tests/query.test.ts +++ b/packages/query-db-collection/tests/query.test.ts @@ -3500,6 +3500,32 @@ describe(`QueryCollection`, () => { // Clean up customQueryClient.clear() }) + + it(`should forward structuralSharing option to QueryObserver`, async () => { + const queryKey = [`structuralSharingTest`] + const queryFn = vi.fn().mockResolvedValue([]) + + const options = queryCollectionOptions({ + id: `test`, + queryClient, + queryKey, + queryFn, + getKey, + structuralSharing: false, + startSync: true, + }) + + createCollection(options) + + await vi.waitFor(() => { + expect(queryFn).toHaveBeenCalled() + }) + + const query = queryClient.getQueryCache().find({ queryKey }) + + expect(query).toBeDefined() + expect(query!.options.structuralSharing).toBe(false) + }) }) describe(`Query Garbage Collection`, () => { From 7434ec1f565748a3b4c1b6d1b15e668fbf4e9039 Mon Sep 17 00:00:00 2001 From: kisk Date: Tue, 27 Jan 2026 02:15:28 +0200 Subject: [PATCH 2/2] fix(query-db-collection): forward structuralSharing option --- .changeset/open-ideas-fix.md | 5 +++++ packages/db/src/query/builder/index.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/open-ideas-fix.md diff --git a/.changeset/open-ideas-fix.md b/.changeset/open-ideas-fix.md new file mode 100644 index 000000000..a90008e0c --- /dev/null +++ b/.changeset/open-ideas-fix.md @@ -0,0 +1,5 @@ +--- +'@tanstack/query-db-collection': patch +--- + +Forward structuralSharing option to QueryObserver diff --git a/packages/db/src/query/builder/index.ts b/packages/db/src/query/builder/index.ts index 6ef4d1ddc..fefc23d34 100644 --- a/packages/db/src/query/builder/index.ts +++ b/packages/db/src/query/builder/index.ts @@ -34,8 +34,8 @@ import type { import type { CompareOptions, Context, - GetResult, FunctionalHavingRow, + GetResult, GroupByCallback, JoinOnCallback, MergeContextForJoinCallback,