@ultimat3/render 31.13.1 → 31.15.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/CLAUDE.md +2 -1
- package/README.md +16 -1
- package/package.json +7 -7
- package/src/client.ts +5 -2
- package/src/island-mount.ts +37 -0
- package/src/render-ssr.ts +17 -1
- package/src/render-stream.ts +19 -4
package/CLAUDE.md
CHANGED
|
@@ -14,7 +14,8 @@ A row marked `†` has its full text in [`docs/history/render-rules.md`](../../d
|
|
|
14
14
|
a name from both barrels: `index.test.ts` asserts the empty name intersection and that `index.ts`'s
|
|
15
15
|
runtime import graph reaches none of those seven modules; `scripts/browser-barrel.test.ts` holds
|
|
16
16
|
the end property. **`"./client"` (`client.ts`) is THE browser entry** for what an island calls
|
|
17
|
-
(`navigate`, `refresh`, `openModal`, `closeModal`, the modal refusal, the three event names
|
|
17
|
+
(`navigate`, `refresh`, `openModal`, `closeModal`, the modal refusal, the three event names,
|
|
18
|
+
`mountOver` — an island's mount that restores the server markup on a render throw): its
|
|
18
19
|
graph never reaches `errors.ts` (the barrel's `sideEffects` keeps that table in every chunk), held
|
|
19
20
|
by `client-bundle.test.ts`. A name there stays on `.` too (additive); a refusal it can construct
|
|
20
21
|
lives in its own module over `@ultimat3/core/page`'s `UltimateError` (`navigation-errors.ts`) and
|
package/README.md
CHANGED
|
@@ -174,6 +174,10 @@ through `cacheControl()`, and its `vary` joins the defaults. `As of 2026-09-24`
|
|
|
174
174
|
`RouteCache`; `@ultimat3/http` is a dependency of this package for that type and for
|
|
175
175
|
`cacheControl` in the server half.
|
|
176
176
|
|
|
177
|
+
Every `ssr` document whose `cache-control` is not `no-store` carries `etag: "<contentHash(html)>"`
|
|
178
|
+
(strong; `compress` weakens it when it offers a coding), and the CLI answers a matching
|
|
179
|
+
`If-None-Match` with a 304. `As of 2026-11-12`.
|
|
180
|
+
|
|
177
181
|
## `post` — the page's URL also answers `POST`
|
|
178
182
|
|
|
179
183
|
`defineRoute({ render: 'ssr', …, post: 'unsubscribeOnboarding' })` binds `POST <this page's path>`
|
|
@@ -569,7 +573,7 @@ side effect. Anything that loads an app's source — `x dev`, `x build`, `server
|
|
|
569
573
|
`NavigationModalPathInvalidError`, `NAVIGATE_EVENT`, `NAVIGATED_EVENT`, `NAVIGATION_ERROR_EVENT`,
|
|
570
574
|
`NAVIGATION_MODAL_ATTRIBUTE` (the `data-x-modal` the router marks its `<dialog>` with — style
|
|
571
575
|
`dialog[data-x-modal]` off the constant, never a restated string), `disposeIslands`,
|
|
572
|
-
`scheduleRefresh`.
|
|
576
|
+
`mountOver`, `IslandDraw`, `scheduleRefresh`.
|
|
573
577
|
The barrel bundles for the browser but its `sideEffects` keeps `errors.ts` — render's code table,
|
|
574
578
|
and core's and schema's titles tables behind it — in every chunk that reaches it; this entry's
|
|
575
579
|
graph is the navigation helpers plus `@ultimat3/core/page` (`client-bundle.test.ts`). `As of
|
|
@@ -598,6 +602,16 @@ export function release(dropped: readonly Node[]): void {
|
|
|
598
602
|
}
|
|
599
603
|
```
|
|
600
604
|
|
|
605
|
+
**`mountOver(el, draw)`** (`island-mount.ts`, `As of 2026-11`) is how an island's `mount` replaces
|
|
606
|
+
its server markup: it clears `el`, calls `draw(el)` and answers the disposer `draw` returned. A
|
|
607
|
+
draw that THROWS puts the server's nodes back — the same nodes, in order, the half-rendered tree
|
|
608
|
+
taken out — and rethrows, so the runtime still marks the root `data-x-failed` and
|
|
609
|
+
`/x-client-errors.js` reports it once. Without it, a render throw leaves a blank box. Every
|
|
610
|
+
`x g island` / `x new` island is written as
|
|
611
|
+
`return mountOver(el, (root) => render(() => <Island {...props} />, root));`; an older app's
|
|
612
|
+
islands are found by the shipped guard `x g guard island-mount-clears` (`X_ISLAND_MOUNT_CLEARS`).
|
|
613
|
+
167 B minified. Framework-neutral: the draw is the caller's, so this package takes no `solid-js`.
|
|
614
|
+
|
|
601
615
|
## Error classes
|
|
602
616
|
|
|
603
617
|
Every error class `src/index.ts` exports, for `instanceof` inside one process. Across a wire or
|
|
@@ -644,6 +658,7 @@ a job boundary the class is gone and the `code` is what survives — match on th
|
|
|
644
658
|
| `navigate`‡, `refresh`‡, `openModal`‡, `closeModal`‡, `NavigateToOptions`‡, `NavigationModalPathInvalidError`‡ | navigating from code: the router when the page has one, the browser's own load when not. Import from `/client` in an island |
|
|
645
659
|
| `scheduleRefresh`‡ | a `refresh()` once the visitor is idle, coalesced; never a reload |
|
|
646
660
|
| `disposeIslands` (on `/client` only) | dispose the islands mounted under an element: what the router does on a swap, for an island that drops markup holding other islands |
|
|
661
|
+
| `mountOver`, `IslandDraw` (on `/client` only) | an island's `mount` that clears the server markup for the live render and restores it when the render throws |
|
|
647
662
|
| `modalAddress`, `modalLocation`, `addressOf`, `presentation`, `modalHistory`, `leaveModal`, `NAVIGATION_PRESENTATION_META`, `NAVIGATION_MODAL_ATTRIBUTE` | route-presented modals (`navigation: 'modal'`): the hash grammar, when an answer is a modal, and what leaving one does to history |
|
|
648
663
|
| `declaresModal`, `parseModalRoutes`, `modalRouteList`, `ModalRoutes`, `NAVIGATION_MODALS_META`, `NAVIGATION_MODAL_BODY_ATTRIBUTE`, `NAVIGATION_MODAL_CLOSE_ATTRIBUTE`, `NAVIGATION_MODAL_SKELETON_ATTRIBUTE` | the modal that opens on the click: the meta naming a surface's modal routes (composed by the server, read by the router) and the frame's attributes, styled by `@ultimat3/ui` |
|
|
649
664
|
| `isRouteNavigation`, `navigationModeOf`, `navigationPrefetches`, `RouteNavigationDeclaration`, `RouteModalPrefetch` | `navigation:` read back: the four spellings, which mode, prefetched or not |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/render",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.15.0",
|
|
4
4
|
"description": "The route primitive and the five render modes: static, isr, ssr, stream, spa.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ultimate",
|
|
@@ -52,12 +52,12 @@
|
|
|
52
52
|
"test": "bun test"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@ultimat3/cache": "31.
|
|
56
|
-
"@ultimat3/core": "31.
|
|
57
|
-
"@ultimat3/http": "31.
|
|
58
|
-
"@ultimat3/i18n": "31.
|
|
59
|
-
"@ultimat3/schema": "31.
|
|
60
|
-
"@ultimat3/seo": "31.
|
|
55
|
+
"@ultimat3/cache": "31.15.0",
|
|
56
|
+
"@ultimat3/core": "31.15.0",
|
|
57
|
+
"@ultimat3/http": "31.15.0",
|
|
58
|
+
"@ultimat3/i18n": "31.15.0",
|
|
59
|
+
"@ultimat3/schema": "31.15.0",
|
|
60
|
+
"@ultimat3/seo": "31.15.0",
|
|
61
61
|
"sass": "1.106.1"
|
|
62
62
|
}
|
|
63
63
|
}
|
package/src/client.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// `@ultimat3/render/client` — THE browser entry of this package: what an island or a page script
|
|
2
2
|
// may call, and nothing that drags the rest along. The `.` barrel bare-retains `errors.ts` (render's
|
|
3
3
|
// whole code table, registered at import, plus core's titles tables); this entry's graph is
|
|
4
|
-
// `navigation-api.ts`, `navigation-errors.ts`, `island-dispose.ts`, `
|
|
5
|
-
// rules and `@ultimat3/core/page`, held
|
|
4
|
+
// `navigation-api.ts`, `navigation-errors.ts`, `island-dispose.ts`, `island-mount.ts`,
|
|
5
|
+
// `refresh-idle.ts`, the pure rules and `@ultimat3/core/page`, held by `client-bundle.test.ts`.
|
|
6
6
|
//
|
|
7
7
|
// import { navigate, refresh, scheduleRefresh } from '@ultimat3/render/client';
|
|
8
8
|
//
|
|
@@ -10,6 +10,9 @@
|
|
|
10
10
|
|
|
11
11
|
// An island that drops markup holding other islands releases them first: `disposeIslands(node)`.
|
|
12
12
|
export { disposeIslands } from './island-dispose';
|
|
13
|
+
// An island's `mount` that keeps the server's markup when its render throws (`island-mount.ts`).
|
|
14
|
+
export type { IslandDraw } from './island-mount';
|
|
15
|
+
export { mountOver } from './island-mount';
|
|
13
16
|
export type { NavigateToOptions } from './navigation-api';
|
|
14
17
|
export { closeModal, navigate, openModal, refresh } from './navigation-api';
|
|
15
18
|
export { NavigationModalPathInvalidError } from './navigation-errors';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// An island's `mount` that never leaves a blank box: the server's markup is cleared for the live
|
|
2
|
+
// render and put BACK when that render throws. Framework-neutral — the caller hands in the draw
|
|
3
|
+
// (Solid's `render`), so this package takes no `solid-js` dependency and adds 167 B to a chunk.
|
|
4
|
+
|
|
5
|
+
/** What an island draws into its wrapper, answering the disposer (Solid's `render` does). */
|
|
6
|
+
export type IslandDraw = (root: HTMLElement) => () => void;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Clear `el`, draw into it, and answer the draw's disposer. A draw that THROWS restores the server
|
|
10
|
+
* markup it replaced — every node, in order, including whatever the draw half-inserted before it
|
|
11
|
+
* failed being taken out — and rethrows the same error, once.
|
|
12
|
+
*
|
|
13
|
+
* Rethrown, never swallowed: the hydration runtime's `boot` (`hydrate.ts`) is what marks the root
|
|
14
|
+
* `data-x-failed`, and `/x-client-errors.js` reports an island by that marker, once per element. A
|
|
15
|
+
* swallowed throw would mark the island MOUNTED and reach no error tracker — a dead control that
|
|
16
|
+
* looks alive. Reporting here as well would be the second report of one failure.
|
|
17
|
+
*
|
|
18
|
+
* The clear is still load-bearing on success: Solid's `render` APPENDS to a container with
|
|
19
|
+
* children, so without it the server's copy stays on screen above the live one.
|
|
20
|
+
*
|
|
21
|
+
* export function mount(el: HTMLElement, props: Props): () => void {
|
|
22
|
+
* return mountOver(el, (root) => render(() => <Counter {...props} />, root));
|
|
23
|
+
* }
|
|
24
|
+
*/
|
|
25
|
+
export function mountOver(el: HTMLElement, draw: IslandDraw): () => void {
|
|
26
|
+
const server = Array.from(el.childNodes);
|
|
27
|
+
el.textContent = '';
|
|
28
|
+
try {
|
|
29
|
+
return draw(el);
|
|
30
|
+
} catch (error) {
|
|
31
|
+
// Clear-then-append, not `replaceChildren`: the same two calls the success path relies on, so
|
|
32
|
+
// no host that can run the island lacks the repair (`@ultimat3/testing`'s micro-DOM did).
|
|
33
|
+
el.textContent = '';
|
|
34
|
+
for (const node of server) el.appendChild(node);
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
}
|
package/src/render-ssr.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { BUILD_ID_HEADER } from '@ultimat3/core';
|
|
|
9
9
|
import { cacheControl } from '@ultimat3/http';
|
|
10
10
|
import { finiteStatus } from './finite-status';
|
|
11
11
|
import type { RouteEntry } from './registry';
|
|
12
|
+
import { contentHash } from './render-static';
|
|
12
13
|
import type { RenderResult, RouteCache, RouteParams } from './route';
|
|
13
14
|
|
|
14
15
|
export interface SsrRenderInput {
|
|
@@ -37,11 +38,26 @@ export async function renderSsr(
|
|
|
37
38
|
// Screened here and not at the Response boundary: `??` guards nullish, so a non-finite status
|
|
38
39
|
// reaches `new Response` intact and raises a RangeError two frames above the route that set it.
|
|
39
40
|
status: finiteStatus('renderSsr', options.status ?? 200),
|
|
40
|
-
headers: ssrHeaders(input.entry, options),
|
|
41
|
+
headers: validated(ssrHeaders(input.entry, options), html),
|
|
41
42
|
body: html,
|
|
42
43
|
};
|
|
43
44
|
}
|
|
44
45
|
|
|
46
|
+
const NO_STORE = /(?:^|[\s,])no-store(?=$|[\s,=])/i;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* A document anyone may keep carries the strong hash of its bytes — `static`'s `contentHash`, the
|
|
50
|
+
* one ETag function — so a CDN or a browser revalidating `public, s-maxage=30` is answered 304
|
|
51
|
+
* rather than the page again. `no-store` gets none: nothing holds a copy to revalidate.
|
|
52
|
+
*/
|
|
53
|
+
const validated = (
|
|
54
|
+
headers: Readonly<Record<string, string>>,
|
|
55
|
+
html: string,
|
|
56
|
+
): Readonly<Record<string, string>> =>
|
|
57
|
+
NO_STORE.test(headers['cache-control'] ?? '')
|
|
58
|
+
? headers
|
|
59
|
+
: { ...headers, etag: `"${contentHash(html)}"` };
|
|
60
|
+
|
|
45
61
|
const PRIVATE_NO_STORE = 'private, no-store';
|
|
46
62
|
|
|
47
63
|
/**
|
package/src/render-stream.ts
CHANGED
|
@@ -159,6 +159,23 @@ const afterOf = (hole: StreamHole, outcome: 'filled' | 'failed'): string => {
|
|
|
159
159
|
}
|
|
160
160
|
};
|
|
161
161
|
|
|
162
|
+
// Escaped as `holeMarker` escapes the same id: it lands inside an attribute either way.
|
|
163
|
+
const defaultErrorFallback = (id: string): string =>
|
|
164
|
+
`<div data-x-hole-error="${escapeHtml(id)}" hidden></div>`;
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* The app's `errorFallback`, which is app-shaped code like `after`: a throw there would escape the
|
|
168
|
+
* rejection handler, the hole would never settle and the document would never close.
|
|
169
|
+
*/
|
|
170
|
+
const fallbackOf = (fallback: (id: string) => string, id: string): string => {
|
|
171
|
+
try {
|
|
172
|
+
return fallback(id);
|
|
173
|
+
} catch (error) {
|
|
174
|
+
logger.warn('render.stream.hole_fallback_failed', { hole: id, error: renderThrowable(error) });
|
|
175
|
+
return defaultErrorFallback(id);
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
|
|
162
179
|
/** What a monitor hears when a hole misses its deadline: the visitor got the error markup. */
|
|
163
180
|
const holeDeadlineMissed = (id: string, timeoutMs: number): UltimateError =>
|
|
164
181
|
new UltimateError({
|
|
@@ -178,9 +195,7 @@ export function renderStreamHtml(
|
|
|
178
195
|
): ReadableStream<Uint8Array> {
|
|
179
196
|
const encoder = new TextEncoder();
|
|
180
197
|
const tail = plan.tail ?? '</body></html>';
|
|
181
|
-
const errorFallback =
|
|
182
|
-
// Escaped as `holeMarker` escapes the same id: it lands inside an attribute either way.
|
|
183
|
-
options.errorFallback ?? ((id) => `<div data-x-hole-error="${escapeHtml(id)}" hidden></div>`);
|
|
198
|
+
const errorFallback = options.errorFallback ?? defaultErrorFallback;
|
|
184
199
|
// A deadline is the bound a non-finite value does not disable but MOVES: `setTimeout(fn, NaN)`
|
|
185
200
|
// is `setTimeout(fn, 0)`, so every hole would miss a deadline nobody set and the document would
|
|
186
201
|
// be all fallbacks. `null` is the declared opt-out; there is no spelling that means "immediately".
|
|
@@ -256,7 +271,7 @@ export function renderStreamHtml(
|
|
|
256
271
|
write(revealChunk(hole.id, html, after));
|
|
257
272
|
settle();
|
|
258
273
|
};
|
|
259
|
-
const failed = (): string => hole.error ?? errorFallback
|
|
274
|
+
const failed = (): string => hole.error ?? fallbackOf(errorFallback, hole.id);
|
|
260
275
|
const timer =
|
|
261
276
|
timeoutMs === null
|
|
262
277
|
? undefined
|