lit-ui-router-ssr 0.7.0 → 0.8.1
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 +84 -30
- package/dist/client.js +0 -1
- package/dist/client.js.map +1 -1
- package/dist/dev-warn.js +0 -1
- package/dist/dev-warn.js.map +1 -1
- package/dist/development/index.js.map +1 -1
- package/dist/development/prerender.js +41 -12
- package/dist/development/prerender.js.map +1 -1
- package/dist/development/signature.js +1 -1
- package/dist/development/vite-preload.js +7 -0
- package/dist/development/vite-preload.js.map +1 -0
- package/dist/development/vite.js +27 -0
- package/dist/development/vite.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/prerender.d.ts +66 -16
- package/dist/prerender.d.ts.map +1 -1
- package/dist/prerender.js +40 -12
- package/dist/prerender.js.map +1 -1
- package/dist/served-view.js +0 -1
- package/dist/served-view.js.map +1 -1
- package/dist/signature.js +1 -1
- package/dist/vite-preload.d.ts +11 -0
- package/dist/vite-preload.d.ts.map +1 -0
- package/dist/vite-preload.js +7 -0
- package/dist/vite-preload.js.map +1 -0
- package/dist/vite.d.ts +94 -0
- package/dist/vite.d.ts.map +1 -0
- package/dist/vite.js +27 -0
- package/dist/vite.js.map +1 -0
- package/package.json +23 -2
- package/src/index.ts +2 -0
- package/src/prerender.ts +128 -23
- package/src/vite-preload.ts +18 -0
- package/src/vite.ts +164 -0
package/README.md
CHANGED
|
@@ -24,14 +24,14 @@ imports the pre-1.0 renderer or re-derives the incantation.
|
|
|
24
24
|
on the page carries `defer-hydration` and renders nothing until the client's walk reaches it.
|
|
25
25
|
- **The hydration signature.** A page rendered from a template opens on a JSON data block,
|
|
26
26
|
`<script type="application/json" data-lit-ui-router-ssr>`, naming this package's version, the
|
|
27
|
-
state the router stood on, that state's url parameter values, and the resolved values
|
|
28
|
-
`payload` hook
|
|
27
|
+
state the router stood on, that state's url parameter values, and the resolved values
|
|
28
|
+
`dehydrate` or the `payload` hook draws. A page `renderShell` returns as a string is written as-is, without one.
|
|
29
29
|
- **The lit render inside the emit loop.** The loop itself — verdict to file name, redirect to
|
|
30
30
|
rules line, the `_redirects` file, delegating states skipped, tally, warnings for paths that
|
|
31
31
|
matched nothing — is
|
|
32
32
|
`prerender` from `ui-router-server/prerender`, which takes any render. This package's `prerender`
|
|
33
33
|
supplies the lit one and takes the same options, plus `router`, `renderShell`, `document`,
|
|
34
|
-
`root`, `elementRenderers`, `payload`, `responses` and `origin`. No SPA catch-all is ever written: one
|
|
34
|
+
`root`, `elementRenderers`, `dehydrate`, `payload`, `responses` and `origin`. No SPA catch-all is ever written: one
|
|
35
35
|
turns every 404 into a 200.
|
|
36
36
|
- **Response states after settle.** `responder` runs the handler bound to a response state's name
|
|
37
37
|
with the resolves its transition landed with.
|
|
@@ -51,7 +51,8 @@ npm install lit-ui-router-ssr
|
|
|
51
51
|
`lit-ui-router`, `ui-router-server`, `@lit-labs/ssr`, `@lit-labs/ssr-client`, `lit`, and
|
|
52
52
|
`@uirouter/core` are peer dependencies. `@lit-labs/ssr` is the server half and `@lit-labs/ssr-client`
|
|
53
53
|
the client half, so a bundle takes one or the other, never both. `@lit-labs/ssr-client` is optional:
|
|
54
|
-
install it when you import `lit-ui-router-ssr/client`.
|
|
54
|
+
install it when you import `lit-ui-router-ssr/client`. `lit-ui-router-ssr/vite` wraps
|
|
55
|
+
`ui-router-server/vite`, so it takes `vite` through that package's optional peer.
|
|
55
56
|
|
|
56
57
|
The `lit-ui-router` peer is `^1.19.0`: the server renders a view through the helper `<ui-view>`
|
|
57
58
|
renders through, and the client hands a served class element to the view it wakes.
|
|
@@ -88,6 +89,14 @@ on. `dryRun: true` plans all of it and writes nothing.
|
|
|
88
89
|
Files land through `node:fs`, imported lazily on first write; pass `write` to emit into memory or a
|
|
89
90
|
virtual fs instead.
|
|
90
91
|
|
|
92
|
+
## After `vite build`
|
|
93
|
+
|
|
94
|
+
`lit-ui-router-ssr/vite` prerenders the built app after `vite build`. Its `serverRouterPlugin` is
|
|
95
|
+
`ui-router-server/vite`'s, with the DOM shim and `lit-ui-router-ssr/register` loaded before the
|
|
96
|
+
prerender script, and its `definePrerender` calls this package's `prerender` with the options the
|
|
97
|
+
script returns; [Prerender with Vite](https://lit-ui-router.dev/guides/prerender-with-vite) shows
|
|
98
|
+
both files in full.
|
|
99
|
+
|
|
91
100
|
## Static hosts add a trailing slash
|
|
92
101
|
|
|
93
102
|
A shell page lands at `<subpath>/index.html`. Cloudflare Pages, Netlify, and S3-style hosts serve
|
|
@@ -144,22 +153,17 @@ as `responses`, writing a 2xx body at the path its url spells or a 3xx as a rule
|
|
|
144
153
|
|
|
145
154
|
## Adopting the resolves on boot
|
|
146
155
|
|
|
147
|
-
The `
|
|
148
|
-
|
|
156
|
+
The `dehydrate` option draws each rendered page's resolve payload: `prerender` calls `dehydrate`
|
|
157
|
+
from `ui-router-server/ssr` on the page's landed transition with the options given, so
|
|
158
|
+
`shouldDehydrate` and `transport` act exactly as they do there. Pass `{}` to draw every resolve:
|
|
149
159
|
|
|
150
160
|
```typescript
|
|
151
161
|
import { prerender } from 'lit-ui-router-ssr';
|
|
152
|
-
import { dehydrate } from 'ui-router-server/ssr';
|
|
153
162
|
|
|
154
163
|
await prerender({
|
|
155
164
|
// mounts, router, paths, renderShell, …
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
for (const { state, token } of unserializable)
|
|
160
|
-
console.warn(`${path}: ${state}.${token} re-runs on the client`);
|
|
161
|
-
|
|
162
|
-
return payload;
|
|
165
|
+
dehydrate: {
|
|
166
|
+
shouldDehydrate: ({ token }) => token !== 'manifest',
|
|
163
167
|
},
|
|
164
168
|
});
|
|
165
169
|
```
|
|
@@ -169,15 +173,47 @@ The payload's `resolves` go into the page's hydration signature, beside `version
|
|
|
169
173
|
the router starts: each resolve the page was drawn with adopts its value in place of running its
|
|
170
174
|
function. Every other resolve runs as it would without one: a value `dehydrate` left out, a
|
|
171
175
|
`NOWAIT` resolve, every resolve of a boot that lands on another state or other parameters, and
|
|
172
|
-
every resolve of a page whose block carries no `resolves`. Without
|
|
173
|
-
resolves. What `dehydrate` draws, and which values it leaves out, is in
|
|
176
|
+
every resolve of a page whose block carries no `resolves`. Without `dehydrate` or a `payload` hook
|
|
177
|
+
no page carries resolves. What `dehydrate` draws, and which values it leaves out, is in
|
|
174
178
|
[its documentation](https://lit-ui-router.dev/packages/server#handing-resolves-to-the-client).
|
|
175
179
|
|
|
176
180
|
A value plain JSON can't carry, such as a `Date`, travels through a transporter. Pass the same
|
|
177
|
-
`transport`
|
|
178
|
-
|
|
181
|
+
`transport` in `dehydrate` and to `bootstrap()`: the signature keeps the payload's `transported`
|
|
182
|
+
marks, and `bootstrap()` hands `transport` to `seed`. See
|
|
179
183
|
[values beyond plain JSON](https://lit-ui-router.dev/packages/server#values-beyond-plain-json).
|
|
180
184
|
|
|
185
|
+
The `payload` option takes the drawing over by hand: a hook handed each page's landed transition
|
|
186
|
+
returns the payload to write, or `undefined` to write none. Pass one or the other; passing both
|
|
187
|
+
throws.
|
|
188
|
+
|
|
189
|
+
```typescript
|
|
190
|
+
import { dehydrate } from 'ui-router-server/ssr';
|
|
191
|
+
|
|
192
|
+
await prerender({
|
|
193
|
+
// mounts, router, paths, renderShell, …
|
|
194
|
+
payload: (transition, { path }) =>
|
|
195
|
+
path.startsWith('/drafts/')
|
|
196
|
+
? undefined
|
|
197
|
+
: dehydrate(transition, { transport }).payload,
|
|
198
|
+
});
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
Each rendered page's entry in `result.pages` reports its payload as `payload`: `bytes`, what the
|
|
202
|
+
payload adds to the page's signature as written, and, when `dehydrate` drew it, `unserializable`,
|
|
203
|
+
the resolves left out to re-run on the client. A hook returns the payload alone, so behind one the
|
|
204
|
+
report carries `bytes` only. A page with no payload has no `payload` field.
|
|
205
|
+
|
|
206
|
+
```typescript
|
|
207
|
+
const { pages } = await prerender({ /* … */ dehydrate: {} });
|
|
208
|
+
|
|
209
|
+
for (const { path, payload } of pages) {
|
|
210
|
+
if (!payload) continue;
|
|
211
|
+
console.log(`${path}: ${payload.bytes} bytes of resolves`);
|
|
212
|
+
for (const { state, token } of payload.unserializable ?? [])
|
|
213
|
+
console.warn(`${path}: ${state}.${token} re-runs on the client`);
|
|
214
|
+
}
|
|
215
|
+
```
|
|
216
|
+
|
|
181
217
|
## The routed view, drawn on the server
|
|
182
218
|
|
|
183
219
|
`elementRenderers` defaults to `[UiViewRenderer, LightElementRenderer]` — not `@lit-labs/ssr`'s
|
|
@@ -362,23 +398,41 @@ await bootstrap(router, root, page(router));
|
|
|
362
398
|
|
|
363
399
|
A `<ui-view>` another class already defined throws, naming both ways out.
|
|
364
400
|
|
|
365
|
-
The build-time entry that calls `prerender()`
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
401
|
+
The build-time entry that calls `prerender()` needs the DOM shim installed before anything defines
|
|
402
|
+
an element. The shim module awaits at its top level, so a static import beside it evaluates first:
|
|
403
|
+
lit's Node build installs a registry of its own, the elements are defined there, and the shim then
|
|
404
|
+
replaces `globalThis.customElements` with an empty one. Load the shim and `lit-ui-router-ssr/register`
|
|
405
|
+
before the entry starts. `serverRouterPlugin` from `lit-ui-router-ssr/vite` names both as preloads
|
|
406
|
+
of its prerender worker, and its `definePrerender` calls `prerender()` with the options the entry
|
|
407
|
+
returns:
|
|
370
408
|
|
|
371
409
|
```typescript
|
|
372
|
-
|
|
410
|
+
// vite.config.ts
|
|
411
|
+
import { createServerRouter } from 'ui-router-server';
|
|
412
|
+
import { serverRouterPlugin } from 'lit-ui-router-ssr/vite';
|
|
413
|
+
|
|
414
|
+
plugins: [
|
|
415
|
+
serverRouterPlugin(createServerRouter({ mounts }), {
|
|
416
|
+
prerender: './src/prerender.ts',
|
|
417
|
+
}),
|
|
418
|
+
];
|
|
373
419
|
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
420
|
+
// src/prerender.ts
|
|
421
|
+
import { definePrerender } from 'lit-ui-router-ssr/vite';
|
|
422
|
+
|
|
423
|
+
export default definePrerender((site) => ({
|
|
424
|
+
mounts,
|
|
425
|
+
router,
|
|
426
|
+
paths,
|
|
427
|
+
renderShell,
|
|
428
|
+
document,
|
|
429
|
+
}));
|
|
378
430
|
```
|
|
379
431
|
|
|
380
|
-
|
|
381
|
-
|
|
432
|
+
The entry then uses plain static imports; see
|
|
433
|
+
[Prerender with Vite](https://lit-ui-router.dev/guides/prerender-with-vite). An entry node runs
|
|
434
|
+
directly gets the same order from `node --import @lit-labs/ssr/lib/install-global-dom-shim.js`.
|
|
435
|
+
`UiViewRenderer` draws the served
|
|
382
436
|
class, and a `<ui-view>` nothing defined on the server renders as an inert element with an empty
|
|
383
437
|
part pair — no error, and every page's body missing. In development `prerender()` warns when the
|
|
384
438
|
registry holds no `<ui-view>`.
|
package/dist/client.js
CHANGED
|
@@ -7,7 +7,6 @@ import { getDirectiveClass } from "lit/directive-helpers.js";
|
|
|
7
7
|
import { provideContext } from "lit-ui-router/context";
|
|
8
8
|
import { UiView } from "lit-ui-router/pure";
|
|
9
9
|
import { seed } from "ui-router-server/ssr/client";
|
|
10
|
-
import "#dev-gate";
|
|
11
10
|
import { adoptUiViewContext } from "./adopt-context.js";
|
|
12
11
|
import { isLightDomElement } from "./light-dom-brand.js";
|
|
13
12
|
import { servedMarkerPrefix } from "./served-markers.js";
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","mappings":"AAOA,SAAS,eAAe;AACxB,SAAS,mBAAmB;AAE5B,SAAS,YAAY,kBAAkB;AAEvC,SAAS,UAAU,cAAc;AAEjC,SAAS,iBAAiB;AAE1B,SAAS,yBAAyB;AAClC,SAAS,sBAAsB;AAC/B,SAAS,cAAc;AAEvB,SAAS,YAAY;
|
|
1
|
+
{"version":3,"file":"client.js","mappings":"AAOA,SAAS,eAAe;AAC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W,iBAAiB,WAAW,SAAS,MAAM;CAC5D,MAAM,QAAQ,aAAa;CAC3B,IAAI,WAAW;CAEf,MAAM,YAA2B,MAAM,SAAS,UAAU;EACxD,IAAI,YAAY,aAAa,YAAY;EACzC,UAAU,MAAM,SAAS,KAAK;CAChC;CAEA,IAAI;CAEJ,IAAI;EACF,UAAU,UACR,WACA,OACA,eACA,QACI;GAAE;GAAU,OAAO;EAAM,IACzB;GAAE;GAAU,OAAO;GAAM,OAAO,UAAU,WAAW,MAAM;EAAE,CACnE;CACF,SAAS,OAAO;EACd,OAAO,OAAO,WAAW,aAAa;EACtC,MAAM,YAAY,SAAS;EAE3B,OAAO;GAAE,SAAS;GAAQ,WAAW;GAAU;EAAM;CACvD;CAEA,MAAM,YAAY,SAAS;CAC3B,QAAQ;CAGR,IAAI,WAAW,KAAK,UAAU,UAAU,OAAO,QAAQ,QAAQ;CAG/D,OAAO;EAAE,SAAS;EAAW,WAAW;CAAS;AACnD;AAGA,MAAM,oBACJ,WACA,SACA,WACuB;CACvB,IAAI,CAAC,WAAW,OAAO;CAEvB,OAAO,gBAAgB,WAAW,iBAAiB,WAAW,MAAM,IAChE,YACA;AACN;AAGA,MAAM,aAAa,YACjB,WAAW,UAAU,EAAE,OAAO,QAAQ,MAAM,IAAI,CAAC","names":[],"ignoreList":[],"sources":["../src/client.ts"]}
|
package/dist/dev-warn.js
CHANGED
package/dist/dev-warn.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev-warn.js","mappings":"
|
|
1
|
+
{"version":3,"file":"dev-warn.js","mappings":"AAeA,OAAO,SAAS,0BAA0B,SAAwB,CAOlE;AAWA,OAAO,SAAS,uBAAuB,SAAwB,CAO/D;AAsBA,OAAO,SAAS,uBAAuB,SAAwB,CAc/D","names":[],"ignoreList":[],"sources":["../src/dev-warn.ts"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","mappings":"AAMA,
|
|
1
|
+
{"version":3,"file":"index.js","mappings":"AAMA,SAIE,iBAOK;AAEP,SAEE,cAEK;AAEP,SAAS,4BAA4B;AAErC,SAA8C,iBAAiB;AAQ/D,SAAS,sBAAsB","names":[],"ignoreList":[],"sources":["../../src/index.ts"]}
|
|
@@ -3,6 +3,7 @@ import { collectResultSync } from "@lit-labs/ssr/lib/render-result.js";
|
|
|
3
3
|
import { provideRouter, withRouterSync } from "lit-ui-router/context";
|
|
4
4
|
import { isString } from "@uirouter/core";
|
|
5
5
|
import { prerender as prerenderSite } from "ui-router-server/prerender";
|
|
6
|
+
import { dehydrate as dehydrateLanded } from "ui-router-server/ssr";
|
|
6
7
|
import { devGate } from "#dev-gate";
|
|
7
8
|
import { LightElementRenderer } from "./light-element-renderer.js";
|
|
8
9
|
import { responder } from "./respond.js";
|
|
@@ -45,6 +46,8 @@ export const signatureBlock = (signature) => {
|
|
|
45
46
|
const json = JSON.stringify(signature).replaceAll("<", "\\u003c").replaceAll(">", "\\u003e");
|
|
46
47
|
return `<script type="application/json" ${signatureAttribute}>${json}<\/script>`;
|
|
47
48
|
};
|
|
49
|
+
const utf8Length = (text) => new TextEncoder().encode(text).length;
|
|
50
|
+
const payloadBytes = (router, drawn) => utf8Length(signatureBlock(signatureOf(router, drawn))) - utf8Length(signatureBlock(signatureOf(router)));
|
|
48
51
|
export const renderPage = (body, router, root, elementRenderers, drawn) => signatureBlock(signatureOf(router, drawn)) + withRouterSync(router, () => collectResultSync(render(body, {
|
|
49
52
|
eventTargetStack: rootedStack(root),
|
|
50
53
|
elementRenderers,
|
|
@@ -53,15 +56,32 @@ export const renderPage = (body, router, root, elementRenderers, drawn) => signa
|
|
|
53
56
|
const warnUnregistered = () => {
|
|
54
57
|
if (!devGate()) return;
|
|
55
58
|
if (globalThis.customElements?.get("ui-view")) return;
|
|
56
|
-
console.warn("lit-ui-router-ssr: <ui-view> is not defined on the current customElements registry, so every <ui-view> on these pages renders empty. The DOM shim replaces the registry when it finishes installing: load lit-ui-router-ssr/register by dynamic import after the shim, or preload the shim with node --import.");
|
|
59
|
+
console.warn("lit-ui-router-ssr: <ui-view> is not defined on the current customElements registry, so every <ui-view> on these pages renders empty. The DOM shim replaces the registry when it finishes installing: prerender through serverRouterPlugin from lit-ui-router-ssr/vite, which preloads both, load lit-ui-router-ssr/register by dynamic import after the shim, or preload the shim with node --import.");
|
|
57
60
|
};
|
|
58
61
|
export async function prerender(options) {
|
|
59
|
-
const { router, renderShell, document, elementRenderers = [UiViewRenderer, LightElementRenderer], root = new EventTarget(), write = nodeWrite, payload, responses, origin = "http://lit-ui-router-ssr", ...site } = options;
|
|
62
|
+
const { router, renderShell, document, elementRenderers = [UiViewRenderer, LightElementRenderer], root = new EventTarget(), write = nodeWrite, dehydrate: dehydrateOptions, payload, responses, origin = "http://lit-ui-router-ssr", ...site } = options;
|
|
63
|
+
if (dehydrateOptions && payload) throw new Error("prerender: pass `dehydrate` or `payload`, not both; a `payload` hook calls `dehydrate()` itself");
|
|
60
64
|
warnUnregistered();
|
|
61
|
-
const
|
|
62
|
-
if (
|
|
65
|
+
const draw = (transition, context) => {
|
|
66
|
+
if (dehydrateOptions) return dehydrateLanded(transition, dehydrateOptions);
|
|
67
|
+
return { payload: payload?.(transition, context) };
|
|
68
|
+
};
|
|
69
|
+
const drawLanded = (context) => {
|
|
70
|
+
if (!dehydrateOptions && !payload) return {};
|
|
63
71
|
const landed = router.globals.successfulTransitions.peekTail();
|
|
64
|
-
return landed
|
|
72
|
+
return landed ? draw(landed, context) : {};
|
|
73
|
+
};
|
|
74
|
+
const reports = new Map();
|
|
75
|
+
const renderTemplate = (body, context) => {
|
|
76
|
+
const { payload: drawn, unserializable } = drawLanded(context);
|
|
77
|
+
if (drawn) {
|
|
78
|
+
const bytes = payloadBytes(router, drawn);
|
|
79
|
+
reports.set(context.file, unserializable ? {
|
|
80
|
+
bytes,
|
|
81
|
+
unserializable
|
|
82
|
+
} : { bytes });
|
|
83
|
+
}
|
|
84
|
+
return renderPage(body, router, root, elementRenderers, drawn);
|
|
65
85
|
};
|
|
66
86
|
const renderLit = async (verdict, siteContext) => {
|
|
67
87
|
const context = {
|
|
@@ -69,7 +89,7 @@ export async function prerender(options) {
|
|
|
69
89
|
root
|
|
70
90
|
};
|
|
71
91
|
const body = await renderShell(verdict, context);
|
|
72
|
-
const markup = isString(body) ? body :
|
|
92
|
+
const markup = isString(body) ? body : renderTemplate(body, context);
|
|
73
93
|
return document ? document(markup, context) : markup;
|
|
74
94
|
};
|
|
75
95
|
const uninstall = provideRouter(root, router);
|
|
@@ -78,13 +98,22 @@ export async function prerender(options) {
|
|
|
78
98
|
if (responses === void 0) throw new Error(`prerender: '${path}' matched response state '${verdict.state}'; pass \`responses\` to answer it`);
|
|
79
99
|
return responder(router, responses)(verdict, new Request(new URL(path, origin)));
|
|
80
100
|
};
|
|
101
|
+
const result = await prerenderSite({
|
|
102
|
+
...site,
|
|
103
|
+
render: renderLit,
|
|
104
|
+
respond,
|
|
105
|
+
write
|
|
106
|
+
});
|
|
107
|
+
const pages = result.pages.map((page) => {
|
|
108
|
+
const report = reports.get(page.file);
|
|
109
|
+
return report ? {
|
|
110
|
+
...page,
|
|
111
|
+
payload: report
|
|
112
|
+
} : page;
|
|
113
|
+
});
|
|
81
114
|
return {
|
|
82
|
-
...
|
|
83
|
-
|
|
84
|
-
render: renderLit,
|
|
85
|
-
respond,
|
|
86
|
-
write
|
|
87
|
-
}),
|
|
115
|
+
...result,
|
|
116
|
+
pages,
|
|
88
117
|
root
|
|
89
118
|
};
|
|
90
119
|
} finally {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prerender.js","mappings":"AACA,SAAS,cAAc;AAEvB,SAAS,yBAAyB;AAIlC,SAAS,eAAe,sBAAsB;AAC9C,SAAS,gBAAgB;AAEzB,SAAS,aAAa,qBAAqB;AAQ3C,SAAS,eAAe;AAExB,SAAS,4BAA4B;AACrC,SAAS,iBAAiB;AAE1B,SAAS,gBAAgB,SAAS,0BAA0B;AAC5D,SA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E,GAAG;IAAM,SAAS;GAAO,IAAI;EACjD,CAAC;EAED,OAAO;GAAE,GAAG;GAAQ;GAAO;EAAK;CAClC,UAAU;EACR,UAAU;CACZ;AACF","names":[],"ignoreList":[],"sources":["../../src/prerender.ts"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DefType } from "@uirouter/core";
|
|
2
2
|
export const signatureAttribute = "data-lit-ui-router-ssr";
|
|
3
3
|
export const signatureSelector = `script[type="application/json"][${signatureAttribute}]`;
|
|
4
|
-
export const packageVersion = "0.
|
|
4
|
+
export const packageVersion = "0.8.1";
|
|
5
5
|
export const urlParamsOf = (state, params) => Object.fromEntries(state.parameters().flatMap((param) => param.location === DefType.CONFIG ? [] : [[param.id, param.type.encode(params[param.id])]]));
|
|
6
6
|
export const routeOf = ({ $current, params }) => [$current.name, urlParamsOf($current, params)];
|
|
7
7
|
//# sourceMappingURL=signature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite-preload.js","mappings":"AACA,OAAO,MAAM,WAA8B,CACzC,8CACF;AASA,OAAO,MAAM,cACX,MACA,YACa,CACb,GAAG,IAAI,IAAI;CAAC,GAAG;CAAM;CAA8B,GAAG;AAAO,CAAC,CAChE","names":[],"ignoreList":[],"sources":["../../src/vite-preload.ts"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { serverRouterPlugin as siteRouterPlugin } from "ui-router-server/vite";
|
|
2
|
+
import { DOM_SHIM, litPreload } from "./vite-preload.js";
|
|
3
|
+
const loadPrerender = async () => (await import("./prerender.js")).prerender;
|
|
4
|
+
export function definePrerender(script) {
|
|
5
|
+
return async (build) => {
|
|
6
|
+
const [options, prerender] = await Promise.all([script(build), loadPrerender()]);
|
|
7
|
+
const { root: _root, ...result } = await prerender({
|
|
8
|
+
...build,
|
|
9
|
+
...options
|
|
10
|
+
});
|
|
11
|
+
return result;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export function serverRouterPlugin(router, options = {}) {
|
|
15
|
+
const { shim = DOM_SHIM, ...siteOptions } = options;
|
|
16
|
+
const { prerender } = siteOptions;
|
|
17
|
+
if (prerender === void 0) return siteRouterPlugin(router, siteOptions);
|
|
18
|
+
const { entry, preload = [] } = typeof prerender === "string" ? { entry: prerender } : prerender;
|
|
19
|
+
return siteRouterPlugin(router, {
|
|
20
|
+
...siteOptions,
|
|
21
|
+
prerender: {
|
|
22
|
+
entry,
|
|
23
|
+
preload: litPreload(shim, preload)
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=vite.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite.js","mappings":"AAcA,SAAS,sBAAsB,wBAAwB;AASvD,SAAS,UAAU,kBAAkB;AAmDrC,MAAM,gBAAgB,aAAa,MAAM,OAAO,kBAAiB,CAAE;AA0BnE,OAAO,SAAS,gBAAgB,QAAyC;CACvE,OAAO,OAAO,UAAU;EACtB,MAAM,CAAC,SAAS,aAAa,MAAM,QAAQ,IAAI,CAC7C,OAAO,KAAK,GACZ,cAAc,CAChB,CAAC;EAGD,MAAM,EAAE,MAAM,OAAO,GAAG,WAAW,MAAM,UAAU;GACjD,GAAG;GACH,GAAG;EACL,CAAC;EAED,OAAO;CACT;AACF;AA+BA,OAAO,SAAS,mBACd,QACA,UAAqC,CAAC,GAClB;CACpB,MAAM,EAAE,OAAO,UAAU,GAAG,gBAAgB;CAC5C,MAAM,EAAE,cAAc;CAEtB,IAAI,cAAc,QAAW,OAAO,iBAAiB,QAAQ,WAAW;CAExE,MAAM,EAAE,OAAO,UAAU,CAAC,MAExB,OAAO,cAAc,WAAW,EAAE,OAAO,UAAU,IAAI;CAEzD,OAAO,iBAAiB,QAAQ;EAC9B,GAAG;EACH,WAAW;GAAE;GAAO,SAAS,WAAW,MAAM,OAAO;EAAE;CACzD,CAAC;AACH","names":[],"ignoreList":[],"sources":["../../src/vite.ts"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* @module
|
|
6
6
|
*/
|
|
7
|
-
export { type EmittedPage, type FileWriter, prerender, type PrerenderOptions, type PrerenderResult, type PrerenderTally, type RedirectLine, type RenderContext } from "./prerender.js";
|
|
7
|
+
export { type EmittedPage, type FileWriter, type PagePayload, prerender, type PrerenderedPage, type PrerenderOptions, type PrerenderResult, type PrerenderTally, type RedirectLine, type RenderContext } from "./prerender.js";
|
|
8
8
|
export { type ResolvePayload, settle, type SettleOptions } from "ui-router-server/ssr";
|
|
9
9
|
export { LightElementRenderer } from "./light-element-renderer.js";
|
|
10
10
|
export { type BoundResponses, type Responder, responder } from "./respond.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","mappings":";;;;;;AAMA,cACO,kBACA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","mappings":";;;;;;AAMA,cACO,kBACA,iBACA,aACL,gBACK,sBACA,uBACA,sBACA,qBACA,mBACA,qBACA;AAEP,cACO,gBACL,aACK,qBACA;AAEP,SAAS,4BAA4B;AAErC,cAAc,qBAAqB,WAAW,iBAAiB;AAE/D,cACE,iBACA,iBACA,wBACK;AAEP,SAAS,sBAAsB","names":[],"ignoreList":[],"sources":["../src/index.ts"]}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","mappings":"AAMA,
|
|
1
|
+
{"version":3,"file":"index.js","mappings":"AAMA,SAIE,iBAOK;AAEP,SAEE,cAEK;AAEP,SAAS,4BAA4B;AAErC,SAA8C,iBAAiB;AAQ/D,SAAS,sBAAsB","names":[],"ignoreList":[],"sources":["../src/index.ts"]}
|
package/dist/prerender.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ import type { TemplateResult } from "lit";
|
|
|
3
3
|
import type { Transition } from "@uirouter/core";
|
|
4
4
|
import type { UIRouterLit } from "lit-ui-router";
|
|
5
5
|
import type { Verdict } from "ui-router-server";
|
|
6
|
-
import type { FileWriter, PrerenderOptions as SitePrerenderOptions, PrerenderResult as SitePrerenderResult, RenderContext as SiteRenderContext } from "ui-router-server/prerender";
|
|
7
|
-
import type { ResolvePayload } from "ui-router-server/ssr";
|
|
6
|
+
import type { EmittedPage, FileWriter, PrerenderOptions as SitePrerenderOptions, PrerenderResult as SitePrerenderResult, RenderContext as SiteRenderContext } from "ui-router-server/prerender";
|
|
7
|
+
import type { DehydrateOptions, DehydrateResult, ResolvePayload } from "ui-router-server/ssr";
|
|
8
8
|
import type { BoundResponses } from "./respond.js";
|
|
9
9
|
export type { EmittedPage, FileWriter, PrerenderTally, RedirectLine } from "ui-router-server/prerender";
|
|
10
10
|
type ShellVerdict = Extract<Verdict, {
|
|
@@ -79,32 +79,78 @@ export interface PrerenderOptions extends Omit<SitePrerenderOptions, "render" |
|
|
|
79
79
|
/** Writes a file. Defaults to `node:fs`, imported lazily on first write. */
|
|
80
80
|
write?: FileWriter;
|
|
81
81
|
/**
|
|
82
|
-
* Draws
|
|
82
|
+
* Draws each rendered page's resolve payload with `dehydrate` from
|
|
83
|
+
* `ui-router-server/ssr`, called with these options on the transition the
|
|
83
84
|
* router last landed, once `renderShell` has returned a template. The
|
|
84
85
|
* payload's `resolves` go into the page's hydration signature, beside the
|
|
85
86
|
* state and parameters the router stands on, and the client adopts them on
|
|
86
|
-
* boot in place of running those resolve functions.
|
|
87
|
-
*
|
|
87
|
+
* boot in place of running those resolve functions. Pass `{}` to draw every
|
|
88
|
+
* resolve `dehydrate` draws by default. Without this option or
|
|
89
|
+
* {@link PrerenderOptions.payload | `payload`}, no page carries resolves.
|
|
88
90
|
*
|
|
89
|
-
* `dehydrate`
|
|
90
|
-
*
|
|
91
|
+
* `dehydrate`'s documentation says which values it leaves out and how
|
|
92
|
+
* `shouldDehydrate` and `transport` act. The payload's
|
|
91
93
|
* `transported` marks go into the signature too, so a value a transporter
|
|
92
94
|
* carried is rebuilt when `bootstrap()` gets the same `transport`.
|
|
93
95
|
*
|
|
94
96
|
* @example
|
|
95
97
|
* ```ts
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
* console.warn(`${path}: ${state}.${token} re-runs on the client`);
|
|
100
|
-
* return payload;
|
|
98
|
+
* dehydrate: {
|
|
99
|
+
* shouldDehydrate: ({ token }) => token !== 'manifest',
|
|
100
|
+
* transport,
|
|
101
101
|
* },
|
|
102
102
|
* ```
|
|
103
103
|
*/
|
|
104
|
+
dehydrate?: DehydrateOptions;
|
|
105
|
+
/**
|
|
106
|
+
* Draws the resolve payload for a rendered page by hand, in place of
|
|
107
|
+
* {@link PrerenderOptions.dehydrate | `dehydrate`}: handed the transition the
|
|
108
|
+
* router last landed, once `renderShell` has returned a template, it returns
|
|
109
|
+
* the payload the page's signature carries, or `undefined` to write none.
|
|
110
|
+
* Passing both this and `dehydrate` throws.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* Shape the payload `dehydrate` draws before it is written:
|
|
114
|
+
* ```ts
|
|
115
|
+
* import { dehydrate } from 'ui-router-server/ssr';
|
|
116
|
+
*
|
|
117
|
+
* payload: (transition, { path }) =>
|
|
118
|
+
* path.startsWith('/drafts/')
|
|
119
|
+
* ? undefined
|
|
120
|
+
* : dehydrate(transition, { transport }).payload,
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
104
123
|
payload?: (transition: Transition, context: RenderContext) => ResolvePayload | undefined;
|
|
105
124
|
}
|
|
125
|
+
/** What a page's hydration signature carries of its resolve payload. */
|
|
126
|
+
export interface PagePayload {
|
|
127
|
+
/**
|
|
128
|
+
* The bytes the payload adds to the page's signature as written: its
|
|
129
|
+
* `resolves` and `transported` members, escaped as the block spells them.
|
|
130
|
+
*/
|
|
131
|
+
bytes: number;
|
|
132
|
+
/**
|
|
133
|
+
* The resolves {@link PrerenderOptions.dehydrate | `dehydrate`} left out of
|
|
134
|
+
* the payload because their value is not plain JSON data and no transporter
|
|
135
|
+
* carries it, each to re-run on the client. Present only when `dehydrate`
|
|
136
|
+
* drew the payload: a {@link PrerenderOptions.payload | `payload`} hook
|
|
137
|
+
* returns the payload alone.
|
|
138
|
+
*/
|
|
139
|
+
unserializable?: DehydrateResult["unserializable"];
|
|
140
|
+
}
|
|
141
|
+
/** A page {@link prerender} emitted. */
|
|
142
|
+
export interface PrerenderedPage extends EmittedPage {
|
|
143
|
+
/**
|
|
144
|
+
* What the page's signature carries of its resolve payload. Absent on a page
|
|
145
|
+
* that carries none: one drawn with no payload, one `renderShell` returned
|
|
146
|
+
* as a string, and a response state's body.
|
|
147
|
+
*/
|
|
148
|
+
payload?: PagePayload;
|
|
149
|
+
}
|
|
106
150
|
/** What {@link prerender} did. */
|
|
107
|
-
export interface PrerenderResult extends SitePrerenderResult {
|
|
151
|
+
export interface PrerenderResult extends Omit<SitePrerenderResult, "pages"> {
|
|
152
|
+
/** Every page emitted or planned, in enumeration order. */
|
|
153
|
+
pages: PrerenderedPage[];
|
|
108
154
|
/** The root event target, created or passed through. */
|
|
109
155
|
root: EventTarget;
|
|
110
156
|
}
|
|
@@ -150,9 +196,12 @@ export declare const renderPage: (body: TemplateResult, router: UIRouterLit, roo
|
|
|
150
196
|
* A rendered page opens on its hydration signature: a JSON data block,
|
|
151
197
|
* `<script type="application/json" data-lit-ui-router-ssr>`, naming this
|
|
152
198
|
* package's version and the state and parameter values the router stood on,
|
|
153
|
-
* which `hydrateRoot()` reads before it touches the document.
|
|
154
|
-
* {@link PrerenderOptions.
|
|
155
|
-
*
|
|
199
|
+
* which `hydrateRoot()` reads before it touches the document.
|
|
200
|
+
* {@link PrerenderOptions.dehydrate | `dehydrate`}, or a
|
|
201
|
+
* {@link PrerenderOptions.payload | `payload`} hook, adds the resolved values
|
|
202
|
+
* the page was drawn with, which `bootstrap()` adopts; the page's entry in
|
|
203
|
+
* the result's `pages` reports the bytes they add and, from `dehydrate`, the
|
|
204
|
+
* resolves left to re-run on the client. A `renderShell`
|
|
156
205
|
* that returns a string is written as-is, with no signature, so the client
|
|
157
206
|
* renders it cold.
|
|
158
207
|
*
|
|
@@ -166,6 +215,7 @@ export declare const renderPage: (body: TemplateResult, router: UIRouterLit, roo
|
|
|
166
215
|
* @returns what was emitted, planned or written
|
|
167
216
|
* @throws an `Error` when neither `mounts` nor `resolver` is supplied
|
|
168
217
|
* @throws an `Error` when the 404 document needs a default probe and only a `resolver` is supplied
|
|
218
|
+
* @throws an `Error` when both `dehydrate` and `payload` are supplied
|
|
169
219
|
*
|
|
170
220
|
* @example
|
|
171
221
|
* ```ts
|
package/dist/prerender.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prerender.d.ts","mappings":"AAEA,cAAc,kBAAkB;AAEhC,cAAc,sBAAsB;AACpC,cAAc,kBAAkB;AAChC,cAAc,mBAAmB;AAGjC,cAAc,eAAe;AAE7B,cACE,YACA,oBAAoB,sBACpB,mBAAmB,qBACnB,iBAAiB,yBACZ;
|
|
1
|
+
{"version":3,"file":"prerender.d.ts","mappings":"AAEA,cAAc,kBAAkB;AAEhC,cAAc,sBAAsB;AACpC,cAAc,kBAAkB;AAChC,cAAc,mBAAmB;AAGjC,cAAc,eAAe;AAE7B,cACE,aACA,YACA,oBAAoB,sBACpB,mBAAmB,qBACnB,iBAAiB,yBACZ;AAEP,cACE,kBACA,iBACA,sBACK;AAKP,cAAc,sBAAsB;AAIpC,cACE,aACA,YACA,gBACA,oBACK;KAEF,eAAe,QAAQ,SAAS;CAAE,MAAM;AAAQ;;AAgCrD,iBAAiB,sBAAsB,kBAAkB;;CAEvD,MAAM;AACR;;;;;AAMA,iBAAiB,yBAAyB,KACxC,sBACA,WAAW,YAAY,SACvB;;;;;;CAMA,QAAQ;;;;;;;CAOR,cACE,SAAS,cACT,SAAS,kBACN,0BAA0B,QAAQ;;;;;;CAMvC,YAAY,cAAc,SAAS,2BAA2B;;;;;;;;CAQ9D,OAAO;;;;;;;;;;;CA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