Skip to content

Single-flight responses for server components send an empty X-Frame-Stream: frames' bundled copy of INVOCATIONS is never written #3641

Closed

Description

@brenelz

Describe the bug

When a server component is called with POST and single-flight collects data, the frame-stream response has X-Frame-Stream: "" and its primary frame has "id": "". On the client, applyFlightResponse returns rootId ? binding : envelope.value. With an empty root id it returns envelope.value, which is undefined for a component result, so a dynamic() over the call renders nothing: no fallback, no content, no error.

The cause is packaging. packages/web/frames/src/frame-sink.ts imports getEventServerFunctionInvocation from ../../server-functions/src/server.js by relative path, so frames/dist/server.js bundles its own copy of that module. The shared registries in that copy go through processState(...) on globalThis, but INVOCATIONS is const INVOCATIONS = new WeakMap() (server.ts:1102 on next). The handler records the invocation in the server-functions copy, and frameTransformFlightResult reads the frames copy, which is always empty.

Any app that registers a flight-data source hits this on every POST server component call. That includes @solidjs/router's createFlightDataCollector and TanStack Start's tsr source. Components fetched with GET (for example through query()) aren't affected, because single-flight only applies to POST.

Steps to Reproduce the Bug or Issue

With @solidjs/[email protected] and [email protected]:

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

createServerReference(registerServerReference("view-1", async () => () => "view markup"));

configureServerFunctionsServer({
  provideEvent: provideRequestEvent,
  transformResult: frameTransformResult,
  transformDirectResult: frameTransformDirectResult,
  transformFlightResult: frameTransformFlightResult,
  collectFlightData: async () => ({ "route-data[]": { title: "x" } })
});

const res = await handleServerFunctionRequest(
  new Request("http://localhost/_server/data/view-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(FRAME_STREAM_HEADER + ":", JSON.stringify(res.headers.get(FRAME_STREAM_HEADER)));

It prints X-Frame-Stream: "". Calling getEventServerFunctionInvocation(event) from @solidjs/web/server-functions/server inside a wrapping transformFlightResult returns {"id":"view-1"} for the same event, which shows the two copies disagree.

Expected behavior

X-Frame-Stream: "view-1", so the client binds the returned component. Changing the declaration to const INVOCATIONS = processState("solid.ServerFunctionInvocations", () => new WeakMap()) in the server-functions and frames server bundles (all three flavors) makes the script print "view-1". It also fixes the blank render in a TanStack Start app that calls a server component client-first in production.

Platform

Activity

  1. ryansolid commented on Sep 24, 2026

    @ryansolid
    Member

    Fixed in 78523bf (#3643) — thanks for the reproduction, and especially for the copy-disagreement diagnostic (getEventServerFunctionInvocation(event) answering {"id":"view-1"} from the server-functions entry while the frames transform saw nothing); that pointed straight at the packaging.

    Your diagnosis was exactly right: frames/dist/server*.js carried a private copy of the server-function runtime, and INVOCATIONS was the one piece of module state in it that wasn't process state.

    We went a different way than the processState("solid.ServerFunctionInvocations", …) one-liner, though. That would make this symptom go away, but it treats the real defect — two instances of a runtime designed to have one — as something to route around, and every further bit of module state added to server.ts or shared.js would need the same treatment or regress the same way. #3640 settled this for the client half (the frames client imports the shared server-function client rather than bundling one), and #3643 applies the same ruling to the server half: the frames server build now resolves its server-functions/src/server.js and shared.js imports to @solidjs/web/server-functions/server, and its SSR-runtime import to @solidjs/web, as externals. One instance by construction, in all three tiers; processState stays exactly where it is for the Vite dev module-runner case (#3346), which is a different problem.

    Externalizing the SSR runtime turned out to matter on its own: compiled SSR output arms the <select value> gate through @solidjs/web, and the frames copy's renderToStream never saw it, so a <select value> inside a server component streamed unresolved. That is fixed by the same change and pinned in the same dist-level spec, which runs your script against the built artifacts under the default, development and observe conditions.

    — 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