@ultimat3/render 31.10.0 → 31.12.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/package.json +7 -7
- package/src/navigation-swap.ts +24 -11
- package/src/navigation.ts +12 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/render",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.12.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.12.0",
|
|
56
|
+
"@ultimat3/core": "31.12.0",
|
|
57
|
+
"@ultimat3/http": "31.12.0",
|
|
58
|
+
"@ultimat3/i18n": "31.12.0",
|
|
59
|
+
"@ultimat3/schema": "31.12.0",
|
|
60
|
+
"@ultimat3/seo": "31.12.0",
|
|
61
61
|
"sass": "1.106.1"
|
|
62
62
|
}
|
|
63
63
|
}
|
package/src/navigation-swap.ts
CHANGED
|
@@ -52,28 +52,34 @@ export function missingStylesheets(doc: Document, next: Document): readonly stri
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
|
-
* Resolves once every sheet loaded OR failed — a missing sheet must not hang the navigation
|
|
56
|
-
*
|
|
55
|
+
* Resolves once every sheet loaded OR failed — a missing sheet must not hang the navigation — to
|
|
56
|
+
* whether ALL of them loaded. A failed one leaves the head (a later navigation asks for it again
|
|
57
|
+
* rather than trusting a dead link); the caller decides what an unstyled answer becomes. Each sheet
|
|
58
|
+
* joins `owned` as it is appended, so a swap that never happens still leaves it retirable.
|
|
57
59
|
*/
|
|
58
|
-
export function loadStylesheets(
|
|
60
|
+
export async function loadStylesheets(
|
|
59
61
|
doc: Document,
|
|
60
62
|
hrefs: readonly string[],
|
|
61
63
|
owned: WeakSet<Element>,
|
|
62
|
-
): Promise<
|
|
63
|
-
|
|
64
|
+
): Promise<boolean> {
|
|
65
|
+
const loaded = await Promise.all(
|
|
64
66
|
hrefs.map(
|
|
65
67
|
(href) =>
|
|
66
|
-
new Promise<
|
|
68
|
+
new Promise<boolean>((done) => {
|
|
67
69
|
const link = doc.createElement('link');
|
|
68
70
|
link.rel = 'stylesheet';
|
|
69
71
|
link.href = href;
|
|
70
|
-
link.onload = () => done();
|
|
71
|
-
link.onerror = () =>
|
|
72
|
+
link.onload = () => done(true);
|
|
73
|
+
link.onerror = () => {
|
|
74
|
+
link.remove();
|
|
75
|
+
done(false);
|
|
76
|
+
};
|
|
72
77
|
doc.head.append(link);
|
|
73
78
|
owned.add(link);
|
|
74
79
|
}),
|
|
75
80
|
),
|
|
76
|
-
)
|
|
81
|
+
);
|
|
82
|
+
return loaded.every(Boolean);
|
|
77
83
|
}
|
|
78
84
|
|
|
79
85
|
/** `[data-x-persist="id"]` present in BOTH documents: the live element moves into the next body. */
|
|
@@ -212,8 +218,15 @@ export function documentHead(doc: Document): WeakSet<Element> {
|
|
|
212
218
|
* The swap itself, after the caller decided the answer IS a page for this tab. Synchronous from
|
|
213
219
|
* the dispose to the head, so a view transition's "after" snapshot is one consistent document.
|
|
214
220
|
* `owned` is `documentHead`'s set, kept by the caller across swaps and grown by each one.
|
|
221
|
+
* `retire: false` when one of the next page's sheets did not load: the previous page's sheets are
|
|
222
|
+
* then the only styling the tab has, and stay until a swap whose sheets all arrived.
|
|
215
223
|
*/
|
|
216
|
-
export function swapDocument(
|
|
224
|
+
export function swapDocument(
|
|
225
|
+
doc: Document,
|
|
226
|
+
next: Document,
|
|
227
|
+
owned: WeakSet<Element>,
|
|
228
|
+
retire = true,
|
|
229
|
+
): Swapped {
|
|
217
230
|
// Read before the head moves: `next.title` reads the `<title>` element, which the plan adopts.
|
|
218
231
|
const title = next.title;
|
|
219
232
|
const nextSheets = new Set(
|
|
@@ -256,7 +269,7 @@ export function swapDocument(doc: Document, next: Document, owned: WeakSet<Eleme
|
|
|
256
269
|
// sheet a script added (not `owned`), never one both pages link.
|
|
257
270
|
for (const sheet of [...doc.head.querySelectorAll('link')].filter(isStylesheet)) {
|
|
258
271
|
const href = new URL(sheet.getAttribute('href') ?? '', doc.baseURI).href;
|
|
259
|
-
if (owned.has(sheet) && !nextSheets.has(href)) sheet.remove();
|
|
272
|
+
if (retire && owned.has(sheet) && !nextSheets.has(href)) sheet.remove();
|
|
260
273
|
}
|
|
261
274
|
for (const sheet of [...doc.head.querySelectorAll('link')].filter(isStylesheet)) {
|
|
262
275
|
if (nextSheets.has(new URL(sheet.getAttribute('href') ?? '', doc.baseURI).href))
|
package/src/navigation.ts
CHANGED
|
@@ -261,8 +261,18 @@ export function startNavigation(win: RouterWindow = window): NavigationRouter |
|
|
|
261
261
|
// Owned from the moment they are appended: a navigation aborted after this point left its
|
|
262
262
|
// sheets in the head for good, styling every page after it — the next swap retires an
|
|
263
263
|
// owned sheet its page does not link.
|
|
264
|
-
await loadStylesheets(doc, missingStylesheets(doc, next), owned);
|
|
264
|
+
const sheetsLoaded = await loadStylesheets(doc, missingStylesheets(doc, next), owned);
|
|
265
265
|
if (mine.signal.aborted) return;
|
|
266
|
+
// A sheet that did not load (a rolling deploy's other replica serves another build's
|
|
267
|
+
// assets) would swap in an unstyled page: a GET is the browser's to load whole, a refresh
|
|
268
|
+
// ends quietly, a POST (never re-sent) swaps but keeps the sheets the tab already has.
|
|
269
|
+
if (!sheetsLoaded) {
|
|
270
|
+
if (refreshFailsQuietly(options.refresh)) return;
|
|
271
|
+
if (method === 'GET') {
|
|
272
|
+
win.location.assign(url);
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
266
276
|
if (shown === 'modal') {
|
|
267
277
|
await modal.present(next, addressOf(landed), landed, modalHistory(method, history));
|
|
268
278
|
doc.dispatchEvent(new CustomEvent(NAVIGATED_EVENT, { detail: { url: landed } }));
|
|
@@ -283,7 +293,7 @@ export function startNavigation(win: RouterWindow = window): NavigationRouter |
|
|
|
283
293
|
() => {
|
|
284
294
|
// A newer navigation started while the sheets loaded: this answer is no longer asked for.
|
|
285
295
|
if (mine.signal.aborted) return;
|
|
286
|
-
swapped = swapDocument(doc, next, owned);
|
|
296
|
+
swapped = swapDocument(doc, next, owned, sheetsLoaded);
|
|
287
297
|
// Emptied here and filled after the scripts, so a page with the same title still reads out.
|
|
288
298
|
if (hold === undefined) live.textContent = '';
|
|
289
299
|
swapped.body.append(live);
|