SerovalUnsupportedTypeError when TanStack Start SSR dehydrates an on-demand query collection
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 52/100
- Issue-Typ
- Bug
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- react, typescript
- Bereich
- backend
Rechercherichtung
Start with the reproduction by running npm install and node index.js, then trace metadata from packages/query-db-collection/src/query.ts through packages/query-core/src/hydration.ts. Read the expression structures in packages/db/src/query/ir.ts and compare them with the SSR serialization path described in the issue. Done means the on-demand collection dehydrates and serializes successfully, allowing SSR hydration without the SerovalUnsupportedTypeError.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
- I've validated the bug against the latest version of DB packages
Describe the bug
SSR breaks with SerovalUnsupportedTypeError when a syncMode: "on-demand" query collection is used with @tanstack/react-router-ssr-query (setupRouterSsrQueryIntegration).
query-db-collection stores LoadSubsetOptions on the TanStack Query cache entry as meta.loadSubsetOptions. Those options contain the expression IR classes (Func, PropRef, Value) from @tanstack/db and a live AbortSignal. @tanstack/query-core's dehydrateQuery copies meta into the dehydrated state, and @tanstack/router-core serializes the router payload with seroval.crossSerializeStream. Seroval has no plugin for the IR classes or for AbortSignal, so it throws on the first Func node.
Server log:
Serialization error: SerovalUnsupportedTypeError: Seroval Error (specific: 1)
at parseObjectPhase2 (seroval/dist/index.js:2783:8)
...
value: Func { name: 'and', args: [ [Func], [Func] ], type: 'func' }
The dev server then reports [vite] Internal server error: socket hang up and the request 500s.
To Reproduce
StackBlitz: link
Or locally:
npm installnode index.js
The script creates an on-demand query collection, runs a live query with two .where() calls, dehydrates the QueryClient, and feeds the result to seroval.crossSerializeStream with the same options shape @tanstack/router-core uses (refs, onSerialize, onError, onDone).
Output:
queryFn received where: Func and
query.meta.loadSubsetOptions keys: [ 'where', 'signal', 'orderBy', 'limit' ]
where: Func and
signal: AbortSignal
seroval.crossSerializeStream(dehydratedRouter) <- TanStack Start SSR serialization:
FAILED: Seroval Error (specific: 1)
offending value: Func {
name: 'and',
args: [
Func { name: 'eq', args: [Array], type: 'func' },
Func { name: 'eq', args: [Array], type: 'func' }
],
type: 'func'
}
Expected behavior
The dehydrated state for a query collection should serialize like any other cached query, so SSR hydration works.
Screenshots
Not applicable. The failure is server-side and the terminal output is above.
Desktop
- OS: Linux (Ubuntu devcontainer)
- Browser: not applicable, the failure happens during SSR
- Version: Node v24.21.0, npm 11.19.0
Smartphone
Not applicable.
Additional context
Versions (all current latest): @tanstack/db 0.9.2, @tanstack/query-db-collection 1.2.15, @tanstack/query-core 5.104.0, @tanstack/router-core 1.171.33, @tanstack/router-ssr-query-core 1.169.3, seroval 1.6.8.
Where the meta comes from (packages/query-db-collection/src/query.ts):
function getLoadSubsetOptionsForMeta(
opts: LoadSubsetOptions,
): Omit<LoadSubsetOptions, `subscription` | `refetch`> {
const {
subscription: _subscription,
refetch: _refetch,
...serializableOptions
} = opts
return serializableOptions
}
subscription and refetch are removed, and the rest is named serializableOptions. What remains includes where, orderBy, and cursor (instances of Func / PropRef / Value, see packages/db/src/query/ir.ts) plus signal, an AbortSignal. The copy becomes extendedMeta.loadSubsetOptions on the QueryObserver, so it ends up at query.meta.loadSubsetOptions.
Dehydration keeps it (packages/query-core/src/hydration.ts):
...(query.meta && { meta: query.meta }),
@tanstack/router-ssr-query-core dehydrates every query into dehydratedData.query.initial and the query stream. @tanstack/router-core serializes that payload with crossSerializeStream and ssrSerovalPlugins (ShallowErrorPlugin, RawStreamSSRPlugin, ReadableStreamPlugin). None of those plugins handle the IR classes, and the set has no AbortSignal plugin, although one exists in seroval-plugins/web. seroval.serialize({ s: new AbortController().signal }) throws for the same reason.
PR #1644 / issue #901 covered structuredClone-based persisters. structuredClone drops prototypes and on Node accepts the AbortSignal, so those persisters pass, while the Seroval path still fails. The two consumers need different handling.
Possible fixes:
- Strip
signalfrom the meta copy. Query functions already receive asignalthrough the Query function context. - Store the expression tree as plain serializable nodes.
parseWhereExpressionandparseOrderByExpressionreadtype/name/args/path/value, so plain objects keep working forctx.meta.loadSubsetOptions. - Alternatively keep subset state out of
meta, or add aserializeMetahook to the dehydration path.
Workaround in an app:
setupRouterSsrQueryIntegration({
router,
queryClient,
dehydrateOptions: {
shouldDehydrateQuery: (query) => {
const options = query.meta?.loadSubsetOptions
return !options?.where && !options?.orderBy?.length && !options?.cursor && !options?.signal
},
},
})
That keeps plain and eager-collection queries in the SSR payload and lets the on-demand ones refetch in the browser.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 3.9k
- Forks
- 277
- Ø Merge
- 20 Std. 31 Min.
- Gemergte PRs (30 T.)
- 228
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus TanStack/db
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 48/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 22/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 12/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 8/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 25/100
Maintainer antworten meist innerhalb von 1 Tag
Ähnliche Issues
-
area:workflow bug ready-for-human
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 78/100
fil-donadoni/tolaria#6108 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
apache/rocketmq-dashboard#7234 ·
Maintainer antworten meist innerhalb von 3 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
vitest-dev/vitest#11656 ·
Maintainer antworten meist innerhalb von 1 Tag
-
e2e-failure ready-to-code
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
redhat-developer/rhdh-plugin-export-overlays#4460 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
ehmpathy/rhachet-roles-bhrain#655 ·
Maintainer antworten meist innerhalb von 1 Tag