Skip to content

A 304 resolves the call to undefined, so "not modified" arrives as "no data" #3101

Closed

Description

@frenzzy

Describe the bug

A 304 Not Modified reaching a scripted caller resolves the call to undefined, so "nothing changed" is delivered as "there is no data". The client has no handling for 304 at all — grep 304 packages/web/server-functions/src/client.ts finds nothing — and the response's Void body format decodes to undefined like any other empty answer.

This is not new behaviour, but it became reachable on the wire in 5be07a8 (#3096), which correctly narrowed the redirect mask to the statuses fetch follows, so a 304 now forwards instead of collapsing to 200. The client-visible result was already undefined before that; the fix only made the status honest about it.

The consequence for a caller is that the natural conditional-read idiom silently clears state:

const items = createAsync(() => getItems());   // resolves undefined on a 304

Steps to reproduce

mkdir sf-304 && cd sf-304 && npm init -y
npm i @solidjs/[email protected]
node repro.mjs

repro.mjs:

import { AsyncLocalStorage } from "node:async_hooks";
globalThis[Symbol.for("solid.RequestContext")] = new AsyncLocalStorage();
const srv = await import("@solidjs/web/server-functions/server");
const cli = await import("@solidjs/web/server-functions/client");
const { respond } = await import("@solidjs/web");

srv.registerServerFunction("fresh", () => respond({ items: [1, 2, 3] }, { status: 200 }));
srv.registerServerFunction("unchanged", () => respond(undefined, { status: 304 }));

globalThis.fetch = (address, init) => {
  const request = new Request(new URL(address.toString(), "http://localhost"), init);
  request.headers.set("Sec-Fetch-Site", "same-origin");
  return srv.handleServerFunctionRequest(request);
};

for (const id of ["fresh", "unchanged"]) {
  const wire = await srv.handleServerFunctionRequest(
    new Request(`http://localhost/_server/${id}`, {
      method: "POST", body: "[]",
      headers: { "Sec-Fetch-Site": "same-origin", "X-Server-Function-Instance": "i" } }));
  const value = await cli.createServerReference(id)();
  console.log(id.padEnd(10), "| wire", wire.status, "| client resolves:", JSON.stringify(value));
}

On next (ec523607):

fresh      | wire 200 | client resolves: {"items":[1,2,3]}
unchanged  | wire 304 | client resolves: undefined

On 2.0.0-rc.4 the wire status is 200 instead of 304 and the client result is the same undefined.

How much this matters, honestly

Less than it first looks, and I would rather say so than oversell it.

A 304 is an answer to a conditional request. In a browser, if the author uses ordinary HTTP caching (ETag / Cache-Control), the revalidation happens inside the browser's cache and JavaScript never sees a 304 — fetch hands back the stored 200. To reach the case above, someone has to set the conditional header themselves (prepareRequest makes that easy now) or sit behind an intermediary that answers 304 on its own.

So this is not "everyone hits it", it is "the one person who reaches for the conditional-read idiom gets a silent state wipe, with nothing in the API hinting that the idiom is unsupported". React Router's model says the quiet part out loud in its own source: it excludes 304 from the client-side bodiless set "because the browser should fill those responses with the cached body content" — i.e. a 304 is addressed to the cache, never to application code.

Expected behavior

Either a 304 never reaches application code, or it arrives as something distinguishable from "the answer is empty".

Options

  1. Say the idiom is unsupported, in the docs and in dev. A 304 is for the HTTP cache; a server function that wants conditional reads should set ETag/Cache-Control and let the browser revalidate. Add a dev-only warning when a scripted call receives a 304, so the silent wipe becomes a message. Cheapest, and it matches what the status is for.
  2. Deliver it as a distinguishable signal rather than undefined — a sentinel the query layer can act on by keeping its previous value. This is the only option that makes the idiom actually work, and it is the biggest: the transport holds no previous value, so "keep what you had" has to be decided a layer up, which means a contract between the transport and createAsync/query.
  3. Reject it at the source: treat respond(undefined, { status: 304 }) from a scripted call as an authoring error, the way a value at a null-body status now is (A null-body status turns into a 200 carrying an unexplained Internal Server Error #3095). Consistent with the precedent just set, and blunt — it forecloses (2) if anyone later wants it.
  4. Leave it. Defensible, given how narrow the path is; the cost is that the failure mode is a silently emptied UI.

I lean to (1). (2) is the right answer only if conditional reads are meant to be a first-class idiom for server functions, which is a product question rather than a bug.

Related

Surfaced while verifying #3096. #3097 covers the other half of "the status says one thing and the caller sees another".

Activity

  1. ryansolid commented on Aug 30, 2026

    @ryansolid
    Member

    Landed the middle path in da50a36: the 304 keeps forwarding untouched — it is real HTTP for unscripted callers and the natural conditional-read answer — but the dev build now warns when a scripted call is answered with one, naming the function and pointing at the supported shape.

    The framing that stuck: the scripted transport sends no conditional headers, so a hand-rolled respond(undefined, { status: 304 }) answers a question the caller never asked — the bodiless answer resolves the call to undefined and consumer state clears, which is the silent data loss you hit. Conditional reads belong to the browser on a GET-declared function with ETag/Cache-Control, where the 304 revalidates the HTTP cache and the caller replays the cached 200 without ever seeing it. RFC 10's GET section now says this in prose too.

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