Skip to content

Commit d893d0b

Browse files
committed
Merge remote-tracking branch 'origin/next' into pr365-merge
2 parents 256c25d + 8532f56 commit d893d0b

19 files changed

Lines changed: 1606 additions & 137 deletions

File tree

‎.changeset/ride-solid-rc-9.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@solidjs/vite-plugin': patch
3+
---
4+
5+
Require solid-js / @solidjs/web 2.0.0-rc.9 (peer floor) and compile with @solidjs/compiler / @solidjs/babel-plugin rc.9 — runtime and compiler move in lockstep. The rc.9 compilers emit output only the rc.9 runtime understands, so this floor is a hard requirement, not policy: native elements with several spread sources compile to the runtimes' array form (`spread(el, [a, b], …)` on the client, `ssrElement(tag, [a, b], …)` on the server — no `mergeProps()` proxy, no memo, no hydration id; #3418/#3419/#3423) which only rc.9's `@solidjs/web` accepts; delegated event handlers move off Solid 1's `$$<type>` element key onto `_$$<type>` in both compiled output and the runtime's document delegate, so an rc.8 runtime would never fire an rc.9-compiled `onClick` (and vice versa); and under `componentNames` — which the plugin already turns on for its dev and observe postures — SSR output keeps `createComponent(Comp, props, "Comp")` so the server runtime's observe/dev tier labels the owner and a server finding's `ownerPath` reads `<App> › <Page>` like the client's. Nothing in the plugin itself had to change for rc.9: the new `observe` / `development` export conditions on `@solidjs/web`'s server-functions and frames client entries (and `observe` on every server entry) are picked up by the condition lists the plugin already installs, and the new `solid-js/internal` subpath is covered by the existing `solid-js` inlining.

