@uniweb/build 1.15.4 → 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.
Files changed (2) hide show
  1. package/package.json +7 -7
  2. package/src/prerender.js +89 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniweb/build",
3
- "version": "1.15.4",
3
+ "version": "1.15.5",
4
4
  "description": "Build tooling for the Uniweb Component Web Platform",
5
5
  "type": "module",
6
6
  "exports": {
@@ -56,12 +56,12 @@
56
56
  "js-yaml": "^4.3.2",
57
57
  "sharp": "^0.35.5",
58
58
  "yaml": "^2.5.0",
59
- "@uniweb/schemas": "~1.6.7",
60
59
  "@uniweb/content-reader": "~1.5.8",
61
- "@uniweb/theming": "~1.2.1",
62
- "@uniweb/content-writer": "~1.3.1",
60
+ "@uniweb/projections": "~1.2.11",
61
+ "@uniweb/schemas": "~1.6.7",
63
62
  "@uniweb/semantic-parser": "~1.13.2",
64
- "@uniweb/projections": "~1.2.11"
63
+ "@uniweb/content-writer": "~1.3.1",
64
+ "@uniweb/theming": "~1.2.1"
65
65
  },
66
66
  "optionalDependencies": {
67
67
  "@uniweb/runtime": "~1.4.5"
@@ -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/runtime": "~1.4.5",
77
- "@uniweb/core": "~1.6.4"
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,81 @@ 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
+
688
764
  /** The icons a page's HTML already carries in `__ICON_CACHE__`, by key; none when it carries none. */
689
765
  function embeddedIcons(html) {
690
766
  const script = html.match(/<script[^>]*id="__ICON_CACHE__"[^>]*>([\s\S]*?)<\/script>/)
@@ -886,6 +962,8 @@ export async function prerenderSite(siteDir, options = {}) {
886
962
  // Discover all locale content files
887
963
  // Said once more at the end: a build's log is long, and these lines are in the middle of it.
888
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
889
967
  const localeConfigs = await discoverLocaleContents(distDir, defaultSiteContent)
890
968
  if (localeConfigs.length > 1) {
891
969
  onProgress(`Found ${localeConfigs.length} locales: ${localeConfigs.map(l => l.locale).join(', ')}`)
@@ -1027,6 +1105,10 @@ export async function prerenderSite(siteDir, options = {}) {
1027
1105
 
1028
1106
  // Pre-render each page
1029
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
+ })
1030
1112
 
1031
1113
  /**
1032
1114
  * ⭐ A PAGE RENDERS AGAINST WHAT IT CARRIES — the entries its HTML embeds, which are all the
@@ -1125,14 +1207,15 @@ export async function prerenderSite(siteDir, options = {}) {
1125
1207
  const asked = await loadPageData({
1126
1208
  website,
1127
1209
  route: page,
1128
- fetch: fileTransport,
1210
+ fetch: icons.forPage(fileTransport),
1129
1211
  prerender: 'author',
1130
1212
  cache: buildDataCache,
1131
1213
  // ⭐ The icons the site names for this page beyond the ones `prefetchIcons` already holds,
1132
1214
  // the image icons of the whole site's content: a link's icon, a param's, a tagged data
1133
- // block's, a record's. One the graph holds is not asked again, so a build fetches each
1134
- // icon once. ⛔ Until 2026-11-04 this said `false`, and every such icon was a blank box in
1135
- // the built page until the browser fetched it.
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.
1136
1219
  icons: true,
1137
1220
  })
1138
1221
  // Filed under this page, the way a route-bound view always has been: `scopeFetchedData`
@@ -1314,6 +1397,8 @@ export async function prerenderSite(siteDir, options = {}) {
1314
1397
  onProgress,
1315
1398
  })
1316
1399
 
1400
+ // Every page is drawn: what the data step still waits on from the icon corpus is abandoned.
1401
+ icons?.done()
1317
1402
  onProgress(`\nPre-rendered ${renderedFiles.length} pages across ${localeConfigs.length} locale(s)`)
1318
1403
  if (failedIcons.size > 0) {
1319
1404
  console.warn(`[prerender] These icons could not be fetched and are missing from the pages: ${[...failedIcons].join(', ')}`)