Skip to content

Single-flight with server components fails: frameTransformFlightResult does not read consumer-keyed flight data #3638

Closed

Description

@brenelz

Describe the bug

When a mutation's single-flight data includes a server component, the response fails to encode instead of streaming the component's markup.

foldFlightData (packages/web/server-functions/src/server.ts) builds the flight data keyed by consumer id, Object.fromEntries(folded), so an unnamed collector's slice arrives as { "true": { [key]: value } }. frameTransformFlightResult (packages/web/frames/src/frame-sink.ts) only looks for component values at the top level of data. It sees "true" mapped to an object, finds no regions, and returns undefined. The handler then falls back to the plain codec, which throws on the component function:

Server function result could not be encoded: The value [object Function] of type "function" cannot be parsed/serialized.

In production the stream ends with !{"message":"Internal Server Error"}. The response still has status 200 and x-single-flight: true, so the client gets a failed action.

This breaks every single-flight mutation that revalidates a server component, including @solidjs/router's createFlightDataCollector with serverRouteComponent routes and file-system server pages. I hit it in an app using @solidjs/[email protected]. The same code is on next at dcca7d4.

Your Example Website or App

The standalone script below uses only @solidjs/web.

Steps to Reproduce the Bug or Issue

With @solidjs/[email protected] and [email protected] installed, run node repro.mjs (or node --conditions=development repro.mjs for the dev message):

import {
  configureServerFunctionsServer,
  handleServerFunctionRequest,
  registerServerReference,
  createServerReference
} from "@solidjs/web/server-functions/server";
import {
  frameTransformResult,
  frameTransformDirectResult,
  frameTransformFlightResult
} from "@solidjs/web/frames/server";
import { provideRequestEvent } from "@solidjs/web/storage";

// A server component's resolved value (what a query cache entry holds): a component.
const View = () => "fresh markup";

createServerReference(registerServerReference("mutate-1", async () => "ok"));

configureServerFunctionsServer({
  provideEvent: provideRequestEvent,
  transformResult: frameTransformResult,
  transformDirectResult: frameTransformDirectResult,
  transformFlightResult: frameTransformFlightResult,
  // The unnamed collector: one invalidated key whose value is markup.
  collectFlightData: async () => ({ "view[]": View })
});

const res = await handleServerFunctionRequest(
  new Request("http://localhost/_server/data/mutate-1", {
    method: "POST",
    headers: {
      "content-type": "application/json",
      origin: "http://localhost",
      "sec-fetch-site": "same-origin",
      "x-server-function-format": "3",
      "x-single-flight": "true"
    },
    body: "[]"
  })
);
console.log(res.status, res.headers.get("content-type"), "x-single-flight:", res.headers.get("x-single-flight"));
console.log(await res.text());

// The transform itself, given the two data shapes.
const flat = await frameTransformFlightResult(null, { value: "ok", data: { "view[]": View } });
const keyed = await frameTransformFlightResult(null, { value: "ok", data: { true: { "view[]": View } } });
console.log("flat data  ->", flat?.headers.get("content-type"));
console.log("keyed data ->", keyed);

Output:

200 text/plain x-single-flight: true
;0x00000170;!{"message":"Server function result could not be encoded: The value [object Function] of type \"function\" cannot be parsed/serialized. ..."}
flat data  -> application/x-frame-stream
keyed data -> undefined

The last two lines isolate the mismatch. Given flat data, the transform returns a frame stream. Given the consumer-keyed shape that foldFlightData actually passes, it returns undefined.

Expected behavior

The response should be an application/x-frame-stream that carries View's markup as a region, with the { value, data } outcome referencing it, the same as when the transform gets flat data. frameTransformFlightResult should look one level down, into each consumer's slice, for component-valued entries, and keep the consumer keys in the data it serializes so the client can still route each slice to its consumer.

Screenshots or Videos

None.

Platform

Activity

  1. ryansolid commented on Sep 24, 2026

    @ryansolid
    Member

    Fixed in cf22713 (#3640) on next — thanks for the reproduction, @brenelz.

    Root cause: the single-flight fold keys flight data by source ({ [source]: slice }, the unnamed collector under "true"), but the frames transform still scanned only the top level of data for server components. It found none, declined, and the handler fell back to the plain codec, which cannot encode a component function — the could not be encoded … "function" you saw. Two more halves of the same drift went with it: the frames client delivered the whole keyed envelope to the unnamed consumer only, and the frame policy stamped a bare X-Single-Flight: true that dropped named sources from the header. Single-flight delivery is now one shared path for both the plain and frame-stream bodies, and the fold owns the header on every response shape.

    Verified end-to-end on the notes example: a saveNote mutation now answers with application/x-frame-stream carrying the revalidated noteListView/noteView regions plus the outcome envelope. Will ship with the next 2.0.0-rc release.

    — Claude via Cursor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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