fix: fix useSpacetimeDBQuery returns untyped rows for TanStack Start (#4488)

# Description of Changes
- Fix useSpacetimeDBQuery returns untyped rows for TanStack Start

Closes https://github.com/clockworklabs/SpacetimeDB/issues/4441

<!-- Please describe your change, mention any related tickets, and so on
here. -->

# API and ABI breaking changes

<!-- If this is an API or ABI breaking change, please apply the
corresponding GitHub label. -->

# Expected complexity level and risk

<!--
How complicated do you think these changes are? Grade on a scale from 1
to 5,
where 1 is a trivial change, and 5 is a deep-reaching and complex
change.

This complexity rating applies not only to the complexity apparent in
the diff,
but also to its interactions with existing and future code.

If you answered more than a 2, explain what is complex about the PR,
and what other components it interacts with in potentially concerning
ways. -->

# Testing

<!-- Describe any testing you've done, and any testing you'd like your
reviewers to do,
so that you're confident that all the changes work as expected! -->

- [ ] <!-- maybe a test you want to do -->
- [ ] <!-- maybe a test you want a reviewer to do, so they can check it
off when they're satisfied. -->
This commit is contained in:
clockwork-tien
2026-03-03 12:55:46 +02:00
committed by GitHub
parent 7470eb23d3
commit 5836c268a7
2 changed files with 7 additions and 4 deletions
@@ -4,13 +4,15 @@ import type {
QueryFunction,
} from '@tanstack/react-query';
import {
type Query,
toSql,
type BooleanExpr,
evaluateBooleanExpr,
getQueryAccessorName,
getQueryWhereClause,
} from '../lib/query';
type QueryInput = { toSql(): string } & Record<string, any>;
type QueryInput = Query<any>;
const queryRegistry = new Map<
string,
@@ -51,7 +53,7 @@ export function spacetimeDBQuery(
const query = queryOrSkip;
const accessorName = getQueryAccessorName(query);
const whereExpr = getQueryWhereClause(query);
const querySql = query.toSql();
const querySql = toSql(query);
queryRegistry.set(querySql, { accessorName, whereExpr });
@@ -6,6 +6,7 @@ import type {
UseSuspenseQueryResult,
} from '@tanstack/react-query';
import type { UntypedTableDef, RowType } from '../lib/table';
import type { Query } from '../lib/query';
import { spacetimeDBQuery } from './SpacetimeDBQueryClient';
export type UseSpacetimeDBQueryResult<T> = [
@@ -29,7 +30,7 @@ export type UseSpacetimeDBSuspenseQueryResult<T> = [
// useSpacetimeDBQuery(tables.user.where(r => r.online.eq(true)))
// useSpacetimeDBQuery(condition ? tables.user : 'skip')
export function useSpacetimeDBQuery<TableDef extends UntypedTableDef>(
queryOrSkip: ({ toSql(): string } & Record<string, any>) | 'skip',
queryOrSkip: Query<TableDef> | 'skip',
// any useQuery option (e.g. enabled, refetchInterval, select, placeholderData),
// except queryKey, queryFn, and meta (managed internally)
options?: Omit<
@@ -60,7 +61,7 @@ export function useSpacetimeDBQuery<TableDef extends UntypedTableDef>(
// until data is ready, a parent <Suspense fallback={…}> handles the loading UI.
// does not support 'skip' because useSuspenseQuery must always resolve
export function useSpacetimeDBSuspenseQuery<TableDef extends UntypedTableDef>(
query: { toSql(): string } & Record<string, any>,
query: Query<TableDef>,
options?: Omit<
UseSuspenseQueryOptions<
RowType<TableDef>[],