‎.changeset/start-node-entry.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@solidjs/vite-plugin': minor
3+
---
4+
5+
`start.node`: the build emits a ready-to-run Node server. With `start: { node: true }` the ssr build writes `dist/server/node.js` beside `server.js` — `node dist/server/node.js` (env `PORT`, default 3000, and `HOST`) serves the client build statically (files under `build.assetsDir` as `Cache-Control: public, max-age=31536000, immutable`, everything else `public, max-age=0, must-revalidate` with `Last-Modified`; a reasonable MIME table, `HEAD`, dot-segment paths and `..` traversal refused) and hands every other request to `handleRequest` with the raw Node request as `nativeEvent`, so `getRequestEvent().nativeEvent` answers the same as under `vite dev` and `vite preview`. The node<->web bridge is the plugin's own `src/http.ts` — the code the dev and preview middlewares already run (HTTP/2 pseudo-headers, `https:` on TLS sockets, client disconnects as the request's `AbortSignal`, HEAD short-circuit, `set-cookie` split, backpressure that also settles on close) — shipped as a separate build artifact of the package (`dist/node-entry.mjs`) that the plugin reads at build time and emits under a small generated header carrying the emit-time constants (client dir relative to the server dir, `assetsDir`, `base`, the mode). The file is ESM with no dependency beyond `node:*` and `./server.js`, listens only when run directly, and exports `listener` (the `(req, res)` function, mountable into `http.createServer`, Express, Fastify), `createListener({ static?, event? })` — `static: false` leaves files and the client-mode `index.html` fallback to a framework such as `express.static` or a CDN and keeps only the bridge; `event: (req) => fields` merges extra request-event fields over `{ nativeEvent: req }` — and `serve({ port?, host?, static?, event? })`.
6+
7+
Why: the fullstack templates shipped a hand-written `server.js` whose bulk was this generic Node bridge, copied into every scaffold and baked into the CLI, so bridge fixes never reached users — and it looked custom-made. Node is the one mainstream runtime without a fetch-shaped server API (Workers, Deno, Bun, Netlify, Nitro consume the server bundle's `{ fetch }` directly), so the gap is Node-only and belongs in the build output. It is a `start.*` option, not `ssr.*` (`ssr` stays boolean-only), and applies to both start modes: SSR mode renders pages; client mode with `serverFunctions` (which keeps `dist/server`) serves the static client with an `index.html` history fallback for HTML navigations plus the endpoint. `node.js` is an emitted asset, never a second build input — `server.js` and its `handleRequest` / `{ fetch }` contracts are unchanged, and nothing changes without the option. Where no server bundle exists (client mode without `serverFunctions`, or `start.external`) the build warns and emits nothing. Compression/proxy stance unchanged: plain HTTP, put a reverse proxy or CDN in front. Follow-ups this unlocks: the templates drop `server.js` and point their `start` script at `node dist/server/node.js`; create-solid drops its baked `SERVER_JS` constant.

‎README.md‎

Lines changed: 77 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ The object form carries the options (`start: true` is pure sugar for
192192
`start: {}` — both mean the identical start mode with defaults, and
193193
`false`/absent means off): `app`, `document`, `entryServer`, `entryClient`,
194194
`middleware`, `setup`, `renderMode`, `env`, `devtools`, `errorBoundary`,
195-
`css`, `external`, all documented below.
195+
`css`, `external`, `node`, all documented below.
196196

197197
Install `@solidjs/start-devtools` as a development dependency to add the
198198
development toolbar with runtime errors and server function calls:
@@ -264,12 +264,75 @@ The Fetchable wrapper deliberately accepts only the request. Hosts may pass
264264
environment or execution-context arguments after it; those are not the
265265
Solid options accepted by `handleRequest`'s second parameter.
266266

267-
Among those options, **`event`** is the supported public seam for extending
268-
the request event: its fields spread into the event at creation, so a custom
269-
server entry (or a host wrapper) can attach whatever its platform knows and
270-
read it back anywhere in the request scope with `getRequestEvent()`. The
271-
conventional field name is `nativeEvent` — the platform's raw request
272-
object. A Node entry passes the `IncomingMessage`:
267+
- **Deploying to Node** — **`node`**: Node is the one mainstream runtime
268+
without a fetch-shaped server API (Workers, Deno, Bun, Netlify, and Nitro
269+
consume `{ fetch }` directly), so the build can emit the Node server for
270+
you. With `start: { node: true }` the ssr build writes
271+
`dist/server/node.js` beside `server.js`, and the production start
272+
command is:
273+
274+
```sh
275+
node dist/server/node.js # PORT (default 3000), HOST
276+
```
277+
278+
The entry serves `dist/client` statically — files under
279+
`build.assetsDir` as `Cache-Control: public, max-age=31536000, immutable`
280+
(their names are content hashes), everything else `public, max-age=0,
281+
must-revalidate` with `Last-Modified`; `HEAD` supported, dot-segment
282+
paths and `..` traversal refused — and hands every other request to
283+
`handleRequest` with the raw Node request as `nativeEvent`, so
284+
`getRequestEvent().nativeEvent` is the `IncomingMessage` (client IP:
285+
`event.nativeEvent.socket.remoteAddress`; behind a proxy read the
286+
forwarding headers off `event.request` instead, only when you trust the
287+
proxy). The node<->web bridge is the plugin's own — the same code the dev
288+
and preview middlewares run: HTTP/2 pseudo-headers, `https:` on TLS
289+
sockets, client disconnects as the request's `AbortSignal`, HEAD
290+
short-circuit, `set-cookie` split, backpressure that also settles when
291+
the client goes away. Errors log to `console.error` and answer 500. The
292+
file is ESM, depends on nothing but `node:*` and `./server.js`, and
293+
exports `listener` — the `(req, res)` function — plus
294+
`createListener(options?)` and `serve(options?)`, so it composes with an
295+
existing server. With Express, either let the entry serve everything or
296+
keep only the bridge behind Express's own static handling:
297+
298+
```js
299+
import express from 'express';
300+
import compression from 'compression';
301+
import { listener, createListener } from './dist/server/node.js';
302+
303+
const app = express();
304+
app.use(compression());
305+
app.use(listener); // static + pages + server functions
306+
// — or — let Express own static files (point it at dist/client):
307+
app.use(express.static('dist/client', { immutable: true, maxAge: '1y' }));
308+
app.use(createListener({ static: false }));
309+
app.listen(process.env.PORT || 3000);
310+
```
311+
312+
`createListener({ static: false })` skips the file lookup and, in client
313+
mode, the `index.html` history fallback — the framework owns both.
314+
`createListener({ event: (req) => ({ ... }) })` merges extra fields over
315+
`{ nativeEvent: req }` into the request event. `serve({ port, host, static,
316+
event })` takes the same two options on top of the listen address.
317+
318+
`node.js` is an emitted asset, not a second build input: `server.js` and
319+
its `handleRequest` / `{ fetch }` contracts are unchanged. It applies to
320+
both start modes — in client mode with `serverFunctions` (which keeps
321+
`dist/server`) the entry serves the static client with an `index.html`
322+
history fallback for HTML navigations plus the endpoint. Nothing is
323+
emitted where no server bundle exists (client mode without
324+
`serverFunctions`, or `start.external`); the build warns. The
325+
compression/proxy stance is unchanged: the entry speaks plain HTTP —
326+
terminate TLS and compress at the reverse proxy or CDN in front of it.
327+
328+
Among the `handleRequest` options, **`event`** is the supported public seam
329+
for extending the request event: its fields spread into the event at
330+
creation, so a custom server entry (or a host wrapper) can attach whatever
331+
its platform knows and read it back anywhere in the request scope with
332+
`getRequestEvent()`. The conventional field name is `nativeEvent` — the
333+
platform's raw request object. This is what the emitted `node.js` does; a
334+
hand-written Node entry (the custom-server recipe) passes the
335+
`IncomingMessage` the same way:
273336

274337
```js
275338
import { createServer } from 'node:http';
@@ -292,12 +355,13 @@ event.nativeEvent; // the Node IncomingMessage the entry passed
292355

293356
The plugin's own dev and preview middlewares (and the server-function dev
294357
middleware) pass `event: { nativeEvent: req }` with the Node request, so
295-
`getRequestEvent().nativeEvent` answers the same under `vite dev` and
296-
`vite preview` as behind a Node entry written like the above. For the
297-
client's IP on bare Node, read `event.nativeEvent.socket.remoteAddress`;
298-
behind a proxy or load balancer that address is the proxy's, so read the
299-
forwarding headers off `event.request` instead (`x-forwarded-for` and
300-
friends) — only when you trust the proxy that set them.
358+
`getRequestEvent().nativeEvent` answers the same under `vite dev`,
359+
`vite preview`, and `node dist/server/node.js` as behind a Node entry
360+
written like the above. For the client's IP on bare Node, read
361+
`event.nativeEvent.socket.remoteAddress`; behind a proxy or load balancer
362+
that address is the proxy's, so read the forwarding headers off
363+
`event.request` instead (`x-forwarded-for` and friends) — only when you
364+
trust the proxy that set them.
301365

302366
- **Preview**: `vite build && vite preview` runs the production artifact
303367
with no server file — Vite's preview statics serve `dist/client`, and

‎examples/start-client/src/App.tsx‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { createSignal, lazy, Loading } from 'solid-js';
2+
import { ping } from './ping';
23
import './App.css';
34

45
// A lazy chunk proves code splitting + chunk CSS keep working in SPA mode
@@ -7,6 +8,7 @@ const LazySection = lazy(() => import('./LazySection.tsx'));
78

89
export default function App() {
910
const [count, setCount] = createSignal(0);
11+
const [pong, setPong] = createSignal('');
1012

1113
return (
1214
<main>
@@ -16,6 +18,12 @@ export default function App() {
1618
Increment
1719
</button>
1820
<span id="count">{count()}</span>
21+
{/* node mode: a server-function round-trip over /_server through the
22+
emitted Node entry (plain client code when serverFunctions is off). */}
23+
<button id="ping" onClick={async () => setPong(await ping('node'))}>
24+
Ping
25+
</button>
26+
<span id="pong">{pong()}</span>
1927
<Loading fallback={<p>loading…</p>}>
2028
<LazySection />
2129
</Loading>

‎examples/start-client/src/ping.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// A server function for the node mode (test/run.mjs, SOLID_START_NODE=1 with
2+
// `serverFunctions: true`): the emitted Node entry must dispatch the
3+
// /_server endpoint through the kept dist/server handler while pages stay
4+
// static. In the other modes `serverFunctions` is off and the directive is
5+
// inert — `ping` is then plain client code, and the app behaves identically.
6+
'use server';
7+
8+
export async function ping(name: string) {
9+
return `pong:${name}`;
10+
}

0 commit comments

Comments
 (0)