@pyreon/runtime-server 0.1.0
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/LICENSE +21 -0
- package/README.md +74 -0
- package/lib/analysis/index.js.html +5406 -0
- package/lib/index.js +318 -0
- package/lib/index.js.map +1 -0
- package/lib/types/index.d.ts +298 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index2.d.ts +37 -0
- package/lib/types/index2.d.ts.map +1 -0
- package/package.json +44 -0
- package/src/index.ts +460 -0
- package/src/tests/ssr.test.ts +916 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-present Vit Bokisch
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# @pyreon/runtime-server
|
|
2
|
+
|
|
3
|
+
Server-side rendering for Pyreon. Renders VNode trees to HTML strings or Web-standard `ReadableStream` chunks with Suspense streaming support.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add @pyreon/runtime-server
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { renderToString } from "@pyreon/runtime-server"
|
|
15
|
+
import { h } from "@pyreon/core"
|
|
16
|
+
|
|
17
|
+
function App() {
|
|
18
|
+
return h("h1", null, "Hello from SSR")
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const html = await renderToString(h(App, null))
|
|
22
|
+
// "<h1>Hello from SSR</h1>"
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## API
|
|
26
|
+
|
|
27
|
+
### `renderToString(vnode)`
|
|
28
|
+
|
|
29
|
+
Render a VNode tree to a complete HTML string. Returns `Promise<string>`. Async components are awaited. Each call gets an isolated context stack.
|
|
30
|
+
|
|
31
|
+
### `renderToStream(vnode)`
|
|
32
|
+
|
|
33
|
+
Render a VNode tree to a `ReadableStream<string>` for progressive HTML streaming. Synchronous subtrees are flushed immediately. Suspense boundaries are streamed out-of-order: the fallback is emitted first, then resolved children are sent as `<template>` elements with inline swap scripts.
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { renderToStream } from "@pyreon/runtime-server"
|
|
37
|
+
|
|
38
|
+
const stream = renderToStream(h(App, null))
|
|
39
|
+
return new Response(stream, {
|
|
40
|
+
headers: { "Content-Type": "text/html" },
|
|
41
|
+
})
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### `runWithRequestContext(fn)`
|
|
45
|
+
|
|
46
|
+
Run an async function with a fresh, isolated context stack and store registry. Useful for calling Pyreon APIs (e.g. `useHead`, route loader prefetching) outside of `renderToString` while maintaining per-request isolation.
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
import { runWithRequestContext } from "@pyreon/runtime-server"
|
|
50
|
+
|
|
51
|
+
const result = await runWithRequestContext(async () => {
|
|
52
|
+
// Pyreon context and stores are isolated to this call
|
|
53
|
+
return await prefetchLoaderData(url)
|
|
54
|
+
})
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### `configureStoreIsolation(registryProvider)`
|
|
58
|
+
|
|
59
|
+
Wire up per-request store isolation for concurrent SSR. Call once at server startup with a function that hooks your store registry into the request-scoped `AsyncLocalStorage`. Prevents store state from leaking between requests.
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
import { configureStoreIsolation } from "@pyreon/runtime-server"
|
|
63
|
+
|
|
64
|
+
configureStoreIsolation(provider => {
|
|
65
|
+
// Wire your store registry to use the per-request provider
|
|
66
|
+
})
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Behavior Notes
|
|
70
|
+
|
|
71
|
+
- Signal accessors are called synchronously to snapshot their current value. No effects are created on the server.
|
|
72
|
+
- Async component functions (`async function Component()`) are fully supported.
|
|
73
|
+
- Context isolation uses `AsyncLocalStorage` internally. Each `renderToString` and `renderToStream` call gets its own context stack.
|
|
74
|
+
- HTML output is escaped. Event handlers and custom directives (`on*`, `n-*`) are omitted. URL attributes are sanitized against `javascript:` and `data:` URIs.
|