@solidjs/web 2.0.0-rc.2 → 2.0.0-rc.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/server.dev.js +5165 -0
- package/dist/server.js +1876 -374
- package/dist/{server.cjs → server.observe.js} +2070 -577
- package/dist/{dev.cjs → web.dev.js} +955 -567
- package/dist/web.js +646 -350
- package/dist/{dev.js → web.observe.js} +699 -421
- package/frames/dist/assets.js +92 -0
- package/frames/dist/client.dev.js +1296 -1198
- package/frames/dist/client.js +1128 -1191
- package/frames/dist/client.observe.js +2041 -0
- package/frames/dist/regions.js +171 -0
- package/frames/dist/server.dev.js +2545 -0
- package/frames/dist/server.js +1683 -3004
- package/frames/dist/server.observe.js +2544 -0
- package/frames/dist/trace.js +45 -0
- package/frames/dist/wire.js +594 -0
- package/frames/package.json +2 -25
- package/package.json +244 -256
- package/performance-tracks/dist/performance-tracks.dev.js +679 -0
- package/performance-tracks/dist/performance-tracks.js +6 -0
- package/performance-tracks/dist/performance-tracks.observe.js +667 -0
- package/performance-tracks/package.json +7 -0
- package/performance-tracks/types/index.d.ts +69 -0
- package/serialization/decode/package.json +2 -15
- package/serialization/dist/decode.js +121 -25
- package/serialization/dist/serialization.js +282 -88
- package/serialization/package.json +2 -15
- package/serialization/types/index.d.ts +115 -153
- package/serialization/types/serializer-decode.d.ts +173 -114
- package/serialization/types/serializer.d.ts +144 -0
- package/server-functions/dist/client.dev.js +1462 -0
- package/server-functions/dist/client.js +667 -165
- package/server-functions/dist/client.observe.js +1441 -0
- package/server-functions/dist/rich-args.js +102 -1
- package/server-functions/dist/server.dev.js +2802 -299
- package/server-functions/dist/server.js +2724 -314
- package/server-functions/dist/server.observe.js +3680 -0
- package/server-functions/package.json +2 -35
- package/server-functions/rich-args/package.json +2 -15
- package/skills/server-components/SKILL.md +117 -0
- package/storage/package.json +2 -15
- package/types/client.d.ts +342 -288
- package/types/constants.d.ts +22 -0
- package/types/cookies.d.ts +32 -84
- package/types/diagnostics.d.ts +80 -0
- package/types/frames/assets-tier.d.ts +78 -0
- package/types/frames/client.d.ts +40 -1
- package/types/frames/frame-client.d.ts +443 -280
- package/types/frames/frame-container-plugin.d.ts +64 -0
- package/types/frames/frame-morph.d.ts +29 -0
- package/types/frames/frame-sink.d.ts +141 -161
- package/types/frames/frame-transport.d.ts +263 -184
- package/types/frames/regions-tier.d.ts +60 -0
- package/types/frames/serializer-decode.d.ts +241 -0
- package/types/frames/serializer.d.ts +115 -153
- package/types/frames/server.d.ts +2 -2
- package/types/frames/trace-tier.d.ts +2 -0
- package/types/frames/tree-rewrite.d.ts +39 -0
- package/types/frames/wire-tier.d.ts +169 -0
- package/types/head.d.ts +20 -0
- package/types/index.d.ts +98 -81
- package/types/index.server.d.ts +159 -0
- package/types/jsx.d.ts +49 -44
- package/types/observe.d.ts +535 -0
- package/types/reconcile.d.ts +1 -0
- package/types/render.d.ts +11 -0
- package/types/request-error-hook.d.ts +5 -0
- package/types/response.d.ts +95 -147
- package/types/serializer-decode.d.ts +173 -114
- package/types/serializer.d.ts +115 -153
- package/types/server-functions/argument-codec.d.ts +30 -0
- package/types/server-functions/client.d.ts +237 -223
- package/types/server-functions/flash.d.ts +28 -30
- package/types/server-functions/registry.d.ts +105 -0
- package/types/server-functions/rich-args.d.ts +1 -10
- package/types/server-functions/server.d.ts +538 -531
- package/types/server-functions/shared.d.ts +398 -425
- package/types/server-functions/uploads.d.ts +53 -0
- package/types/server-mock.d.ts +154 -20
- package/types/server-observe.d.ts +86 -0
- package/types/server.d.ts +601 -422
- package/types/trace.d.ts +127 -0
- package/LICENSE +0 -21
- package/dist/web.cjs +0 -2033
- package/frames/dist/client.cjs +0 -2002
- package/frames/dist/client.dev.cjs +0 -2022
- package/frames/dist/server.cjs +0 -3877
- package/serialization/dist/decode.cjs +0 -139
- package/serialization/dist/serialization.cjs +0 -261
- package/serialization/types-cjs/index.d.cts +0 -182
- package/serialization/types-cjs/package.json +0 -3
- package/serialization/types-cjs/serializer-decode.d.cts +0 -182
- package/server-functions/dist/client.cjs +0 -834
- package/server-functions/dist/rich-args.cjs +0 -11
- package/server-functions/dist/server.cjs +0 -1242
- package/server-functions/dist/server.dev.cjs +0 -1242
- package/storage/dist/storage.cjs +0 -12
- package/storage/types-cjs/index.d.cts +0 -28
- package/storage/types-cjs/package.json +0 -3
- package/types/core.d.ts +0 -9
- package/types-cjs/client.d.cts +0 -337
- package/types-cjs/cookies.d.cts +0 -93
- package/types-cjs/core.d.cts +0 -9
- package/types-cjs/frames/client.d.cts +0 -36
- package/types-cjs/frames/frame-client.d.cts +0 -356
- package/types-cjs/frames/frame-sink.d.cts +0 -194
- package/types-cjs/frames/frame-transport.d.cts +0 -222
- package/types-cjs/frames/serializer.d.cts +0 -182
- package/types-cjs/frames/server.d.cts +0 -52
- package/types-cjs/index.d.cts +0 -244
- package/types-cjs/jsx-properties.d.cts +0 -93
- package/types-cjs/jsx.d.cts +0 -4159
- package/types-cjs/package.json +0 -3
- package/types-cjs/response.d.cts +0 -174
- package/types-cjs/serializer-decode.d.cts +0 -182
- package/types-cjs/serializer.d.cts +0 -182
- package/types-cjs/server-functions/client.d.cts +0 -262
- package/types-cjs/server-functions/flash.d.cts +0 -38
- package/types-cjs/server-functions/rich-args.d.cts +0 -10
- package/types-cjs/server-functions/server.d.cts +0 -681
- package/types-cjs/server-functions/shared.d.cts +0 -523
- package/types-cjs/server-mock.d.cts +0 -286
- package/types-cjs/server.d.cts +0 -544
|
@@ -1,40 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
3
|
-
"main": "./dist/server.cjs",
|
|
2
|
+
"main": "./dist/server.js",
|
|
4
3
|
"module": "./dist/server.js",
|
|
5
4
|
"types": "../types/server-functions/server.d.ts",
|
|
6
5
|
"type": "module",
|
|
7
|
-
"sideEffects": false
|
|
8
|
-
"exports": {
|
|
9
|
-
".": {
|
|
10
|
-
"browser": {
|
|
11
|
-
"import": {
|
|
12
|
-
"types": "../types/server-functions/client.d.ts",
|
|
13
|
-
"default": "./dist/client.js"
|
|
14
|
-
},
|
|
15
|
-
"require": {
|
|
16
|
-
"types": "../types-cjs/server-functions/client.d.cts",
|
|
17
|
-
"default": "./dist/client.cjs"
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
"development": {
|
|
21
|
-
"import": {
|
|
22
|
-
"types": "../types/server-functions/server.d.ts",
|
|
23
|
-
"default": "./dist/server.dev.js"
|
|
24
|
-
},
|
|
25
|
-
"require": {
|
|
26
|
-
"types": "../types-cjs/server-functions/server.d.cts",
|
|
27
|
-
"default": "./dist/server.dev.cjs"
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
"import": {
|
|
31
|
-
"types": "../types/server-functions/server.d.ts",
|
|
32
|
-
"default": "./dist/server.js"
|
|
33
|
-
},
|
|
34
|
-
"require": {
|
|
35
|
-
"types": "../types-cjs/server-functions/server.d.cts",
|
|
36
|
-
"default": "./dist/server.cjs"
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
6
|
+
"sideEffects": false
|
|
40
7
|
}
|
|
@@ -1,20 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
3
|
-
"main": "../dist/rich-args.cjs",
|
|
2
|
+
"main": "../dist/rich-args.js",
|
|
4
3
|
"module": "../dist/rich-args.js",
|
|
5
4
|
"types": "../../types/server-functions/rich-args.d.ts",
|
|
6
5
|
"type": "module",
|
|
7
|
-
"sideEffects": false
|
|
8
|
-
"exports": {
|
|
9
|
-
".": {
|
|
10
|
-
"import": {
|
|
11
|
-
"types": "../../types/server-functions/rich-args.d.ts",
|
|
12
|
-
"default": "../dist/rich-args.js"
|
|
13
|
-
},
|
|
14
|
-
"require": {
|
|
15
|
-
"types": "../../types-cjs/server-functions/rich-args.d.cts",
|
|
16
|
-
"default": "../dist/rich-args.cjs"
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
6
|
+
"sideEffects": false
|
|
20
7
|
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: server-components
|
|
3
|
+
description: Rules for writing Solid 2.0 server components ("use server" functions that return a template) and their slots with @solidjs/web. Use when writing or reviewing a server component, deciding what lives on the server versus the client, or wiring a slot.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Writing Solid server components with slots
|
|
7
|
+
|
|
8
|
+
A Solid server component is a `"use server"` function that returns a
|
|
9
|
+
template; the browser receives its markup and never its code. Anything the
|
|
10
|
+
client contributes goes through a **slot** on the component's props: a
|
|
11
|
+
client component the client places at a position in the server's markup.
|
|
12
|
+
This guide is the set of rules an author — a person or an agent — needs to
|
|
13
|
+
write one correctly the first time. The design record is
|
|
14
|
+
`documentation/server-components/server-components-principles.md`; this
|
|
15
|
+
file is the operative subset.
|
|
16
|
+
|
|
17
|
+
## Where things go
|
|
18
|
+
|
|
19
|
+
> **An element lives where the data that creates it lives.**
|
|
20
|
+
|
|
21
|
+
- Exists because of **server data** (a todo row, a nav link, a search
|
|
22
|
+
form the server renders)? It is **server markup**. A mutation on it is a
|
|
23
|
+
form `action` — it works without JavaScript, and the router marks a
|
|
24
|
+
submission in flight (`aria-busy`) so CSS can show the intent.
|
|
25
|
+
- Needs **client behavior or client state** (a handler, an optimistic add,
|
|
26
|
+
a modal, a drag ghost, an editor open over a field)? It is a **client
|
|
27
|
+
component** placed through a **slot**.
|
|
28
|
+
|
|
29
|
+
When the client confirms an optimistic entity and the server renders it, the
|
|
30
|
+
row _becomes_ server markup; `$key` on the element reconciles the two.
|
|
31
|
+
|
|
32
|
+
## Slots
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
import type { Slot } from "@solidjs/web/frames";
|
|
36
|
+
|
|
37
|
+
interface TodosProps {
|
|
38
|
+
pending: Slot; // no props
|
|
39
|
+
editor: Slot<{ id: string; title: string }>; // props from the server
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
A slot is placed as an element: `<props.pending />`,
|
|
44
|
+
`<props.editor id={t.id} title={t.title} />`. The client owns the nodes
|
|
45
|
+
between the slot's markers; the server's markup around them stays the
|
|
46
|
+
server's.
|
|
47
|
+
|
|
48
|
+
```tsx
|
|
49
|
+
export async function todoList() {
|
|
50
|
+
"use server";
|
|
51
|
+
const todos = await db.list();
|
|
52
|
+
return (props: TodosProps) => (
|
|
53
|
+
<ul>
|
|
54
|
+
{todos.map(t => (
|
|
55
|
+
<li $key={t.id}>
|
|
56
|
+
{t.title}
|
|
57
|
+
<props.editor $key={t.id} id={t.id} title={t.title} />
|
|
58
|
+
</li>
|
|
59
|
+
))}
|
|
60
|
+
<props.pending />
|
|
61
|
+
</ul>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
The client passes the fill — a component of the slot's props:
|
|
67
|
+
|
|
68
|
+
```tsx
|
|
69
|
+
<Todos editor={p => <Editor id={p.id} title={p.title} />} pending={() => <For each={adds}>{…}</For>} />
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
- **The fill runs once per occurrence, as a component body does.** It runs
|
|
73
|
+
untracked, under the occurrence's owner, with live props. State it
|
|
74
|
+
creates (a signal, a memo, an `onCleanup`) lives as long as the
|
|
75
|
+
occurrence. A top-level read is read once, and `STRICT_READ_UNTRACKED`
|
|
76
|
+
names it ("the \`editor\` template-slot fill").
|
|
77
|
+
- **Place slots as JSX, not calls.** The compiler wraps each prop in a
|
|
78
|
+
getter so the read defers to the slot border; a call form
|
|
79
|
+
(`props.status({ … })`) evaluates its args eagerly in the server
|
|
80
|
+
component's body.
|
|
81
|
+
- **`$key` is optional.** Add it when the fill holds its own state (an edit
|
|
82
|
+
draft, a signal created inside) that must follow the entity across
|
|
83
|
+
refetches and reorders.
|
|
84
|
+
- **An async value crosses with `asyncArg`.**
|
|
85
|
+
`<props.status progress={asyncArg(gen.progress)} />` ships the promise or
|
|
86
|
+
async iterable; the fill's read settles (suspends until the first value).
|
|
87
|
+
|
|
88
|
+
## Behavior on server markup
|
|
89
|
+
|
|
90
|
+
A handler on a server-rendered element cannot come from the server: a
|
|
91
|
+
server function never runs in the browser. Pick one:
|
|
92
|
+
|
|
93
|
+
- **A form.** A mutation is `<form action={…}>`; it works before
|
|
94
|
+
JavaScript and needs no client code.
|
|
95
|
+
- **A client component that owns the element.** Move the control into a
|
|
96
|
+
slot's fill (`<props.toggle id={t.id} done={t.completed} />`, rendering
|
|
97
|
+
the checkbox on the client).
|
|
98
|
+
- **One delegated listener.** For many identical controls inside server
|
|
99
|
+
markup (a copy button on every code block), place one slot occurrence
|
|
100
|
+
whose component registers a single document listener in `onSettled` and
|
|
101
|
+
finds its target from the event (`closest("button.copy-code")`). Inside a
|
|
102
|
+
live hole this is the shape that keeps the hole streaming: a slot placed
|
|
103
|
+
inside a live hole latches it (`SSR_LIVE_HOLE_LATCHED`, `data.cause`
|
|
104
|
+
`"records"`). `examples/chat`'s Copy button is this shape.
|
|
105
|
+
|
|
106
|
+
## Shared components
|
|
107
|
+
|
|
108
|
+
One component can render on both sides. Put `$key={props.id}` on the
|
|
109
|
+
element it renders (morph identity) — the slot's own `$key` is a different
|
|
110
|
+
key for a different job. Do not read `document`/`window` during render;
|
|
111
|
+
that is the ordinary isomorphic rule.
|
|
112
|
+
|
|
113
|
+
## Compiling
|
|
114
|
+
|
|
115
|
+
With `@solidjs/vite-plugin`, `solid({ ssr: true, serverFunctions:
|
|
116
|
+
{ components: true } })` is the turnkey setup (the examples under
|
|
117
|
+
`examples/todos-server`, `examples/notes`, `examples/chat`).
|
package/storage/package.json
CHANGED
|
@@ -1,20 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
3
|
-
"main": "./dist/storage.cjs",
|
|
2
|
+
"main": "./dist/storage.js",
|
|
4
3
|
"module": "./dist/storage.js",
|
|
5
4
|
"types": "./types/index.d.ts",
|
|
6
5
|
"type": "module",
|
|
7
|
-
"sideEffects": false
|
|
8
|
-
"exports": {
|
|
9
|
-
".": {
|
|
10
|
-
"import": {
|
|
11
|
-
"types": "./types/index.d.ts",
|
|
12
|
-
"default": "./dist/storage.js"
|
|
13
|
-
},
|
|
14
|
-
"require": {
|
|
15
|
-
"types": "./types-cjs/index.d.cts",
|
|
16
|
-
"default": "./dist/storage.cjs"
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
6
|
+
"sideEffects": false
|
|
20
7
|
}
|