Skip to content

Deserialization error when using async generators from server functions #7345

@Zuruuh

Description

@Zuruuh

Which project does this relate to?

Start

Describe the bug

When defining a streamable server function (with an async function*), I can consistently get the deserialization to fail, preventing me from doing anything further

Stack Trace
Invalid JSON: {"t":32,"i":5,"f":{"t":10,"i":9,"p":{"k":["hello"],"v":[{"t":1,"s":"world"}]},"o":0}}
 Error: Seroval caught an error during the deserialization process.

Error
Malformed node type "32".

- For more information, please check the "cause" property of this error.
- If you believe this is an error in Seroval, please submit an issue at https://github.com/lxsmnsyc/seroval/issues/new
    SerovalError errors.ts:51
    SerovalDeserializationError errors.ts:69
    deserializeTop deserializer.ts:858
    fromCrossJSON index.ts:189
    onMessage serverFnFetcher.ts:289
    drain serverFnFetcher.ts:391
    processFramedResponse serverFnFetcher.js:226
    getResponse serverFnFetcher.ts:287
    serverFnFetcher serverFnFetcher.ts:167
    clientFn createClientRpc.ts:12
    client createServerFn.ts:921
    callNextMiddleware createServerFn.ts:313
    executeMiddleware createServerFn.ts:353
    handler createServerFn.ts:150
    onClick index.tsx:17
    React 13
    <anonymous> client.tsx:6
    startTransition React
    <anonymous> client.tsx:5
Caused by: Error: Malformed node type "32".
    SerovalMalformedNodeError errors.ts:170
    validateNodeType deserializer.ts:368
    deserializeStreamNext deserializer.ts:695
    deserialize deserializer.ts:834
    deserializeTop deserializer.ts:856
    fromCrossJSON index.ts:189
    onMessage serverFnFetcher.ts:289
    drain serverFnFetcher.ts:391
    processFramedResponse serverFnFetcher.js:226
    getResponse serverFnFetcher.ts:287
    serverFnFetcher serverFnFetcher.ts:167
    clientFn createClientRpc.ts:12
    client createServerFn.ts:921
    callNextMiddleware createServerFn.ts:313
    executeMiddleware createServerFn.ts:353
    handler createServerFn.ts:150
    onClick index.tsx:17
    React 13
    <anonymous> client.tsx:6
    startTransition React
    <anonymous> client.tsx:5
[__root.tsx:66:14](http://localhost:3000/src/routes/__root.tsx)
Invalid JSON: {"t":34,"i":5,"f":{"t":2,"s":1}}
 Error: Seroval caught an error during the deserialization process.

Error
Malformed node type "34".

- For more information, please check the "cause" property of this error.
- If you believe this is an error in Seroval, please submit an issue at https://github.com/lxsmnsyc/seroval/issues/new
    SerovalError errors.ts:51
    SerovalDeserializationError errors.ts:69
    deserializeTop deserializer.ts:858
    fromCrossJSON index.ts:189
    onMessage serverFnFetcher.ts:289
    drain serverFnFetcher.ts:391
    processFramedResponse serverFnFetcher.js:226
    getResponse serverFnFetcher.ts:287
    serverFnFetcher serverFnFetcher.ts:167
    clientFn createClientRpc.ts:12
    client createServerFn.ts:921
    callNextMiddleware createServerFn.ts:313
    executeMiddleware createServerFn.ts:353
    handler createServerFn.ts:150
    onClick index.tsx:17
    React 13
    <anonymous> client.tsx:6
    startTransition React
    <anonymous> client.tsx:5
Caused by: Error: Malformed node type "34".
    SerovalMalformedNodeError errors.ts:170
    validateNodeType deserializer.ts:368
    deserializeStreamReturn deserializer.ts:723
    deserialize deserializer.ts:838
    deserializeTop deserializer.ts:856
    fromCrossJSON index.ts:189
    onMessage serverFnFetcher.ts:289
    drain serverFnFetcher.ts:391
    processFramedResponse serverFnFetcher.js:226
    getResponse serverFnFetcher.ts:287
    serverFnFetcher serverFnFetcher.ts:167
    clientFn createClientRpc.ts:12
    client createServerFn.ts:921
    callNextMiddleware createServerFn.ts:313
    executeMiddleware createServerFn.ts:353
    handler createServerFn.ts:150
    onClick index.tsx:17
    React 13
    <anonymous> client.tsx:6
    startTransition React
    <anonymous> client.tsx:5

Complete minimal reproducer

https://github.com/Zuruuh/start-async-generator-repro

Steps to Reproduce the Bug

  1. Go to http://localhost:3000
  2. Open the console devtools
  3. Press the Test button

Expected behavior

I expect the deserialization to complete successfully so I can stream the response of my server function

Screenshots or Videos

No response

Platform

  • Router / Start Version: latset
  • OS: MacOS
  • Browser: Firefox, Brave
  • Browser Version: 150.x, 1.89.132
  • Bundler: vite
  • Bundler Version: 8.0.x

Additional context

I think I got this to work a few weeks ago and it might be possible that a recent update broke it

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions