Skip to content

Commit 47d2346

Browse files
authored
Merge pull request #4062 from solidjs/claude/project-thread-271xwi
Live holes keep updating with nested For and condition memos; add server-dbmon example
2 parents 2da0f8e + b972757 commit 47d2346

21 files changed

Lines changed: 819 additions & 101 deletions

File tree

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 holes keep updating when their markup creates reactive scopes (a nested `<For>`, a compiler condition memo such as `{m.usage && …}`, a component). Each re-render runs in a throwaway scope disposed once its markup is out; only a scope still waiting on async work closes the hole (#4023).

‎documentation/solid-2.0/08-dev-diagnostics.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,9 +660,9 @@ Check (`warn`, dev only, `kind: "ssr"`). A boundary whose content turned out to
660660

661661
#### `SSR_LIVE_HOLE_LATCHED`
662662

663-
**Message:** "[SSR_LIVE_HOLE_LATCHED] A live markup hole stopped updating: re-running it created reactive scopes (a component, a memo, or a compiler condition memo such as {m.usage && …}), so it cannot re-run and keeps the markup it last sent. Read a property used in a condition into a local first (const usage = m.usage), and keep components and memos out of markup that re-renders from a live source."
663+
**Message:** "[SSR_LIVE_HOLE_LATCHED] A live markup hole stopped updating: re-running it created a reactive scope that waits on async work (a memo over a fetch or a stream), so it cannot re-run and keeps the markup it last sent. Create async sources outside markup that re-renders from a live source (in the component body, not inside the hole's expression)."
664664

665-
Check (`warn`, dev only, `kind: "ssr"`). A live hole's first render escalated before its impure part ran, so it shipped its markers; the first re-evaluation then created reactive scopes or emitted slot records, and the live-hole engine's impurity gate closed the binding (#4023). Before this check that was silent: the markup simply stopped updating. The common cause is a condition on a property (`{m.usage && …}`, `{m.usage ? … : …}`), which the compiler memoizes; a local identifier condition is not memoized and stays live. Once per binding. `data.cause` (`"owners"` or `"records"`). Located by owner (the component the hole is in); the expression itself is not named, since keeping it on every hole would cost the render. A hole that latches on its first render (never opened) is not reported.
665+
Check (`warn`, dev only, `kind: "ssr"`). A live hole's first render escalated before its impure part ran, so it shipped its markers; a re-evaluation then created a reactive scope still waiting on async work, or emitted slot records, and the live-hole engine's impurity gate closed the binding (#4023). Each re-evaluation runs in a throwaway scope disposed once its markup is out, so scopes that finish synchronously (a nested `<For>`, a compiler condition memo such as `{m.usage && …}`, a component) keep the hole live; an async source re-created on every re-run would restart forever, so that one closes it. Once per binding. `data.cause` (`"owners"` or `"records"`). Located by owner (the component the hole is in); the expression itself is not named, since keeping it on every hole would cost the render. A hole that latches on its first render (never opened) is not reported.
666666

667667
#### `SSR_UNDECLARED_LIVE_SOURCE`
668668

‎examples/server-dbmon/README.md‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# DBMon — a live server-rendered dashboard
2+
3+
The classic DBMon benchmark, as a page the server keeps rendering. A
4+
simulation of monitored databases lives on the server and ticks while anyone
5+
is watching; every tick re-renders the table on the server and streams it to
6+
the browser as HTML.
7+
8+
Two routes render the same simulation, so they can be compared:
9+
10+
- `/` — the live view. The table is a server component behind a `live()`
11+
address; the browser only applies the markup it receives.
12+
- `/spa` — the client-rendered twin. The server streams the databases as
13+
data and the browser renders them with keyed `<For>`s.
14+
15+
```sh
16+
pnpm dev # https://localhost:3020/ (self-signed cert)
17+
pnpm build && pnpm start # production harness, http://localhost:3020/
18+
```
19+
20+
Knobs (environment, read by the server):
21+
22+
```sh
23+
DBMON_ROWS=200 pnpm start # clusters; each is a primary and a replica row (default 50)
24+
DBMON_MUTATIONS=0.2 pnpm start # share of rows that change per tick (default 0.5)
25+
DBMON_FPS=10 pnpm start # ticks per second (default 5)
26+
```
27+
28+
Styles come from Solid's [dbmon example](https://github.com/ryansolid/solid-dbmon).

‎examples/server-dbmon/package.json‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "server-dbmon-example",
3+
"description": "DBMon as a live server component: a monitoring dashboard whose data lives on the server, rendered there and streamed to every open tab as it changes",
4+
"version": "0.0.0",
5+
"private": true,
6+
"author": "Ryan Carniato",
7+
"license": "MIT",
8+
"type": "module",
9+
"scripts": {
10+
"dev": "vite",
11+
"build": "vite build",
12+
"start": "node server.js",
13+
"typecheck": "tsc --noEmit"
14+
},
15+
"dependencies": {
16+
"@solidjs/router": "2.0.0-next.39",
17+
"@solidjs/web": "workspace:*",
18+
"solid-js": "workspace:*"
19+
},
20+
"devDependencies": {
21+
"@solidjs/vite-plugin": "3.0.0-next.50",
22+
"@vitejs/plugin-basic-ssl": "^2.3.0",
23+
"vite": "^8.0.0"
24+
}
25+
}
664 Bytes
Binary file not shown.

‎examples/server-dbmon/server.js‎

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
// The whole production server: static client assets plus one import — the
2+
// built server bundle's `handleRequest`, an adapter-agnostic web
3+
// `Request -> Response` that streams the SSR render, resolves hashed assets
4+
// through the build manifest, and serves the `/_server` endpoint. The node
5+
// <-> web plumbing below is the only glue.
6+
//
7+
// Responses are compressed because every deployed host compresses text, and
8+
// a benchmark against an uncompressed origin measures the harness rather than
9+
// the app. Brotli quality 4 keeps per-chunk flushes cheap while still ~6x on
10+
// HTML; each SSR chunk is flushed so streaming boundaries survive.
11+
import { createServer } from "node:http";
12+
import { readFileSync } from "node:fs";
13+
import { Readable } from "node:stream";
14+
import { fileURLToPath } from "node:url";
15+
import path from "node:path";
16+
import { brotliCompressSync, createBrotliCompress, createGzip, constants } from "node:zlib";
17+
import { handleRequest } from "./dist/server/server.js";
18+
19+
const root = path.dirname(fileURLToPath(import.meta.url));
20+
const PORT = process.env.PORT || 3020;
21+
22+
const MIME = {
23+
".js": "application/javascript",
24+
".css": "text/css",
25+
".html": "text/html",
26+
".json": "application/json",
27+
".ico": "image/x-icon",
28+
".svg": "image/svg+xml"
29+
};
30+
31+
/** Negotiated streaming compressor piped into `res`, or null for identity. */
32+
function encoder(req, res) {
33+
const accepts = req.headers["accept-encoding"] || "";
34+
let stream;
35+
if (/\bbr\b/.test(accepts)) {
36+
res.setHeader("Content-Encoding", "br");
37+
stream = createBrotliCompress({ params: { [constants.BROTLI_PARAM_QUALITY]: 4 } });
38+
} else if (/\bgzip\b/.test(accepts)) {
39+
res.setHeader("Content-Encoding", "gzip");
40+
stream = createGzip();
41+
} else return null;
42+
stream.pipe(res);
43+
return stream;
44+
}
45+
46+
// Static assets compress once at a higher quality — they're cached, not streamed.
47+
const staticBrotli = new Map();
48+
49+
function webRequest(req, signal) {
50+
const url = new URL(req.url || "/", `http://${req.headers.host || `localhost:${PORT}`}`);
51+
const method = req.method || "GET";
52+
const body = method === "GET" || method === "HEAD" ? undefined : Readable.toWeb(req);
53+
return new Request(url, {
54+
method,
55+
headers: req.headers,
56+
body,
57+
signal,
58+
...(body ? { duplex: "half" } : {})
59+
});
60+
}
61+
62+
createServer(async (req, res) => {
63+
const url = req.url || "/";
64+
65+
if (url !== "/" && !url.includes("..")) {
66+
const file = url.split("?")[0];
67+
try {
68+
const content = readFileSync(path.resolve(root, "dist/client" + file));
69+
const headers = {
70+
"Content-Type": MIME[path.extname(file)] ?? "application/octet-stream",
71+
"Cache-Control": "public, max-age=3600"
72+
};
73+
if (/\bbr\b/.test(req.headers["accept-encoding"] || "")) {
74+
let compressed = staticBrotli.get(file);
75+
if (!compressed) {
76+
compressed = brotliCompressSync(content, {
77+
params: { [constants.BROTLI_PARAM_QUALITY]: 9 }
78+
});
79+
staticBrotli.set(file, compressed);
80+
}
81+
res.writeHead(200, { ...headers, "Content-Encoding": "br" });
82+
return res.end(compressed);
83+
}
84+
res.writeHead(200, headers);
85+
return res.end(content);
86+
} catch {
87+
// Fall through to the handler (SSR routes, /_server, ...).
88+
}
89+
}
90+
91+
// A tab that closes must end its render: the live table's simulation runs
92+
// only while someone is watching.
93+
const gone = new AbortController();
94+
res.on("close", () => gone.abort());
95+
try {
96+
const response = await handleRequest(webRequest(req, gone.signal));
97+
const cookies = response.headers.getSetCookie?.();
98+
response.headers.forEach((value, key) => {
99+
if (key !== "set-cookie") res.setHeader(key, value);
100+
});
101+
if (cookies?.length) res.setHeader("set-cookie", cookies);
102+
res.statusCode = response.status;
103+
const out = encoder(req, res) ?? res;
104+
if (response.body) {
105+
const reader = response.body.getReader();
106+
gone.signal.addEventListener("abort", () => reader.cancel().catch(() => {}), { once: true });
107+
for (;;) {
108+
const { done, value } = await reader.read();
109+
if (done) break;
110+
out.write(value);
111+
if (out !== res) out.flush();
112+
}
113+
}
114+
out.end();
115+
} catch (e) {
116+
console.error(e);
117+
res.statusCode = 500;
118+
res.end(e.message);
119+
}
120+
}).listen(PORT, () => {
121+
console.log(`DBMon (server components) on http://localhost:${PORT}`);
122+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { HydrationScript, type JSX } from "@solidjs/web";
2+
3+
export default function Document(props: { children?: JSX.Element }) {
4+
return (
5+
<html lang="en">
6+
<head>
7+
<meta charset="utf-8" />
8+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
9+
<meta name="description" content="DBMon rendered on the server and kept live" />
10+
<title>DBMon</title>
11+
<link rel="icon" href="/favicon.ico" />
12+
<HydrationScript />
13+
</head>
14+
<body>{props.children}</body>
15+
</html>
16+
);
17+
}

‎examples/server-dbmon/src/app.css‎

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/* Styles from Solid's dbmon example: https://github.com/ryansolid/solid-dbmon */
2+
body {
3+
color: #333;
4+
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
5+
font-size: 14px;
6+
line-height: 1.42857143;
7+
margin: 0;
8+
}
9+
label {
10+
display: inline-block;
11+
font-weight: 700;
12+
margin-bottom: 5px;
13+
}
14+
input[type="range"] {
15+
display: block;
16+
width: 100%;
17+
}
18+
table {
19+
border-collapse: collapse;
20+
border-spacing: 0;
21+
}
22+
:before,
23+
:after {
24+
box-sizing: border-box;
25+
}
26+
27+
.table > thead > tr > th,
28+
.table > tbody > tr > th,
29+
.table > tfoot > tr > th,
30+
.table > thead > tr > td,
31+
.table > tbody > tr > td,
32+
.table > tfoot > tr > td {
33+
border-top: 1px solid #ddd;
34+
line-height: 1.42857143;
35+
padding: 8px;
36+
vertical-align: top;
37+
}
38+
.table {
39+
width: 100%;
40+
}
41+
.table-striped > tbody > tr:nth-child(odd) > td,
42+
.table-striped > tbody > tr:nth-child(odd) > th {
43+
background: #f9f9f9;
44+
}
45+
46+
.label {
47+
border-radius: 0.25em;
48+
color: #fff;
49+
display: inline;
50+
font-size: 75%;
51+
font-weight: 700;
52+
line-height: 1;
53+
padding: 0.2em 0.6em 0.3em;
54+
text-align: center;
55+
vertical-align: baseline;
56+
white-space: nowrap;
57+
}
58+
.label-success {
59+
background-color: #5cb85c;
60+
}
61+
.label-warning {
62+
background-color: #f0ad4e;
63+
}
64+
65+
.popover {
66+
background-color: #fff;
67+
background-clip: padding-box;
68+
border: 1px solid #ccc;
69+
border: 1px solid rgba(0, 0, 0, 0.2);
70+
border-radius: 6px;
71+
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
72+
display: none;
73+
left: 0;
74+
max-width: 276px;
75+
padding: 1px;
76+
position: absolute;
77+
text-align: left;
78+
top: 0;
79+
white-space: normal;
80+
z-index: 1010;
81+
}
82+
.popover > .arrow:after {
83+
border-width: 10px;
84+
content: "";
85+
}
86+
.popover.left {
87+
margin-left: -10px;
88+
}
89+
.popover.left > .arrow {
90+
border-right-width: 0;
91+
border-left-color: rgba(0, 0, 0, 0.25);
92+
margin-top: -11px;
93+
right: -11px;
94+
top: 50%;
95+
}
96+
.popover.left > .arrow:after {
97+
border-left-color: #fff;
98+
border-right-width: 0;
99+
bottom: -10px;
100+
content: " ";
101+
right: 1px;
102+
}
103+
.popover > .arrow {
104+
border-width: 11px;
105+
}
106+
.popover > .arrow,
107+
.popover > .arrow:after {
108+
border-color: transparent;
109+
border-style: solid;
110+
display: block;
111+
height: 0;
112+
position: absolute;
113+
width: 0;
114+
}
115+
116+
.popover-content {
117+
padding: 9px 14px;
118+
}
119+
120+
.Query {
121+
position: relative;
122+
}
123+
.Query:hover .popover {
124+
display: block;
125+
left: -100%;
126+
width: 100%;
127+
}

‎examples/server-dbmon/src/app.tsx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { Router } from "~/router";
2+
import "./app.css";
3+
4+
export default function App() {
5+
return <Router>{props => props.children}</Router>;
6+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// The dashboard, rendered on the server (`/`) and, for comparison, in the
2+
// browser from streamed data (`/spa`).
3+
import { createRouter, defineRoute } from "@solidjs/router";
4+
import Dashboard from "~/routes/dashboard";
5+
import Spa from "~/routes/spa";
6+
7+
export const Router = createRouter({
8+
routes: [
9+
defineRoute({ path: "/", component: Dashboard }),
10+
defineRoute({ path: "/spa", component: Spa })
11+
]
12+
});

0 commit comments

Comments
 (0)