Skip to content

Undici crash when using form data and blobs in server functions #6009

@Zuruuh

Description

@Zuruuh

Which project does this relate to?

Start

Describe the bug

(Tested react-start 1.139.12, nodejs 24.11, undici 7.16 (installed through npm and not using the nodejs' bundled version))

When trying to send a form data object containing a blob using undici.request from a server action the call crashes with the following error

Server Fn Error!

TypeError: Cannot read properties of null (reading 'byteLength')
    at Object.pull (node:internal/deps/undici/undici:6191:24)
    at invokePromiseCallback (node:internal/webstreams/util:172:10)
    at Object.<anonymous> (node:internal/webstreams/util:177:23)
    at readableByteStreamControllerCallPullIfNeeded (node:internal/webstreams/readablestream:3145:24)
    at readableByteStreamControllerPullSteps (node:internal/webstreams/readablestream:3254:3)
    at [kPull] (node:internal/webstreams/readablestream:1201:5)
    at readableStreamDefaultReaderRead (node:internal/webstreams/readablestream:2269:39)
    at nextSteps (node:internal/webstreams/readablestream:493:7)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async writeIterable (node:internal/deps/undici/undici:7485:26)

With the following example code

import { createServerFn } from '@tanstack/react-start'
import * as undici from 'undici';
import * as fs from 'node:fs';

export const doFetch = createServerFn({ method: 'GET' }).handler(async () => {
    const data = new undici.FormData();
    data.append(
        'document',
        await fs.openAsBlob('./package.json'),
        'package.json'
    );


    // This function call here is throwing
    const response = await undici.request('http://localhost:3000', {
        body: data,
        method: 'POST',
    });

    console.log(response.statusCode, await response.body.text());

})

This code is valid and works correctly when ran through node's repl:

 : node
Welcome to Node.js v24.11.0.
Type ".help" for more information.
> const { doFetch } = await import('./src/action.ts')
undefined
> await doFetch()
404 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot POST /</pre>
</body>
</html>

undefined
>

I suspect this might have to do with some global patching of the Blob class maybe ? I'm not entirely sure really

Your Example Website or App

https://github.com/Zuruuh/tanstack-start-undici-repro

Steps to Reproduce the Bug or Issue

  1. Press the button on the reproducer and check the terminal

Expected behavior

The http call should succeed

Screenshots or Videos

No response

Platform

  • Router / Start Version: 1.139.12
  • OS: Reproduced on WSL and MacOS
  • Browser: Reproduced on Chrome and Firefox (both latest)
  • Bundler: vite
  • Bundler Version: 7.2.6

Additional context

I'm not sure wether this is an issue with tanstack start or undici really, but given that the same function works outside of start I think it's worth reporting here

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