@uniweb/build 1.15.3 → 1.15.5
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/prerender.js +112 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniweb/build",
|
|
3
|
-
"version": "1.15.
|
|
3
|
+
"version": "1.15.5",
|
|
4
4
|
"description": "Build tooling for the Uniweb Component Web Platform",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -56,15 +56,15 @@
|
|
|
56
56
|
"js-yaml": "^4.3.2",
|
|
57
57
|
"sharp": "^0.35.5",
|
|
58
58
|
"yaml": "^2.5.0",
|
|
59
|
+
"@uniweb/content-reader": "~1.5.8",
|
|
59
60
|
"@uniweb/projections": "~1.2.11",
|
|
61
|
+
"@uniweb/schemas": "~1.6.7",
|
|
60
62
|
"@uniweb/semantic-parser": "~1.13.2",
|
|
61
63
|
"@uniweb/content-writer": "~1.3.1",
|
|
62
|
-
"@uniweb/
|
|
63
|
-
"@uniweb/theming": "~1.2.1",
|
|
64
|
-
"@uniweb/schemas": "~1.6.7"
|
|
64
|
+
"@uniweb/theming": "~1.2.1"
|
|
65
65
|
},
|
|
66
66
|
"optionalDependencies": {
|
|
67
|
-
"@uniweb/runtime": "~1.4.
|
|
67
|
+
"@uniweb/runtime": "~1.4.5"
|
|
68
68
|
},
|
|
69
69
|
"peerDependencies": {
|
|
70
70
|
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0",
|
|
@@ -73,8 +73,8 @@
|
|
|
73
73
|
"@tailwindcss/vite": "^4.0.0",
|
|
74
74
|
"@vitejs/plugin-react": "^4.0.0 || ^5.0.0",
|
|
75
75
|
"vite-plugin-svgr": "^4.0.0",
|
|
76
|
-
"@uniweb/
|
|
77
|
-
"@uniweb/
|
|
76
|
+
"@uniweb/core": "~1.6.4",
|
|
77
|
+
"@uniweb/runtime": "~1.4.5"
|
|
78
78
|
},
|
|
79
79
|
"peerDependenciesMeta": {
|
|
80
80
|
"vite": {
|
package/src/prerender.js
CHANGED
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
} from '@uniweb/core'
|
|
26
26
|
import { isDynamicRoute, recordTitle, recordImage, routePatternToRegex, routeFieldOf } from '@uniweb/core/route-match'
|
|
27
27
|
import DataStore from '@uniweb/core/datastore'
|
|
28
|
+
import { DEFAULT_ICON_BASE } from '@uniweb/core/icon-corpus'
|
|
28
29
|
import { executeFetch, mergeDataIntoContent, toFetchList } from './site/data-fetcher.js'
|
|
29
30
|
import { createFileTransport } from './site/file-transport.js'
|
|
30
31
|
import { shouldSplitContent } from './site/split-content.js'
|
|
@@ -685,6 +686,92 @@ function dedupeByAddress(entries) {
|
|
|
685
686
|
return out
|
|
686
687
|
}
|
|
687
688
|
|
|
689
|
+
/**
|
|
690
|
+
* ⭐ THE ICON CORPUS, ASKED BY THE DATA STEP ONCE PER ICON AND NEVER WAITED FOR TWICE. The step asks
|
|
691
|
+
* for a page's icons on every page, skips the ones the graph holds and waits a moment for the rest
|
|
692
|
+
* (`loadPageData`, `icons: true`), so an icon that arrived is asked once. One that did not, a name
|
|
693
|
+
* the corpus lacks or a request the network drops, would be asked again by every page naming it,
|
|
694
|
+
* and a dropped one costs each of those pages the whole wait. So:
|
|
695
|
+
*
|
|
696
|
+
* - each icon address's answer is kept for the build, every locale's pages included, and a later
|
|
697
|
+
* page gets it at once, a failure as well;
|
|
698
|
+
* - a request from an earlier page still on its way when the next page starts says the corpus
|
|
699
|
+
* answers slower than the step waits, so the rest of the build asks it nothing and says so once.
|
|
700
|
+
* Those icons stay on the browser's path, as every such icon was before the step asked for them.
|
|
701
|
+
*
|
|
702
|
+
* Measured 2026-11-04 with every icon request dropped, each failing at Node's 10 s connect timeout:
|
|
703
|
+
* a project of 13 pages built in 44 s with 104 icon requests while the step asked for icons this
|
|
704
|
+
* way, and in 26 s with 52 since, where it took 23 s and 38 when the step asked for none; one of 288
|
|
705
|
+
* pages in 24 languages, 450 s and 3,540 requests, then 246 s and 272, where none took 245 s and
|
|
706
|
+
* 264. What is left is the site-wide prefetch's, which waits once for each language. Built on a
|
|
707
|
+
* working network, both drew every icon either way, in the same time.
|
|
708
|
+
*
|
|
709
|
+
* @param {string} base - the icon corpus the step asks, as `iconUrl` builds its addresses
|
|
710
|
+
* @param {Function} warn - told once, when the corpus stops being asked
|
|
711
|
+
*/
|
|
712
|
+
function iconAsker(base, warn) {
|
|
713
|
+
const prefix = `${String(base).replace(/\/+$/, '')}/`
|
|
714
|
+
const answers = new Map()
|
|
715
|
+
// ⭐ What is still on its way is abandoned when the corpus stops being asked, and when the build
|
|
716
|
+
// is done: a request a page stopped waiting for otherwise holds the build open until the
|
|
717
|
+
// network gives up on it.
|
|
718
|
+
const abandon = new AbortController()
|
|
719
|
+
let onTheirWay = 0
|
|
720
|
+
let silent = false
|
|
721
|
+
const answered = (entry, url) => {
|
|
722
|
+
if (!entry.answer) throw new TypeError(`[prerender] no answer for ${url}`)
|
|
723
|
+
return new Response(entry.answer.body || null, { status: entry.answer.status })
|
|
724
|
+
}
|
|
725
|
+
return {
|
|
726
|
+
/** Abandons what is still on its way: the build has drawn its last page. */
|
|
727
|
+
done() {
|
|
728
|
+
abandon.abort()
|
|
729
|
+
},
|
|
730
|
+
/** The transport for one page's step, over the build's own (`createFileTransport`). */
|
|
731
|
+
forPage(transport) {
|
|
732
|
+
if (onTheirWay > 0 && !silent) {
|
|
733
|
+
silent = true
|
|
734
|
+
abandon.abort()
|
|
735
|
+
warn(`The icon corpus at ${base} is answering slower than a page waits; the rest of this build leaves the icons its pages name beyond their content for the browser to fetch.`)
|
|
736
|
+
}
|
|
737
|
+
return async function stepTransport(input, init) {
|
|
738
|
+
const url = typeof input === 'string' ? input : input?.url
|
|
739
|
+
if (typeof url !== 'string' || !url.startsWith(prefix)) return transport(input, init)
|
|
740
|
+
const known = answers.get(url)
|
|
741
|
+
if (known) {
|
|
742
|
+
if (known.answer === undefined) throw new TypeError(`[prerender] ${url} is still on its way`)
|
|
743
|
+
return answered(known, url)
|
|
744
|
+
}
|
|
745
|
+
if (silent) throw new TypeError(`[prerender] not asked, the icon corpus is not answering: ${url}`)
|
|
746
|
+
const entry = { answer: undefined }
|
|
747
|
+
answers.set(url, entry)
|
|
748
|
+
onTheirWay++
|
|
749
|
+
try {
|
|
750
|
+
const signal = init?.signal ? AbortSignal.any([init.signal, abandon.signal]) : abandon.signal
|
|
751
|
+
const response = await transport(input, { ...init, signal })
|
|
752
|
+
entry.answer = { status: response.status, body: response.ok ? await response.text() : null }
|
|
753
|
+
} catch {
|
|
754
|
+
entry.answer = null
|
|
755
|
+
} finally {
|
|
756
|
+
onTheirWay--
|
|
757
|
+
}
|
|
758
|
+
return answered(entry, url)
|
|
759
|
+
}
|
|
760
|
+
},
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
/** The icons a page's HTML already carries in `__ICON_CACHE__`, by key; none when it carries none. */
|
|
765
|
+
function embeddedIcons(html) {
|
|
766
|
+
const script = html.match(/<script[^>]*id="__ICON_CACHE__"[^>]*>([\s\S]*?)<\/script>/)
|
|
767
|
+
if (!script) return {}
|
|
768
|
+
try {
|
|
769
|
+
return JSON.parse(script[1])
|
|
770
|
+
} catch {
|
|
771
|
+
return {}
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
|
|
688
775
|
/**
|
|
689
776
|
* Inject build-specific data into HTML (theme CSS, __SITE_CONTENT__, icon cache).
|
|
690
777
|
* Called after the shared injectPageContent for build-specific additions.
|
|
@@ -760,9 +847,16 @@ export function injectBuildData(html, siteContent, { splitContent = false, curre
|
|
|
760
847
|
)
|
|
761
848
|
}
|
|
762
849
|
|
|
763
|
-
//
|
|
850
|
+
// ⭐ THE PAGE'S ICONS, so the browser draws them without fetching: the site's content icons,
|
|
851
|
+
// which every page embeds so the next page a visit opens has them too, and whatever else this
|
|
852
|
+
// page drew, which its render wrote here (`injectPageContent`): a link's icon, a param's, a
|
|
853
|
+
// record's. Those follow in key order, so a build writes the same page every time. Replacing the
|
|
854
|
+
// render's copy instead would blank them in the browser's first render.
|
|
764
855
|
if (siteContent._iconCache) {
|
|
765
|
-
const
|
|
856
|
+
const icons = { ...siteContent._iconCache }
|
|
857
|
+
const drawn = embeddedIcons(result)
|
|
858
|
+
for (const key of Object.keys(drawn).sort()) if (!(key in icons)) icons[key] = drawn[key]
|
|
859
|
+
const iconScript = `<script id="__ICON_CACHE__" type="application/json">${jsonForScript(icons)}</script>`
|
|
766
860
|
if (result.includes('__ICON_CACHE__')) {
|
|
767
861
|
result = result.replace(
|
|
768
862
|
/<script[^>]*id="__ICON_CACHE__"[^>]*>[\s\S]*?<\/script>/,
|
|
@@ -868,6 +962,8 @@ export async function prerenderSite(siteDir, options = {}) {
|
|
|
868
962
|
// Discover all locale content files
|
|
869
963
|
// Said once more at the end: a build's log is long, and these lines are in the middle of it.
|
|
870
964
|
const failedIcons = new Set()
|
|
965
|
+
// The data step's way to the icon corpus, for every locale (`iconAsker`): made with the first.
|
|
966
|
+
let icons = null
|
|
871
967
|
const localeConfigs = await discoverLocaleContents(distDir, defaultSiteContent)
|
|
872
968
|
if (localeConfigs.length > 1) {
|
|
873
969
|
onProgress(`Found ${localeConfigs.length} locales: ${localeConfigs.map(l => l.locale).join(', ')}`)
|
|
@@ -1009,6 +1105,10 @@ export async function prerenderSite(siteDir, options = {}) {
|
|
|
1009
1105
|
|
|
1010
1106
|
// Pre-render each page
|
|
1011
1107
|
const website = uniweb.activeWebsite
|
|
1108
|
+
icons ??= iconAsker(website.config?.icons?.base || DEFAULT_ICON_BASE, (message) => {
|
|
1109
|
+
console.warn(`[prerender] ${message}`)
|
|
1110
|
+
onProgress(` ${message}`)
|
|
1111
|
+
})
|
|
1012
1112
|
|
|
1013
1113
|
/**
|
|
1014
1114
|
* ⭐ A PAGE RENDERS AGAINST WHAT IT CARRIES — the entries its HTML embeds, which are all the
|
|
@@ -1107,11 +1207,16 @@ export async function prerenderSite(siteDir, options = {}) {
|
|
|
1107
1207
|
const asked = await loadPageData({
|
|
1108
1208
|
website,
|
|
1109
1209
|
route: page,
|
|
1110
|
-
fetch: fileTransport,
|
|
1210
|
+
fetch: icons.forPage(fileTransport),
|
|
1111
1211
|
prerender: 'author',
|
|
1112
1212
|
cache: buildDataCache,
|
|
1113
|
-
//
|
|
1114
|
-
icons:
|
|
1213
|
+
// ⭐ The icons the site names for this page beyond the ones `prefetchIcons` already holds,
|
|
1214
|
+
// the image icons of the whole site's content: a link's icon, a param's, a tagged data
|
|
1215
|
+
// block's, a record's. One the graph holds is not asked again, and the transport keeps
|
|
1216
|
+
// the answer to every other (`iconAsker`), so a build asks for each icon once.
|
|
1217
|
+
// ⛔ Until 2026-11-04 this said `false`, and every such icon was a blank box in the built
|
|
1218
|
+
// page until the browser fetched it.
|
|
1219
|
+
icons: true,
|
|
1115
1220
|
})
|
|
1116
1221
|
// Filed under this page, the way a route-bound view always has been: `scopeFetchedData`
|
|
1117
1222
|
// embeds it in this page's HTML and nowhere else, and one address embedded twice collapses.
|
|
@@ -1292,6 +1397,8 @@ export async function prerenderSite(siteDir, options = {}) {
|
|
|
1292
1397
|
onProgress,
|
|
1293
1398
|
})
|
|
1294
1399
|
|
|
1400
|
+
// Every page is drawn: what the data step still waits on from the icon corpus is abandoned.
|
|
1401
|
+
icons?.done()
|
|
1295
1402
|
onProgress(`\nPre-rendered ${renderedFiles.length} pages across ${localeConfigs.length} locale(s)`)
|
|
1296
1403
|
if (failedIcons.size > 0) {
|
|
1297
1404
|
console.warn(`[prerender] These icons could not be fetched and are missing from the pages: ${[...failedIcons].join(', ')}`)
|