lit-ui-router-ssr 0.1.1 → 0.2.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/README.md +17 -5
- package/dist/client.d.ts +46 -4
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +37 -18
- package/dist/client.js.map +1 -1
- package/dist/development/client.js +44 -18
- package/dist/development/client.js.map +1 -1
- package/dist/development/prerender.js +88 -52
- package/dist/development/prerender.js.map +1 -1
- package/dist/development/signature.js +4 -0
- package/dist/development/signature.js.map +1 -0
- package/dist/prerender.d.ts +33 -3
- package/dist/prerender.d.ts.map +1 -1
- package/dist/prerender.js +82 -47
- package/dist/prerender.js.map +1 -1
- package/dist/signature.d.ts +39 -0
- package/dist/signature.d.ts.map +1 -0
- package/dist/signature.js +4 -0
- package/dist/signature.js.map +1 -0
- package/package.json +2 -2
- package/src/client.ts +131 -33
- package/src/prerender.ts +169 -78
- package/src/signature.ts +43 -0
package/README.md
CHANGED
|
@@ -22,6 +22,10 @@ imports the pre-1.0 renderer or re-derives the incantation.
|
|
|
22
22
|
per page — so a template's `<ui-router>` descendants answer `context-request` and its `srefHref`
|
|
23
23
|
attribute directives emit real hrefs. The render passes `deferHydration`, so every custom element
|
|
24
24
|
on the page carries `defer-hydration` and renders nothing until the client's walk reaches it.
|
|
25
|
+
- **The hydration signature.** A page rendered from a template opens on a JSON data block,
|
|
26
|
+
`<script type="application/json" data-lit-ui-router-ssr>`, naming this package's version, the
|
|
27
|
+
state the router stood on, and that state's url parameter values. A page `renderShell` returns
|
|
28
|
+
as a string is written as-is, without one.
|
|
25
29
|
- **The emit loop.** Verdict to file name, redirect to rules line, tally, warnings for paths that
|
|
26
30
|
matched nothing.
|
|
27
31
|
- **The host rules file.** `_redirects` by default, every generated line paired with and without a
|
|
@@ -345,11 +349,20 @@ if (!release) render(page(router), root);
|
|
|
345
349
|
`hydrateRoot()`. The walk commits `.uiRouter` onto `<ui-router>` and each `<ui-view>` re-seeks the
|
|
346
350
|
router before its own first render, so every view finds the settled router rather than the
|
|
347
351
|
placeholder it registered against. Nothing constrains when `lit-ui-router-ssr/register` is imported.
|
|
352
|
+
- **The signature decides first.** `hydrateRoot()` reads the container's hydration signature before
|
|
353
|
+
it touches the document, and returns `false` over an emptied container when there is none — a
|
|
354
|
+
cold client render, a dev server, a page from an earlier `prerender()`, a string `renderShell` —
|
|
355
|
+
or when it names another release line: below 1.0 a document adopts only on the client's own minor,
|
|
356
|
+
from 1.0 its own major. The development build warns on that skew, naming both versions, and on a
|
|
357
|
+
block no `lit-part` marker follows, which is what a comment-stripping minifier leaves. The emptied
|
|
358
|
+
container is what lets `render(page(router), root)` draw the page once. A container it adopts
|
|
359
|
+
keeps the block. `readHydrationSignature(container)` returns the parsed `HydrationSignature`, or
|
|
360
|
+
`null` when there is none or it does not parse to an object with a string `version`; only
|
|
361
|
+
`version` is typed, so narrow `state` and `params` before use.
|
|
348
362
|
- **`hydrateRoot(container, value, options?)`** provides `adoptUiViewContext` under `container` with
|
|
349
363
|
core's `provideContext()` and runs one `hydrate()` over `container`. It returns that provider's
|
|
350
|
-
release function, or `false` when there is nothing to adopt
|
|
351
|
-
|
|
352
|
-
call returns.
|
|
364
|
+
release function, or `false` when there is nothing to adopt. Release it once the page has settled;
|
|
365
|
+
a nested view wakes on its parent's own update, after this call returns.
|
|
353
366
|
- **One walk wakes the page.** A served `<ui-view>` sleeps under `defer-hydration` and renders
|
|
354
367
|
nothing. Removing the attribute wakes it: it re-seeks its router, requests `adoptUiViewContext`
|
|
355
368
|
and calls the adopter it gets, which adopts the nodes the view holds. A view the app detaches
|
|
@@ -383,8 +396,7 @@ if (!release) render(page(router), root);
|
|
|
383
396
|
production as in development. `hydrateRoot()`'s `onAdopt(view, outcome, error)` option receives
|
|
384
397
|
the same reports for every view its walk reaches, a view the pin adopts after the release included.
|
|
385
398
|
- **A mutated document throws.** `hydrateRoot()` rethrows what `hydrate()` threw, over a container it
|
|
386
|
-
first
|
|
387
|
-
hidden behind the prefix. The caller renders over the container.
|
|
399
|
+
first empties. The caller renders into it.
|
|
388
400
|
|
|
389
401
|
### How this compares
|
|
390
402
|
|
package/dist/client.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { renderLight } from "@lit-labs/ssr-client/directives/render-light.js";
|
|
2
2
|
import type { RenderOptions } from "lit";
|
|
3
|
+
import type { HydrationSignature } from "./signature.js";
|
|
3
4
|
export { adoptUiViewContext, type AdoptableView, type AdoptUiViewContext, type AdoptUiViewContextKey } from "./adopt-context.js";
|
|
4
5
|
export { isServedViewClass, type ServedUiView, type ServedUiViewConstructor, servedViewBrand, withServedRender } from "./served-view.js";
|
|
6
|
+
export type { HydrationSignature } from "./signature.js";
|
|
5
7
|
/**
|
|
6
8
|
* What a served `<ui-view>`'s wake came to.
|
|
7
9
|
*
|
|
@@ -89,8 +91,49 @@ declare global {
|
|
|
89
91
|
*/
|
|
90
92
|
export declare const uiViewSlot: typeof renderLight;
|
|
91
93
|
/**
|
|
94
|
+
* Reads the hydration signature `prerender()` wrote ahead of the render a
|
|
95
|
+
* container holds: the version of this package that drew the document, and
|
|
96
|
+
* the state and parameter values it was drawn for.
|
|
97
|
+
*
|
|
98
|
+
* The signature is a `<script type="application/json" data-lit-ui-router-ssr>`
|
|
99
|
+
* data block among the container's own children, so this reads no deeper than
|
|
100
|
+
* they are; the first one wins. It reads the same before and after a
|
|
101
|
+
* {@link hydrateRoot} that adopts, which leaves the block in place; one that
|
|
102
|
+
* returns `false` clears the container.
|
|
103
|
+
*
|
|
104
|
+
* Only `version` is checked. `state` and `params` are whatever the block
|
|
105
|
+
* carries, so narrow them before use. Read it before {@link hydrateRoot}, which
|
|
106
|
+
* clears a container it does not adopt.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```ts
|
|
110
|
+
* import { hydrateRoot, readHydrationSignature } from 'lit-ui-router-ssr/client';
|
|
111
|
+
*
|
|
112
|
+
* await booted;
|
|
113
|
+
* const { state } = readHydrationSignature(root) ?? {};
|
|
114
|
+
* const drawnForBoot = state === router.globals.current.name;
|
|
115
|
+
* const release = hydrateRoot(root, page(router));
|
|
116
|
+
* ```
|
|
117
|
+
*
|
|
118
|
+
* @param container - the element the server's markup was written into
|
|
119
|
+
* @returns the signature, or `null` when the container holds none, or one that
|
|
120
|
+
* does not parse to an object with a string `version`
|
|
121
|
+
*
|
|
122
|
+
* @category client
|
|
123
|
+
*/
|
|
124
|
+
export declare function readHydrationSignature(container: ParentNode): HydrationSignature | null;
|
|
125
|
+
/**
|
|
92
126
|
* Adopts a server-rendered container, and the `<ui-view>`s that wake under it.
|
|
93
127
|
*
|
|
128
|
+
* The container's {@link readHydrationSignature | hydration signature} is read
|
|
129
|
+
* first, and decides whether there is anything to adopt. A container with no
|
|
130
|
+
* signature renders cold, and so does one whose signature names another release
|
|
131
|
+
* line of this package — another minor below 1.0, another major from 1.0 — with
|
|
132
|
+
* a development warning naming both versions, and so does one whose signature
|
|
133
|
+
* no `lit-part` marker follows, as a comment-stripping minifier leaves it. Each
|
|
134
|
+
* time the container is emptied and this returns `false`, so the caller's
|
|
135
|
+
* `render()` draws the page once. A container this adopts keeps its signature.
|
|
136
|
+
*
|
|
94
137
|
* {@link adoptUiViewContext} is provided on `container` with core's
|
|
95
138
|
* `provideContext()` first, so a view woken by the walk finds it; `hydrate()`
|
|
96
139
|
* then runs over `container`. The walk reaches each `<ui-view>`'s {@link
|
|
@@ -120,9 +163,8 @@ export declare const uiViewSlot: typeof renderLight;
|
|
|
120
163
|
* the view, and to `options.onAdopt` when given. The pin carries that callback,
|
|
121
164
|
* so a view adopted after the release still reaches it.
|
|
122
165
|
*
|
|
123
|
-
* A `hydrate()` that throws is rethrown, over a container
|
|
124
|
-
*
|
|
125
|
-
* renders over it.
|
|
166
|
+
* A `hydrate()` that throws is rethrown, over a container emptied the same
|
|
167
|
+
* way. The caller renders into it.
|
|
126
168
|
*
|
|
127
169
|
* The boot is the router first: `router.start()`, await its first successful
|
|
128
170
|
* transition, then this call. The walk commits `.uiRouter` onto `<ui-router>`
|
|
@@ -143,7 +185,7 @@ export declare const uiViewSlot: typeof renderLight;
|
|
|
143
185
|
* @param container - the element the server's markup was written into
|
|
144
186
|
* @param value - the same template the server rendered, with every `<ui-view>` hole empty
|
|
145
187
|
* @param options - lit render options, passed on to `hydrate()`, and `onAdopt`
|
|
146
|
-
* @returns the function that releases the provider, or `false
|
|
188
|
+
* @returns the function that releases the provider, or `false`, over an emptied container, when there is nothing to adopt — no signature, as on a cold client render or a dev server, one from another release line, or one no render marker follows
|
|
147
189
|
*
|
|
148
190
|
* @category client
|
|
149
191
|
*/
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","mappings":"AAMA,SAAS,mBAAmB;AAG5B,cAAyB,qBAAqB;AAU9C,SACE,yBACK,oBACA,yBACA,6BACA;AACP,SACE,wBACK,mBACA,yBACL,iBACA,wBACK;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"client.d.ts","mappings":"AAMA,SAAS,mBAAmB;AAG5B,cAAyB,qBAAqB;AAU9C,cAAc,0BAA0B;AAExC,SACE,yBACK,oBACA,yBACA,6BACA;AACP,SACE,wBACK,mBACA,yBACL,iBACA,wBACK;AACP,cAAc,0BAA0B;;;;;;;;;;;;AAgBxC,YAAY,eAAe,YAAY,cAAc;;;;;;;AAQrD,OAAO,cAAM,sBAAuB;;;;;;AAOpC,iBAAiB,kBAAkB;;UAExB,SAAS;;UAET;AACX;;;;;;;AAQA,YAAY,mBAAmB,YAAY;;;;;;AAO3C,YAAY,iBACV,MAAM,SACN,SAAS,cACT;;;;;;;AASF,iBAAiB,2BAA2B,cAAc;;;;;;CAMxD,UAAU;AACZ;eAEe;WACH,oBAAoB;;EAE5B,iBAAiB;CACnB;AACF;;;;;;;;;;;;;;;;;;;;;;;AA6DA,OAAO,cAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0ThC,OAAO,iBAAS,uBACd,WAAW,aACV;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoIH,OAAO,iBAAS,YACd,WAAW,aACX,gBACA,UAAS,qBACR","names":[],"ignoreList":[],"sources":["../src/client.ts"]}
|
package/dist/client.js
CHANGED
|
@@ -7,6 +7,7 @@ import { provideContext } from "lit-ui-router/context";
|
|
|
7
7
|
import { UiView } from "lit-ui-router/pure";
|
|
8
8
|
import { adoptUiViewContext } from "./adopt-context.js";
|
|
9
9
|
import { servedMarkerPrefix } from "./served-markers.js";
|
|
10
|
+
import { packageVersion, signatureSelector } from "./signature.js";
|
|
10
11
|
export { adoptUiViewContext } from "./adopt-context.js";
|
|
11
12
|
export { isServedViewClass, servedViewBrand, withServedRender } from "./served-view.js";
|
|
12
13
|
const DEFER = "defer-hydration";
|
|
@@ -52,9 +53,8 @@ const report = (view, reporter, outcome, error) => {
|
|
|
52
53
|
try {
|
|
53
54
|
reporter?.(view, outcome, error);
|
|
54
55
|
} catch (thrown) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
});
|
|
56
|
+
if (typeof globalThis.reportError !== "function") throw thrown;
|
|
57
|
+
globalThis.reportError(thrown);
|
|
58
58
|
}
|
|
59
59
|
};
|
|
60
60
|
const isPart = (node, data) => node?.nodeType === Node.COMMENT_NODE && node.data.startsWith(data);
|
|
@@ -86,13 +86,6 @@ const revealServedMarkers = (node) => {
|
|
|
86
86
|
revealServedMarkers(child);
|
|
87
87
|
}
|
|
88
88
|
};
|
|
89
|
-
const revealEveryMarker = (node) => {
|
|
90
|
-
for (const child of node.childNodes) if (child.nodeType === Node.COMMENT_NODE) revealMarker(child);
|
|
91
|
-
else if (child instanceof Element) {
|
|
92
|
-
if (child.shadowRoot) revealEveryMarker(child.shadowRoot);
|
|
93
|
-
revealEveryMarker(child);
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
89
|
const dropServedRender = (view) => {
|
|
97
90
|
const children = [...view.childNodes];
|
|
98
91
|
const from = children.findIndex((child) => isPart(child, servedMarkerPrefix) || child instanceof Element && hasServedMarkers(child));
|
|
@@ -140,21 +133,47 @@ const pinAdopter = (view, reporter) => {
|
|
|
140
133
|
adopt(woken, reporter);
|
|
141
134
|
});
|
|
142
135
|
};
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
136
|
+
const parseSignature = (json) => {
|
|
137
|
+
try {
|
|
138
|
+
const signature = JSON.parse(json);
|
|
139
|
+
return typeof signature?.version === "string" ? signature : null;
|
|
140
|
+
} catch {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
export function readHydrationSignature(container) {
|
|
145
|
+
const block = signatureBlockIn(container);
|
|
146
|
+
return block ? parseSignature(block.text) : null;
|
|
147
|
+
}
|
|
148
|
+
const signatureBlockIn = (container) => [...container.children].find((child) => child.matches(signatureSelector));
|
|
149
|
+
const precedesRender = (block) => {
|
|
150
|
+
let node = block.nextSibling;
|
|
151
|
+
while (node?.nodeType === Node.TEXT_NODE && !node.data.trim()) node = node.nextSibling;
|
|
152
|
+
return isPart(node, "lit-part");
|
|
153
|
+
};
|
|
154
|
+
const releaseLine = (version) => {
|
|
155
|
+
const [major = "", minor = ""] = version.split(".");
|
|
156
|
+
return major === "0" ? `0.${minor}` : major;
|
|
157
|
+
};
|
|
158
|
+
const isAdoptable = (container) => {
|
|
159
|
+
const block = signatureBlockIn(container);
|
|
160
|
+
const signature = block && parseSignature(block.text);
|
|
161
|
+
if (!signature) return false;
|
|
162
|
+
if (releaseLine(signature.version) !== releaseLine(packageVersion)) {
|
|
163
|
+
signature.version;
|
|
148
164
|
return false;
|
|
149
165
|
}
|
|
166
|
+
if (precedesRender(block)) return true;
|
|
150
167
|
return false;
|
|
151
168
|
};
|
|
152
169
|
const makeCold = (container) => {
|
|
153
|
-
|
|
154
|
-
revealEveryMarker(container);
|
|
170
|
+
container.replaceChildren();
|
|
155
171
|
};
|
|
156
172
|
export function hydrateRoot(container, value, options = {}) {
|
|
157
|
-
if (!
|
|
173
|
+
if (!isAdoptable(container)) {
|
|
174
|
+
makeCold(container);
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
158
177
|
const { onAdopt, ...renderOptions } = options;
|
|
159
178
|
const release = provideContext(container, adoptUiViewContext, (view) => adopt(view, onAdopt));
|
|
160
179
|
try {
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","mappings":"AAKA,SAAS,eAAe;AACxB,SAAS,mBAAmB;AAE5B,SAAS,gBAAgB;AAEzB,SAAS,iBAAiB;AAE1B,SAAS,yBAAyB;AAClC,SAAS,sBAAsB;AAC/B,SAAS,cAAc;AACvB,SAAS,0BAA0B;AAEnC,SAAS,0BAA0B;
|
|
1
|
+
{"version":3,"file":"client.js","mappings":"AAKA,SAAS,eAAe;AACxB,SAAS,mBAAmB;AAE5B,SAAS,gBAAgB;AAEzB,SAAS,iBAAiB;AAE1B,SAAS,yBAAyB;AAClC,SAAS,sBAAsB;AAC/B,SAAS,cAAc;AACvB,SAAS,0BAA0B;AAEnC,SAAS,0BAA0B;AACnC,SAAS,gBAAgB,yBAAyB;AAGlD,SACE,0BAIK;AACP,SACE,mBAGA,iBACA,wBACK;AAIP,MAAM,QAAQ;AAqBd,OAAO,MAAM,uBAAuB;AAwDpC,MAAM,uBAAuB,kBAAkB,YAAY,CAAC;AAG5D,MAAM,4BAA4B,qBAAqB;CASrD,YAAY,MAAgB;EAC1B,MAAM,IAAI;EAEV,MAAM,OAAQ,KAAmB;EACjC,IAAI,EAAE,gBAAgB,UAAU;EAEhC,IAAI,WAAW,IAAI,GAAG,WAAW,MAAM,YAAY;EACnD,IAAI,KAAK,aAAa,KAAK,GAAG,KAAK,gBAAgB,KAAK;CAC1D;CAGA,SAA0B;EACxB,OAAO;CACT;CAGA,OAAgB,MAA0B;EACxC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AI;CACpD,IAAI,CAAC,WAAW,OAAO;CACvB,IAAI,YAAY,UAAU,OAAO,MAAM,YAAY,cAAc,GAAG;EAClE,UAA0B;EAC1B,OAAO;CACT;CACA,IAAI,eAAe,KAAK,GAAG,OAAO;CAElC,OAAO;AACT;AAGA,MAAM,YAAY,cAAiC;CACjD,UAAU,gBAAgB;AAC5B;AAqEA,OAAO,SAAS,YACd,WACA,OACA,UAA8B,CAAC,GACT;CACtB,IAAI,CAAC,YAAY,SAAS,GAAG;EAC3B,SAAS,SAAS;EAClB,OAAO;CACT;CACA,MAAM,EAAE,SAAS,GAAG,kBAAkB;CACtC,MAAM,UAAU,eAAe,WAAW,qBAAqB,SAC7D,MAAM,MAAM,OAAO,CACrB;CACA,IAAI;EACF,SAAS,eAAe,QAAQ,OAAO,WAAW,aAAa,CAAC;CAClE,SAAS,OAAO;EACd,QAAQ;EACR,SAAS,SAAS;EAClB,MAAM;CACR;CAEA,KAAK,MAAM,WAAW,UAAU,iBAAiB,IAAI,MAAM,EAAE,GAC3D,IAAI,EAAE,mBAAmB,SAAS,QAAQ,gBAAgB,KAAK;CAEjE,OAAO;AACT","names":[],"ignoreList":[],"sources":["../src/client.ts"]}
|
|
@@ -7,6 +7,7 @@ import { provideContext } from "lit-ui-router/context";
|
|
|
7
7
|
import { UiView } from "lit-ui-router/pure";
|
|
8
8
|
import { adoptUiViewContext } from "./adopt-context.js";
|
|
9
9
|
import { servedMarkerPrefix } from "./served-markers.js";
|
|
10
|
+
import { packageVersion, signatureSelector } from "./signature.js";
|
|
10
11
|
export { adoptUiViewContext } from "./adopt-context.js";
|
|
11
12
|
export { isServedViewClass, servedViewBrand, withServedRender } from "./served-view.js";
|
|
12
13
|
const DEFER = "defer-hydration";
|
|
@@ -52,9 +53,8 @@ const report = (view, reporter, outcome, error) => {
|
|
|
52
53
|
try {
|
|
53
54
|
reporter?.(view, outcome, error);
|
|
54
55
|
} catch (thrown) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
});
|
|
56
|
+
if (typeof globalThis.reportError !== "function") throw thrown;
|
|
57
|
+
globalThis.reportError(thrown);
|
|
58
58
|
}
|
|
59
59
|
};
|
|
60
60
|
const warnMismatch = (view, error) => {
|
|
@@ -89,13 +89,6 @@ const revealServedMarkers = (node) => {
|
|
|
89
89
|
revealServedMarkers(child);
|
|
90
90
|
}
|
|
91
91
|
};
|
|
92
|
-
const revealEveryMarker = (node) => {
|
|
93
|
-
for (const child of node.childNodes) if (child.nodeType === Node.COMMENT_NODE) revealMarker(child);
|
|
94
|
-
else if (child instanceof Element) {
|
|
95
|
-
if (child.shadowRoot) revealEveryMarker(child.shadowRoot);
|
|
96
|
-
revealEveryMarker(child);
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
92
|
const dropServedRender = (view) => {
|
|
100
93
|
const children = [...view.childNodes];
|
|
101
94
|
const from = children.findIndex((child) => isPart(child, servedMarkerPrefix) || child instanceof Element && hasServedMarkers(child));
|
|
@@ -145,21 +138,54 @@ const pinAdopter = (view, reporter) => {
|
|
|
145
138
|
adopt(woken, reporter);
|
|
146
139
|
});
|
|
147
140
|
};
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
141
|
+
const parseSignature = (json) => {
|
|
142
|
+
try {
|
|
143
|
+
const signature = JSON.parse(json);
|
|
144
|
+
return typeof signature?.version === "string" ? signature : null;
|
|
145
|
+
} catch {
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
export function readHydrationSignature(container) {
|
|
150
|
+
const block = signatureBlockIn(container);
|
|
151
|
+
return block ? parseSignature(block.text) : null;
|
|
152
|
+
}
|
|
153
|
+
const signatureBlockIn = (container) => [...container.children].find((child) => child.matches(signatureSelector));
|
|
154
|
+
const precedesRender = (block) => {
|
|
155
|
+
let node = block.nextSibling;
|
|
156
|
+
while (node?.nodeType === Node.TEXT_NODE && !node.data.trim()) node = node.nextSibling;
|
|
157
|
+
return isPart(node, "lit-part");
|
|
158
|
+
};
|
|
159
|
+
const releaseLine = (version) => {
|
|
160
|
+
const [major = "", minor = ""] = version.split(".");
|
|
161
|
+
return major === "0" ? `0.${minor}` : major;
|
|
162
|
+
};
|
|
163
|
+
const warnVersionSkew = (served) => {
|
|
164
|
+
console.warn("lit-ui-router-ssr: this document was prerendered by a release line this client does not adopt, so hydrateRoot() left it to a cold render. Prerender it again with the version the client ships. Prerendered by, then client:", served, packageVersion);
|
|
165
|
+
};
|
|
166
|
+
const warnMarkersStripped = () => {
|
|
167
|
+
console.warn("lit-ui-router-ssr: this document carries a hydration signature but no lit-part marker follows it, so hydrateRoot() left it to a cold render. hydrate() reads html comments: serve prerendered pages without stripping them.");
|
|
168
|
+
};
|
|
169
|
+
const isAdoptable = (container) => {
|
|
170
|
+
const block = signatureBlockIn(container);
|
|
171
|
+
const signature = block && parseSignature(block.text);
|
|
172
|
+
if (!signature) return false;
|
|
173
|
+
if (releaseLine(signature.version) !== releaseLine(packageVersion)) {
|
|
174
|
+
warnVersionSkew(signature.version);
|
|
153
175
|
return false;
|
|
154
176
|
}
|
|
177
|
+
if (precedesRender(block)) return true;
|
|
178
|
+
warnMarkersStripped();
|
|
155
179
|
return false;
|
|
156
180
|
};
|
|
157
181
|
const makeCold = (container) => {
|
|
158
|
-
|
|
159
|
-
revealEveryMarker(container);
|
|
182
|
+
container.replaceChildren();
|
|
160
183
|
};
|
|
161
184
|
export function hydrateRoot(container, value, options = {}) {
|
|
162
|
-
if (!
|
|
185
|
+
if (!isAdoptable(container)) {
|
|
186
|
+
makeCold(container);
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
163
189
|
const { onAdopt, ...renderOptions } = options;
|
|
164
190
|
const release = provideContext(container, adoptUiViewContext, (view) => adopt(view, onAdopt));
|
|
165
191
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","mappings":"AAKA,SAAS,eAAe;AACxB,SAAS,mBAAmB;AAE5B,SAAS,gBAAgB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C,OAAO;CACT;CACA,IAAI,eAAe,KAAK,GAAG,OAAO;CAClC,oBAAoB;CACpB,OAAO;AACT;AAGA,MAAM,YAAY,cAAiC;CACjD,UAAU,gBAAgB;AAC5B;AAqEA,OAAO,SAAS,YACd,WACA,OACA,UAA8B,CAAC,GACT;CACtB,IAAI,CAAC,YAAY,SAAS,GAAG;EAC3B,SAAS,SAAS;EAClB,OAAO;CACT;CACA,MAAM,EAAE,SAAS,GAAG,kBAAkB;CACtC,MAAM,UAAU,eAAe,WAAW,qBAAqB,SAC7D,MAAM,MAAM,OAAO,CACrB;CACA,IAAI;EACF,SAAS,eAAe,QAAQ,OAAO,WAAW,aAAa,CAAC;CAClE,SAAS,OAAO;EACd,QAAQ;EACR,SAAS,SAAS;EAClB,MAAM;CACR;CAEA,KAAK,MAAM,WAAW,UAAU,iBAAiB,IAAI,MAAM,EAAE,GAC3D,IAAI,EAAE,mBAAmB,SAAS,QAAQ,gBAAgB,KAAK;CAEjE,OAAO;AACT","names":[],"ignoreList":[],"sources":["../../src/client.ts"]}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { render } from "@lit-labs/ssr";
|
|
2
2
|
import { collectResultSync } from "@lit-labs/ssr/lib/render-result.js";
|
|
3
3
|
import { provideRouter, withRouterSync } from "lit-ui-router/context";
|
|
4
|
+
import { DefType } from "@uirouter/core";
|
|
4
5
|
import { createServerRouter } from "ui-router-server";
|
|
6
|
+
import { packageVersion, signatureAttribute } from "./signature.js";
|
|
5
7
|
import { UiViewRenderer } from "./ui-view-renderer.js";
|
|
6
8
|
const NODE_FS = "node:fs/promises";
|
|
7
9
|
const DEFAULT_NOT_FOUND_FILE = "404.html";
|
|
@@ -39,6 +41,23 @@ const rootedStack = (root) => {
|
|
|
39
41
|
const litServerRoot = globalThis.litServerRoot;
|
|
40
42
|
return litServerRoot && litServerRoot !== root ? [litServerRoot, root] : [root];
|
|
41
43
|
};
|
|
44
|
+
export const signatureOf = (router) => {
|
|
45
|
+
const { $current, params } = router.globals;
|
|
46
|
+
return {
|
|
47
|
+
version: packageVersion,
|
|
48
|
+
state: $current.name,
|
|
49
|
+
params: Object.fromEntries($current.parameters().filter((param) => param.location !== DefType.CONFIG).map((param) => [param.id, param.type.encode(params[param.id])]))
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
export const signatureBlock = (signature) => {
|
|
53
|
+
const json = JSON.stringify(signature).replaceAll("<", "\\u003c").replaceAll(">", "\\u003e");
|
|
54
|
+
return `<script type="application/json" ${signatureAttribute}>${json}<\/script>`;
|
|
55
|
+
};
|
|
56
|
+
export const renderPage = (body, router, root, elementRenderers) => signatureBlock(signatureOf(router)) + withRouterSync(router, () => collectResultSync(render(body, {
|
|
57
|
+
eventTargetStack: rootedStack(root),
|
|
58
|
+
elementRenderers,
|
|
59
|
+
deferHydration: true
|
|
60
|
+
})));
|
|
42
61
|
const warnUnclaimed = (path) => {
|
|
43
62
|
console.warn("lit-ui-router-ssr: no route matched this path and its mount declares no otherwise projection, so no page was emitted for it:", path);
|
|
44
63
|
};
|
|
@@ -47,14 +66,52 @@ const warnStrictSlash = async (resolver, path) => {
|
|
|
47
66
|
if (slashed.kind === "shell" && slashed.status === void 0) return;
|
|
48
67
|
console.warn("lit-ui-router-ssr: this page is written as <subpath>/index.html, which static hosts serve by redirecting <subpath> to <subpath>/, and its mount rejects the trailing slash. Pass `config: { strict: false }` on the mount and call `router.urlService.config.strictMode(false)` on the client:", path);
|
|
49
68
|
};
|
|
69
|
+
const wantsSlashProbe = (verdict, path, subpath) => subpath !== "" && verdict.status === void 0 && !path.endsWith("/");
|
|
70
|
+
const redirectLines = (path, verdict, trailingSlash) => {
|
|
71
|
+
const line = {
|
|
72
|
+
from: path,
|
|
73
|
+
to: verdict.location,
|
|
74
|
+
status: verdict.status
|
|
75
|
+
};
|
|
76
|
+
const paired = trailingSlash === "both" ? otherSpelling(path) : void 0;
|
|
77
|
+
return paired === void 0 ? [line] : [line, {
|
|
78
|
+
...line,
|
|
79
|
+
from: paired
|
|
80
|
+
}];
|
|
81
|
+
};
|
|
82
|
+
const notFoundPage = async (notFound, mounts, resolver) => {
|
|
83
|
+
if (notFound === false) return void 0;
|
|
84
|
+
const probe = notFound?.probe ?? defaultProbe(mounts);
|
|
85
|
+
const verdict = await resolver.resolve(probe);
|
|
86
|
+
if (verdict.kind !== "shell" || verdict.status !== 404) return void 0;
|
|
87
|
+
return {
|
|
88
|
+
verdict,
|
|
89
|
+
probe,
|
|
90
|
+
file: notFound?.file ?? DEFAULT_NOT_FOUND_FILE
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
const writeRules = async (lines, rules, write, outDir) => {
|
|
94
|
+
if (rules === "none") return;
|
|
95
|
+
if (typeof rules === "function") {
|
|
96
|
+
await rules(lines);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (lines.length === 0) return;
|
|
100
|
+
const body = lines.map((line) => `${line.from} ${line.to} ${line.status}`).join("\n");
|
|
101
|
+
await write(joinPath(outDir, "_redirects"), `${body}\n`);
|
|
102
|
+
};
|
|
103
|
+
const resolverOf = (options) => {
|
|
104
|
+
if (options.resolver) return options.resolver;
|
|
105
|
+
if (!options.mounts) throw new Error("prerender() needs a mount table: pass `mounts`, or a `resolver` from createServerRouter().");
|
|
106
|
+
return createServerRouter({ mounts: options.mounts });
|
|
107
|
+
};
|
|
50
108
|
const warnUnregistered = () => {
|
|
51
109
|
if (globalThis.customElements?.get("ui-view")) return;
|
|
52
110
|
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.");
|
|
53
111
|
};
|
|
54
112
|
export async function prerender(options) {
|
|
55
113
|
const { mounts, router, paths, outDir, renderShell, document, notFound, rules = "_redirects", extraRules = [], trailingSlash = "both", elementRenderers = [UiViewRenderer], write = nodeWrite, dryRun = false } = options;
|
|
56
|
-
|
|
57
|
-
const resolver = options.resolver ?? createServerRouter({ mounts });
|
|
114
|
+
const resolver = resolverOf(options);
|
|
58
115
|
warnUnregistered();
|
|
59
116
|
const root = options.root ?? new EventTarget();
|
|
60
117
|
const tally = {
|
|
@@ -74,11 +131,7 @@ export async function prerender(options) {
|
|
|
74
131
|
root
|
|
75
132
|
};
|
|
76
133
|
const body = await renderShell(verdict, context);
|
|
77
|
-
const markup = typeof body === "string" ? body :
|
|
78
|
-
eventTargetStack: rootedStack(root),
|
|
79
|
-
elementRenderers,
|
|
80
|
-
deferHydration: true
|
|
81
|
-
})));
|
|
134
|
+
const markup = typeof body === "string" ? body : renderPage(body, router, root, elementRenderers);
|
|
82
135
|
const html = document ? await document(markup, context) : markup;
|
|
83
136
|
if (!dryRun) await write(joinPath(outDir, file), html);
|
|
84
137
|
pages.push({
|
|
@@ -89,58 +142,41 @@ export async function prerender(options) {
|
|
|
89
142
|
});
|
|
90
143
|
};
|
|
91
144
|
let slashProbed = false;
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
slashProbed = true;
|
|
101
|
-
await warnStrictSlash(resolver, path);
|
|
102
|
-
}
|
|
103
|
-
await emit(verdict, path, subpath, fileFor(subpath));
|
|
104
|
-
continue;
|
|
145
|
+
const visit = async (path) => {
|
|
146
|
+
const verdict = await resolver.resolve(path);
|
|
147
|
+
if (verdict.kind === "shell") {
|
|
148
|
+
const subpath = subpathIn(verdict.mount, path);
|
|
149
|
+
tally.shell += 1;
|
|
150
|
+
if (!slashProbed && wantsSlashProbe(verdict, path, subpath)) {
|
|
151
|
+
slashProbed = true;
|
|
152
|
+
await warnStrictSlash(resolver, path);
|
|
105
153
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const line = {
|
|
109
|
-
from: path,
|
|
110
|
-
to: verdict.location,
|
|
111
|
-
status: verdict.status
|
|
112
|
-
};
|
|
113
|
-
generated.push(line);
|
|
114
|
-
const paired = trailingSlash === "both" ? otherSpelling(path) : void 0;
|
|
115
|
-
if (paired !== void 0) generated.push({
|
|
116
|
-
...line,
|
|
117
|
-
from: paired
|
|
118
|
-
});
|
|
119
|
-
continue;
|
|
120
|
-
}
|
|
121
|
-
tally.notFound += 1;
|
|
122
|
-
warnings.push(path);
|
|
123
|
-
warnUnclaimed(path);
|
|
154
|
+
await emit(verdict, path, subpath, fileFor(subpath));
|
|
155
|
+
return;
|
|
124
156
|
}
|
|
125
|
-
if (
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
157
|
+
if (verdict.kind === "redirect") {
|
|
158
|
+
tally.redirect += 1;
|
|
159
|
+
generated.push(...redirectLines(path, verdict, trailingSlash));
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
tally.notFound += 1;
|
|
163
|
+
warnings.push(path);
|
|
164
|
+
warnUnclaimed(path);
|
|
165
|
+
};
|
|
166
|
+
const uninstall = provideRouter(root, router);
|
|
167
|
+
try {
|
|
168
|
+
for await (const path of paths) await visit(path);
|
|
169
|
+
const page = await notFoundPage(notFound, mounts, resolver);
|
|
170
|
+
if (page) {
|
|
171
|
+
tally.document += 1;
|
|
172
|
+
const { verdict, probe, file } = page;
|
|
173
|
+
await emit(verdict, probe, subpathIn(verdict.mount, probe), file);
|
|
132
174
|
}
|
|
133
175
|
} finally {
|
|
134
176
|
uninstall();
|
|
135
177
|
}
|
|
136
178
|
const lines = [...extraRules, ...generated];
|
|
137
|
-
if (!dryRun
|
|
138
|
-
if (typeof rules === "function") await rules(lines);
|
|
139
|
-
else if (lines.length > 0) {
|
|
140
|
-
const body = lines.map((line) => `${line.from} ${line.to} ${line.status}`).join("\n");
|
|
141
|
-
await write(joinPath(outDir, "_redirects"), `${body}\n`);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
179
|
+
if (!dryRun) await writeRules(lines, rules, write, outDir);
|
|
144
180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Q,OAAO,IAAI;GAC7C,MAAM,SAAS;GACf,IAEE,CAAC,eACD,gBAAgB,SAAS,MAAM,OAAO,GACtC;IACA,cAAc;IACd,MAAM,gBAAgB,UAAU,IAAI;GACtC;GACA,MAAM,KAAK,SAAS,MAAM,SAAS,QAAQ,OAAO,CAAC;GACnD;EACF;EACA,IAAI,QAAQ,SAAS,YAAY;GAC/B,MAAM,YAAY;GAClB,UAAU,KAAK,GAAG,cAAc,MAAM,SAAS,aAAa,CAAC;GAC7D;EACF;EACA,MAAM,YAAY;EAClB,SAAS,KAAK,IAAI;EAClB,cAAc,IAAI;CACpB;CAEA,MAAM,YAAY,cAAc,MAAM,MAAM;CAC5C,IAAI;EACF,WAAW,MAAM,QAAQ,OAAO,MAAM,MAAM,IAAI;EAEhD,MAAM,OAAO,MAAM,aAAa,UAAU,QAAQ,QAAQ;EAC1D,IAAI,MAAM;GACR,MAAM,YAAY;GAClB,MAAM,EAAE,SAAS,OAAO,SAAS;GACjC,MAAM,KAAK,SAAS,OAAO,UAAU,QAAQ,OAAO,KAAK,GAAG,IAAI;EAClE;CACF,UAAU;EACR,UAAU;CACZ;CAEA,MAAM,QAAQ,CAAC,GAAG,YAAY,GAAG,SAAS;CAC1C,IAAI,CAAC,QAAQ,MAAM,WAAW,OAAO,OAAO,OAAO,MAAM;CAEzD,OAAO;EAAE;EAAO;EAAO,OAAO;EAAO;EAAU;CAAK;AACtD","names":[],"ignoreList":[],"sources":["../../src/prerender.ts"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signature.js","mappings":"AA4BA,OAAO,MAAM,qBAAqB;AAOlC,OAAO,MAAM,oBAA4B,mCAAmC,mBAAmB;AAO/F,OAAO,MAAM","names":[],"ignoreList":[],"sources":["../../src/signature.ts"]}
|