TanStackT
TanStackโ€ข3w agoโ€ข
51 replies
standard-azure

Markdoc serialization from Tanstack Start serverFn

Hi everyone ๐Ÿ‘‹
Did anyone managed to return Markdoc from a serverFn? It looks like seroval cannot serialize Markdoc RenderableTreeNode:
SerovalUnsupportedTypeError: The value [object Object] of type "object" cannot be parsed/serialized.

There are few workarounds for this problem:
- Transform the value in a way that it can be serialized.
- If the reference is present on multiple runtimes (isomorphic), you can use the Reference API to map the references.
    at parseObjectPhase2 (file:///Users/philippelattention/Code/tanstack-start-markdoc-/
...
serialization/node_modules/.pnpm/seroval@1.4.0/node_modules/seroval/dist/esm/development/index.mjs:3539:18) {
  value: Tag {
    '$$mdtype': 'Tag',
    name: 'article',
    attributes: {},
    children: [ [Tag], [Tag] ]
  }
}
Server Fn Error!


Error reading routerStream: E [Error]: Seroval Error (specific: 1)

As seen on the attached screenshot, I used the simplest markdoc setup without any custom Node.

For now a workaround is to JSON stringify and parse... With react-router I was used to directly return the transformed markdoc from the loader, does anyone have another workaround?

Here is a reproduction https://github.com/PhilDL/tanstack-start-markdoc-serialization
CleanShot_2025-12-15_at_16.12.13.png
GitHub
Repro to demonstrate Markdoc serialization error from tanstack start server function using seroval under the hood. - PhilDL/tanstack-start-markdoc-serialization
GitHub - PhilDL/tanstack-start-markdoc-serialization: Repro to demo...
Was this page helpful?