Skip to content

Commit 6232d18

Browse files
ryansolidclaude
andauthored
examples: todos-server works without JS; web: unchanged holes ship once (#3999)
* examples: todos-server renders whole for no-JS; fix HN and notes nits todos-server streamed its list behind a Loading fallback, so a first load without JavaScript never showed it. It now renders in the vite plugin's async mode, and the README says so instead of claiming the list lands before the first flush. Both hackernews twins printed "ago ago" on thread pages (time_ago already ends with it) and linked deleted comments to /users/undefined. The notes sidebar chevron had its Expand/Collapse alt text swapped. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * examples: todos-server retries are forms, so they work without JS The Retry controls under the list and beside the add field were buttons with click handlers, dead on the no-JavaScript path that renders them from the flash cookie. Each is now a form on the same action, built from the failed submission's input; with JavaScript the router submits it like any other form. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * examples: hackernews keeps the plain author link on deleted comments The conditional link added a re-emittable hole per comment, and each one is currently sent twice (1,376 extra records, about 216 KB on the big thread). Deleted comments go back to linking /users/undefined until the runtime stops re-sending unchanged holes. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * fix(web): do not re-send an unchanged hole that holds an addressed element A markup hole's baseline compared without the lh comment markers but with the data-lha addresses the first render writes on elements with dynamic attributes. A sweep's re-evaluation mints none, so every such hole read as changed and shipped a second time as a hole record on the document's live channel: todos-server's whole list, each hackernews feed title. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 4f78e39 commit 6232d18

12 files changed

Lines changed: 119 additions & 29 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+
A server component's markup hole that contains an element with a dynamic attribute is no longer sent twice. The first render writes a `data-lha` address on such an element and the sweep's re-evaluation does not, so the unchanged hole compared as changed and its markup shipped again as a `hole` record on the document's live channel. The baseline now ignores those addresses, as it already ignored the `lh` comment markers. The markup that ships is unchanged.

‎examples/hackernews-spa/src/components/comment.tsx‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ const Comment: Component<{ comment: CommentDefinition }> = props => {
55
return (
66
<li class="comment">
77
<div class="by">
8-
<a href={`/users/${props.comment.user}`}>{props.comment.user}</a> {props.comment.time_ago}{" "}
9-
ago
8+
<a href={`/users/${props.comment.user}`}>{props.comment.user}</a> {props.comment.time_ago}
109
</div>
1110
<div class="text" innerHTML={props.comment.content} />
1211
<Show when={props.comment.comments.length}>

‎examples/hackernews-spa/src/routes/story.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default function Story(props: RouteProps<Path>) {
3434
</Show>
3535
<p class="meta">
3636
{story().points} points | by <a href={`/users/${story().user}`}>{story().user}</a>{" "}
37-
{story().time_ago} ago
37+
{story().time_ago}
3838
</p>
3939
</div>
4040
<div class="item-view-comments">

‎examples/hackernews/src/routes/story.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const getStory = GET(async ({ params }: ServerRouteArgs<RouteParams<"/stories/:i
1818
{story.domain ? <span class="host">({story.domain})</span> : null}
1919
<p class="meta">
2020
{story.points} points | by <a href={`/users/${story.user}`}>{story.user}</a>{" "}
21-
{story.time_ago} ago
21+
{story.time_ago}
2222
</p>
2323
</div>
2424
<div class="item-view-comments">
@@ -46,7 +46,7 @@ function Comment(props: { comment: CommentDefinition }) {
4646
return (
4747
<li class="comment">
4848
<div class="by">
49-
<a href={`/users/${c.user}`}>{c.user}</a> {c.time_ago} ago
49+
<a href={`/users/${c.user}`}>{c.user}</a> {c.time_ago}
5050
</div>
5151
<div class="text" innerHTML={c.content} />
5252
{c.comments.length ? (

‎examples/notes/src/components/SidebarNoteContent.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ export default function SidebarNoteContent(props: {
6868
>
6969
<Show
7070
when={isExpanded()}
71-
fallback={<img src="/chevron-down.svg" width="10px" height="10px" alt="Collapse" />}
71+
fallback={<img src="/chevron-down.svg" width="10px" height="10px" alt="Expand" />}
7272
>
73-
<img src="/chevron-up.svg" width="10px" height="10px" alt="Expand" />
73+
<img src="/chevron-up.svg" width="10px" height="10px" alt="Collapse" />
7474
</Show>
7575
</button>
7676
{isExpanded() && props.expandedChildren}

‎examples/todos-server/README.md‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ list's fresh markup.
4848
Without JavaScript the page also has to arrive whole. The server streams by
4949
default: content that settles before the first flush is inlined into the
5050
document, and anything later arrives as markup that a script swaps into
51-
place. This example's reads answer immediately, so the list lands before
52-
the flush — but that is timing, not a guarantee. An app that has to work
53-
without JavaScript renders in the vite plugin's `async` mode
54-
(`start.renderMode`), which waits for the whole page before sending it:
55-
either always, or only for crawlers, chosen per request from the user agent.
51+
place. A streamed list never appears without that script, so this example
52+
renders in the vite plugin's `async` mode (`start: { renderMode: "async" }`
53+
in [vite.config.ts](./vite.config.ts)), which waits for the whole page
54+
before sending it. The mode can also be chosen per request, for example
55+
only for crawlers, from the user agent.
5656

5757
## Intent is CSS
5858

@@ -76,8 +76,9 @@ to its own submission, so overlapping requests don't clear each other's.
7676
A failed save returns `{ error }` rather than throwing, so the failure is
7777
typed from the action to the client. The server words it — it knows the
7878
todo's title, the client doesn't. The router records each submission;
79-
`useSubmissions(action)` lists them, and `submission.retry()` runs the same
80-
call again. The route ([src/routes/todos.tsx](./src/routes/todos.tsx))
79+
`useSubmissions(action)` lists them with the input each was called with.
80+
A retry is that input posted again: a small form on the same action, so it
81+
works without JavaScript like every other control. The route ([src/routes/todos.tsx](./src/routes/todos.tsx))
8182
renders the failures under the list — the one piece of client code the list
8283
has — and each action's `onSettled` clears the earlier answers to the same
8384
question, so a success dismisses an old error and a new failure takes its

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,11 @@ html .clear-completed:active {
409409
margin-top: 6px;
410410
}
411411

412+
.add-error form,
413+
.failures form {
414+
display: inline;
415+
}
416+
412417
.add-error button,
413418
.failures button {
414419
text-decoration: underline;

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
// Adding shows intent like every other form: the router marks it
66
// `aria-busy` while it saves (app.css dims the input), the input clears when
77
// the answer lands, and a failure stays in the input with its error beside
8-
// it.
8+
// it. The retry is a second form carrying the same title, so it posts
9+
// without JavaScript too.
910
import { useSubmissions } from "@solidjs/router";
1011
import { Errored, Loading, Show } from "solid-js";
1112
import { addTodo } from "~/actions";
@@ -36,10 +37,13 @@ function Header() {
3637
</form>
3738
<Show when={failure()}>
3839
{f => (
39-
<p class="add-error">
40+
<div class="add-error">
4041
Couldn't add “{String(f().input[0].get("title"))}”: {f().result!.error}.{" "}
41-
<button onClick={() => f().retry()}>Retry</button>
42-
</p>
42+
<form action={addTodo} method="post">
43+
<input type="hidden" name="title" value={String(f().input[0].get("title"))} />
44+
<button>Retry</button>
45+
</form>
46+
</div>
4347
)}
4448
</Show>
4549
</header>

‎examples/todos-server/src/routes/todos.tsx‎

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
// `useSubmissions(action)` lists a failed save's `{ error }` until the next
1010
// attempt at the same thing settles. After a form posted without JavaScript
1111
// the router seeds the same list from its flash cookie, so the failures
12-
// render on the server too.
12+
// render on the server too. A retry is the same form again, built from the
13+
// submission's own input, so it works there as well.
1314
import { useSubmissions, type RouteProps, type Submission } from "@solidjs/router";
1415
import { For } from "solid-js";
15-
import { dynamicComponent } from "@solidjs/web";
16-
import { clearCompleted, removeTodo, toggleAll, toggleTodo } from "~/actions";
16+
import { dynamicComponent, type JSX } from "@solidjs/web";
17+
import { clearCompleted, completedOf, removeTodo, toggleAll, toggleTodo } from "~/actions";
1718
import { getTodoList, parseFilter } from "~/todo-list";
1819

1920
type Answer = Submission<any[], { error: string } | undefined>;
@@ -46,14 +47,43 @@ function Failures() {
4647
});
4748
clearCompleted.onSettled(supersede(clears));
4849

49-
const failed = () =>
50-
[...toggles, ...removals, ...markAll, ...clears].filter(s => s.result?.error);
50+
/** The form that asks again: the action bound to the same todo, and the
51+
* button carrying the same `completed` the first attempt submitted. */
52+
const again = (subs: Answer[], retry: (s: Answer) => JSX.Element) =>
53+
subs.filter(s => s.result?.error).map(s => ({ s, retry }));
54+
const completed = (form: FormData) => (completedOf(form) ? "true" : "false");
55+
const failed = () => [
56+
...again(toggles, s => (
57+
<form action={toggleTodo.with(s.input[0])} method="post">
58+
<button name="completed" value={completed(s.input[1])}>
59+
Retry
60+
</button>
61+
</form>
62+
)),
63+
...again(removals, s => (
64+
<form action={removeTodo.with(s.input[0])} method="post">
65+
<button>Retry</button>
66+
</form>
67+
)),
68+
...again(markAll, s => (
69+
<form action={toggleAll} method="post">
70+
<button name="completed" value={completed(s.input[0])}>
71+
Retry
72+
</button>
73+
</form>
74+
)),
75+
...again(clears, () => (
76+
<form action={clearCompleted} method="post">
77+
<button>Retry</button>
78+
</form>
79+
))
80+
];
5181
return (
5282
<ul class="failures" hidden={failed().length === 0}>
5383
<For each={failed()}>
54-
{s => (
84+
{f => (
5585
<li>
56-
{s.result!.error}. <button onClick={() => s.retry()}>Retry</button>
86+
{f.s.result!.error}. {f.retry(f.s)}
5787
</li>
5888
)}
5989
</For>

‎examples/todos-server/vite.config.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ export default defineConfig({
1414
server: { port: 3010 },
1515
plugins: [
1616
solid({
17-
start: {},
17+
// Every control is a form that works without JavaScript, so the page
18+
// has to arrive whole: `async` waits for the list instead of streaming
19+
// it in behind a fallback that only a script can swap out.
20+
start: { renderMode: "async" },
1821
ssr: true,
1922
serverFunctions: { components: true, configure: "src/server-config.ts" }
2023
})

0 commit comments

Comments
 (0)