Skip to content

Commit 9f64ca9

Browse files
ryansolidclaude
andauthored
feat(server-functions): live() implies GET (#4190)
* feat(server-functions): live() implies GET A live source is a read by contract, so live(fn) now declares GET itself on both halves: the server grants GET dispatch, the client connects over the GET transport at the live address. live(GET(fn)) is unchanged. The client's POST-at-the-live-address branch is dead and removed. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01CcxaV3B2Dr9Khbt2G5JmqY * fix(server-functions): client live() reaches GET through the module's RPC seam Importing live alone (a router's liveQuery over a plain producer) no longer pulls the GET transport; a real reference fills the seam first. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01Fmb4aQtDJWoA8CUktR9QoZ --------- Co-authored-by: Claude <[email protected]>
1 parent b0ad1df commit 9f64ca9

18 files changed

Lines changed: 249 additions & 244 deletions

‎.changeset/live-implies-get.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/web": patch
3+
---
4+
5+
`live(fn)` now implies `GET`: a live source is a read by contract, so the declaration grants GET dispatch on the server and connects over the GET transport on the client. `live(GET(fn))` keeps working and is equivalent. The client's POST-at-the-live-address path is gone, which trims live pages by ~144 B minified.

‎documentation/solid-2.0/10-server-functions.md‎

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export const getUser = GET(async (id: string) => {
165165
});
166166
```
167167

168-
Calls go over HTTP GET with arguments codec-encoded in the query string of the call’s data address — cacheable by HTTP infrastructure (a read sends no header of its own, so caches and `<link rel="preload" as="fetch">` match it on the URL alone, and the data address serves the codec shape to every caller, so what a cache stores there is right for anyone who reads it). Arguments too long for a url dispatch over POST instead, which costs the cache entry rather than meeting whichever proxy in the chain draws the line at a 414. Cache headers flow through the handler’s existing header forwarding: `respond(data, { headers: { "cache-control": "max-age=60" } })`. Those headers belong to the call’s own data address: when a page calls the function in-process during SSR, the envelope is unwrapped and only `Set-Cookie` reaches the page’s response (#3910) — a read’s `Cache-Control` never becomes the page’s. A header written through `getRequestEvent().response.headers` is not unwrapped this way; the in-process call runs under a derived event marked `serverOnly`, which tells the two legs apart. `serverFunctionUrl(fn, ...args)` renders that url as a value — for `<link rel="preload" as="fetch" crossorigin href={serverFunctionUrl(getUser, id)} />`, a prefetch, a service-worker warm, or a fetch by hand (decode the answer with `decodeResponse`) — built the way the transport builds it, from the reference (the only thing that knows the call is a GET). It refuses, rather than answering with an address nothing would request, for a reference on the default transport (a POST is not described by its url; `invoke(fn, { priority: "low" }, ...args)` starts such a call early), for arguments that need the codec, and for a url past the POST-fallback length. For a `live(GET(fn))` reference it renders the live address (`<endpoint>/live/<id>?args=…`) — the url that reference's own call requests, a standing event stream to fetch by hand (`curl -N`), not to preload or prefetch (that would open a stream nothing reads; warm a live address by calling the reference, whose readers share one connection); the one-shot url is the inner `GET(fn)`'s. Server-side, the wrapper is identity-flavored — SSR calls stay in-process. Because function-level directives round-trip wrapper calls (above), this needs **no compiler involvement**.
168+
Calls go over HTTP GET with arguments codec-encoded in the query string of the call’s data address — cacheable by HTTP infrastructure (a read sends no header of its own, so caches and `<link rel="preload" as="fetch">` match it on the URL alone, and the data address serves the codec shape to every caller, so what a cache stores there is right for anyone who reads it). Arguments too long for a url dispatch over POST instead, which costs the cache entry rather than meeting whichever proxy in the chain draws the line at a 414. Cache headers flow through the handler’s existing header forwarding: `respond(data, { headers: { "cache-control": "max-age=60" } })`. Those headers belong to the call’s own data address: when a page calls the function in-process during SSR, the envelope is unwrapped and only `Set-Cookie` reaches the page’s response (#3910) — a read’s `Cache-Control` never becomes the page’s. A header written through `getRequestEvent().response.headers` is not unwrapped this way; the in-process call runs under a derived event marked `serverOnly`, which tells the two legs apart. `serverFunctionUrl(fn, ...args)` renders that url as a value — for `<link rel="preload" as="fetch" crossorigin href={serverFunctionUrl(getUser, id)} />`, a prefetch, a service-worker warm, or a fetch by hand (decode the answer with `decodeResponse`) — built the way the transport builds it, from the reference (the only thing that knows the call is a GET). It refuses, rather than answering with an address nothing would request, for a reference on the default transport (a POST is not described by its url; `invoke(fn, { priority: "low" }, ...args)` starts such a call early), for arguments that need the codec, and for a url past the POST-fallback length. For a `live(fn)` reference (live implies `GET`) it renders the live address (`<endpoint>/live/<id>?args=…`) — the url that reference's own call requests, a standing event stream to fetch by hand (`curl -N`), not to preload or prefetch (that would open a stream nothing reads; warm a live address by calling the reference, whose readers share one connection); the one-shot url is a plain `GET(fn)`'s. Server-side, the wrapper is identity-flavored — SSR calls stay in-process. Because function-level directives round-trip wrapper calls (above), this needs **no compiler involvement**.
169169

170170
Conditional reads belong here too, and to the **browser**: set `ETag`/`Cache-Control` on a GET-declared read and the browser owns the conditional exchange — it sends `If-None-Match`, receives the 304, and replays its cached 200 without the caller ever seeing a 304. Answering a _scripted_ call with a hand-rolled `respond(undefined, { status: 304 })` answers a question the transport never asked — it sends no conditional headers — so the bodiless answer resolves the call to `undefined`, which reads as data loss. The dev build warns when a scripted call is answered with a 304 (#3101).
171171

@@ -203,17 +203,15 @@ The reference contract shrinks accordingly (no compatibility shims):
203203

204204
#### `live(fn)`: a standing answer, for the response's lifetime (shipped over the top-level iterable; extended 2026-09-22/23, extension built — Stage 8 Phase A, plan in `documentation/plans/stage8-connection-transport.md`)
205205

206-
`live` declares that a server function's answer is a **standing answer**: the current state of one logical query, which the source re-yields on any invocation, and which the caller wants to keep receiving for as long as it is reading. It is a _client_ declaration — the server half is identity-flavored, in-process SSR calls have no wire — and it composes outermost, because its behavior wraps the call: `live(GET(fn))`.
206+
`live` declares that a server function's answer is a **standing answer**: the current state of one logical query, which the source re-yields on any invocation, and which the caller wants to keep receiving for as long as it is reading. It is a _client_ declaration — the server half is identity-flavored, in-process SSR calls have no wire — and it implies `GET`: a standing answer is a read by contract, so `live(fn)` connects over the GET transport and takes on `GET`'s safe-read obligations. An explicit `live(GET(fn))` is equivalent; live stays outermost, because its behavior wraps the call.
207207

208208
```ts
209-
import { live, GET } from "@solidjs/web/server-functions";
209+
import { live } from "@solidjs/web/server-functions";
210210

211-
export const price = live(
212-
GET(async function* (symbol: string) {
213-
"use server";
214-
for await (const tick of subscribe(symbol)) yield tick.price;
215-
})
216-
);
211+
export const price = live(async function* (symbol: string) {
212+
"use server";
213+
for await (const tick of subscribe(symbol)) yield tick.price;
214+
});
217215

218216
const src = price("ACME"); // the reconnecting iterable itself, synchronously
219217
src.onstatus = setStatus; // optional: "connected" | "reconnecting" | "closed"
@@ -236,13 +234,11 @@ const current = createMemo(() => src);
236234
**Server components.** A server component is a server function whose answer is a component ([RFC 11](11-server-components.md)); its render is a stream of markup over the same connection. That makes it a nested-async answer in the sense above, and `live` covers it with no further vocabulary:
237235

238236
```tsx
239-
export const feed = live(
240-
GET(async (room: string) => {
241-
"use server";
242-
const messages = subscribeRoom(room); // raw async iterable; the component reads it
243-
return (props: { compose: Slot }) => <Feed messages={messages} compose={props.compose} />;
244-
})
245-
);
237+
export const feed = live(async (room: string) => {
238+
"use server";
239+
const messages = subscribeRoom(room); // raw async iterable; the component reads it
240+
return (props: { compose: Slot }) => <Feed messages={messages} compose={props.compose} />;
241+
});
246242

247243
// client
248244
import { dynamicComponent } from "solid-js";

‎examples/board/README.md‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,10 @@ server function: an answer the tab keeps open. Each time the board changes it
5050
yields the whole board again.
5151

5252
```tsx
53-
const getBoard = live(
54-
GET(async function* (client: string | null): AsyncGenerator<Board> {
55-
"use server";
56-
yield* db.watchBoard(client, getRequestEvent()?.request.signal);
57-
})
58-
);
53+
const getBoard = live(async function* (client: string | null): AsyncGenerator<Board> {
54+
"use server";
55+
yield* db.watchBoard(client, getRequestEvent()?.request.signal);
56+
});
5957

6058
const [board, setBoard] = createOptimisticStore<Board>(() => getBoard(me()?.id ?? null), …);
6159
```

‎examples/board/src/board.tsx‎

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030
} from "solid-js";
3131
import type { JSX } from "@solidjs/web";
3232
import { getRequestEvent, isServer } from "@solidjs/web";
33-
import { GET, live } from "@solidjs/web/server-functions";
33+
import { live } from "@solidjs/web/server-functions";
3434
import { createDrag, type Over } from "~/drag";
3535
import { createFlip } from "~/flip";
3636
import { IdentityContext, mintId } from "~/identity";
@@ -45,29 +45,25 @@ import type { Board, Card, Identity, Member } from "~/types";
4545

4646
// The document's render calls this with `null` (the server cannot know the
4747
// tab) and the browser calls it with the tab's id once it has one.
48-
const getBoard = live(
49-
GET(async function* (client: string | null): AsyncGenerator<Board> {
50-
"use server";
51-
// The response's lifetime: aborted when its client goes away, which ends
52-
// the watcher now rather than at the board's next change.
53-
yield* db.watchBoard(client, getRequestEvent()?.request.signal);
54-
})
55-
);
48+
const getBoard = live(async function* (client: string | null): AsyncGenerator<Board> {
49+
"use server";
50+
// The response's lifetime: aborted when its client goes away, which ends
51+
// the watcher now rather than at the board's next change.
52+
yield* db.watchBoard(client, getRequestEvent()?.request.signal);
53+
});
5654

5755
// Who has the board open. Joining is the connection: a tab is present while
5856
// this response is open, and the generator's `finally` is what leaving
5957
// means. The document's render has no identity and only watches.
60-
const getPresence = live(
61-
GET(async function* (me: Identity | null): AsyncGenerator<Member[]> {
62-
"use server";
63-
const leave = me ? presence.join(me) : () => {};
64-
try {
65-
yield* presence.watchMembers(getRequestEvent()?.request.signal);
66-
} finally {
67-
leave();
68-
}
69-
})
70-
);
58+
const getPresence = live(async function* (me: Identity | null): AsyncGenerator<Member[]> {
59+
"use server";
60+
const leave = me ? presence.join(me) : () => {};
61+
try {
62+
yield* presence.watchMembers(getRequestEvent()?.request.signal);
63+
} finally {
64+
leave();
65+
}
66+
});
7167

7268
// The writes answer nothing: what they did arrives on `getBoard`'s stream. A
7369
// create names its row with an id the browser minted; a write to a row that

‎examples/chat/README.md‎

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -80,24 +80,22 @@ fact about the thread, not something left hanging.
8080

8181
```tsx
8282
const getThread = liveQuery(
83-
live(
84-
GET(async (id: string) => {
85-
"use server";
86-
return (props: { composer: ComposerSlot; copyCode: CopySlot }) => {
87-
const view = createMemo(() => db.watchThread(id, gone.signal));
88-
return (
89-
<article class="thread">
90-
…
91-
<ol class="messages">
92-
{view().messages.filter(m => m.status !== "generating").map(…)}
93-
{view().messages.filter(m => m.status === "generating").map(…)}
94-
</ol>
95-
<props.composer $key={id} threadId={id} seen={…} busy={…} />
96-
</article>
97-
);
98-
};
99-
})
100-
),
83+
live(async (id: string) => {
84+
"use server";
85+
return (props: { composer: ComposerSlot; copyCode: CopySlot }) => {
86+
const view = createMemo(() => db.watchThread(id, gone.signal));
87+
return (
88+
<article class="thread">
89+
…
90+
<ol class="messages">
91+
{view().messages.filter(m => m.status !== "generating").map(…)}
92+
{view().messages.filter(m => m.status === "generating").map(…)}
93+
</ol>
94+
<props.composer $key={id} threadId={id} seen={…} busy={…} />
95+
</article>
96+
);
97+
};
98+
}),
10199
"thread"
102100
);
103101
```

‎examples/chat/src/router.tsx‎

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// it.
66
import { createMemo, onCleanup } from "solid-js";
77
import { getRequestEvent } from "@solidjs/web";
8-
import { GET, live } from "@solidjs/web/server-functions";
8+
import { live } from "@solidjs/web/server-functions";
99
import { createRouter, defineRoute, liveQuery } from "@solidjs/router";
1010
import Home from "~/routes/home";
1111
import Thread from "~/routes/thread";
@@ -17,33 +17,31 @@ import * as db from "~/server/db";
1717
// reply finishes, a thread is renamed or deleted. The router marks the link
1818
// to the page you are on.
1919
export const getThreads = liveQuery(
20-
live(
21-
GET(async () => {
22-
"use server";
23-
return () => {
24-
const gone = new AbortController();
25-
onCleanup(() => gone.abort());
26-
getRequestEvent()?.request.signal.addEventListener("abort", () => gone.abort(), {
27-
once: true
28-
});
29-
const threads = createMemo(() => db.watchThreads(gone.signal));
30-
return (
31-
<ul class="threads">
32-
{threads().map(thread => {
33-
const writing = thread.generating ? "writing" : undefined;
34-
return (
35-
<li>
36-
<a href={`/t/${thread.id}`} class={writing}>
37-
{thread.title}
38-
</a>
39-
</li>
40-
);
41-
})}
42-
</ul>
43-
);
44-
};
45-
})
46-
),
20+
live(async () => {
21+
"use server";
22+
return () => {
23+
const gone = new AbortController();
24+
onCleanup(() => gone.abort());
25+
getRequestEvent()?.request.signal.addEventListener("abort", () => gone.abort(), {
26+
once: true
27+
});
28+
const threads = createMemo(() => db.watchThreads(gone.signal));
29+
return (
30+
<ul class="threads">
31+
{threads().map(thread => {
32+
const writing = thread.generating ? "writing" : undefined;
33+
return (
34+
<li>
35+
<a href={`/t/${thread.id}`} class={writing}>
36+
{thread.title}
37+
</a>
38+
</li>
39+
);
40+
})}
41+
</ul>
42+
);
43+
};
44+
}),
4745
"threads"
4846
);
4947

‎examples/chat/src/routes/thread.tsx‎

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// code block's Copy button, a client component in a slot in that block.
1414
import { createMemo, For, Loading, onCleanup } from "solid-js";
1515
import { dynamicComponent, getRequestEvent, redirect } from "@solidjs/web";
16-
import { GET, live } from "@solidjs/web/server-functions";
16+
import { live } from "@solidjs/web/server-functions";
1717
import type { Slot } from "@solidjs/web/frames";
1818
import { formAction, liveQuery, type RouteSectionProps } from "@solidjs/router";
1919
import Composer from "~/components/composer";
@@ -69,49 +69,47 @@ const deleteThread = formAction(async (id: string) => {
6969
// gives it a key and one connection per thread, and tells the router that
7070
// this address is kept fresh by its own stream.
7171
const getThread = liveQuery(
72-
live(
73-
GET(async (id: string) => {
74-
"use server";
75-
return (props: { composer: ComposerSlot; copyCode: CopySlot }) => {
76-
// This render lives as long as its response. When the tab goes away
77-
// the watcher below is told at once.
78-
const gone = new AbortController();
79-
onCleanup(() => gone.abort());
80-
getRequestEvent()?.request.signal.addEventListener("abort", () => gone.abort(), {
81-
once: true
82-
});
72+
live(async (id: string) => {
73+
"use server";
74+
return (props: { composer: ComposerSlot; copyCode: CopySlot }) => {
75+
// This render lives as long as its response. When the tab goes away
76+
// the watcher below is told at once.
77+
const gone = new AbortController();
78+
onCleanup(() => gone.abort());
79+
getRequestEvent()?.request.signal.addEventListener("abort", () => gone.abort(), {
80+
once: true
81+
});
8382

84-
// The thread as it is stored, again after every write to it.
85-
const view = createMemo(() => db.watchThread(id, gone.signal));
83+
// The thread as it is stored, again after every write to it.
84+
const view = createMemo(() => db.watchThread(id, gone.signal));
8685

87-
return (
88-
<article class="thread">
89-
<header class="thread-head">
90-
{headMarkup(view().thread)}
91-
<p class="muted">Answered by {model.modelName()}</p>
92-
</header>
93-
<ol class="messages">
94-
{/* A row the server has already rendered is kept while its
86+
return (
87+
<article class="thread">
88+
<header class="thread-head">
89+
{headMarkup(view().thread)}
90+
<p class="muted">Answered by {model.modelName()}</p>
91+
</header>
92+
<ol class="messages">
93+
{/* A row the server has already rendered is kept while its
9594
message is unchanged, so a streaming reply doesn't render
9695
the whole history again on every write (#4056). */}
97-
<For each={view().messages.filter(m => m.status !== "generating")}>
98-
{message => messageMarkup(message, props.copyCode)}
99-
</For>
100-
{messagesMarkup(view().messages, true, props.copyCode)}
101-
</ol>
102-
{/* Keyed by thread: going to another conversation is a new
96+
<For each={view().messages.filter(m => m.status !== "generating")}>
97+
{message => messageMarkup(message, props.copyCode)}
98+
</For>
99+
{messagesMarkup(view().messages, true, props.copyCode)}
100+
</ol>
101+
{/* Keyed by thread: going to another conversation is a new
103102
composer, so a half-typed message stays with its thread. */}
104-
<props.composer
105-
$key={id}
106-
threadId={id}
107-
seen={view().messages.map(m => m.id)}
108-
busy={view().messages.some(m => m.status === "generating")}
109-
/>
110-
</article>
111-
);
112-
};
113-
})
114-
),
103+
<props.composer
104+
$key={id}
105+
threadId={id}
106+
seen={view().messages.map(m => m.id)}
107+
busy={view().messages.some(m => m.status === "generating")}
108+
/>
109+
</article>
110+
);
111+
};
112+
}),
115113
"thread"
116114
);
117115

‎examples/chat/src/server/model.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ This thread is one. It renders on the server, from the messages the server has s
4444
4545
\`\`\`jsx
4646
const getThread = liveQuery(
47-
live(GET(async (id) => {
47+
live(async (id) => {
4848
"use server";
4949
return props => <Thread id={id} composer={props.composer} />;
50-
})),
50+
}),
5151
"thread"
5252
);
5353
\`\`\`

0 commit comments

Comments
 (0)