@uniweb/runtime 0.26.6 → 0.27.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/dist/ssr.js +12 -115
- package/dist/ssr.js.map +1 -1
- package/package.json +3 -3
- package/src/isolate-api.js +2 -5
- package/src/load-page-data.js +11 -4
- package/src/ssr.js +10 -12
- package/src/wire-foundation.js +21 -11
- package/src/prefetch.js +0 -261
package/dist/ssr.js
CHANGED
|
@@ -3,17 +3,14 @@ import React from "react";
|
|
|
3
3
|
import { renderToString } from "react-dom/server";
|
|
4
4
|
import { sectionDomId } from "@uniweb/core/section-id";
|
|
5
5
|
import { applyBasePath } from "@uniweb/core/base-path";
|
|
6
|
-
import { isDynamicRoute, routePatternToRegex
|
|
7
|
-
import { findPageForRoute
|
|
6
|
+
import { isDynamicRoute, routePatternToRegex } from "@uniweb/core/route-match";
|
|
7
|
+
import { findPageForRoute } from "@uniweb/core/route-match";
|
|
8
8
|
import { DEFAULT_ICON_BASE, iconUrl } from "@uniweb/core/icon-corpus";
|
|
9
9
|
import { buildTheme, FONT_LINKS_MARKER, buildSectionOverrides } from "@uniweb/theming";
|
|
10
10
|
import "@uniweb/core/services";
|
|
11
11
|
import "@uniweb/core/tracker";
|
|
12
12
|
import DataStore, { deriveCacheKey as deriveCacheKey$1 } from "@uniweb/core/datastore";
|
|
13
|
-
import {
|
|
14
|
-
import { buildDetailConfig } from "@uniweb/core/detail-url";
|
|
15
|
-
import { resolveDefaultLocale as resolveDefaultLocale$1 } from "@uniweb/core/locale-config";
|
|
16
|
-
import { findLayoutEntry } from "@uniweb/core/layout-name";
|
|
13
|
+
import { resolveFetchConfigs } from "@uniweb/core/fetch-config";
|
|
17
14
|
import { resolveRecordsService } from "@uniweb/core/records-service";
|
|
18
15
|
function guaranteeItemStructure(item) {
|
|
19
16
|
return {
|
|
@@ -319,7 +316,12 @@ function hydrateDataStore(website, fetchedData) {
|
|
|
319
316
|
if (!website?.dataStore || !fetchedData?.length) return;
|
|
320
317
|
for (const entry of fetchedData) {
|
|
321
318
|
if (entry.outcome && entry.outcome !== "fetched") continue;
|
|
322
|
-
|
|
319
|
+
const value = entry.meta ? { data: entry.data, meta: entry.meta } : { data: entry.data };
|
|
320
|
+
if (typeof website.fetcher?.hydrate === "function") {
|
|
321
|
+
website.fetcher.hydrate(entry.config, value, { website });
|
|
322
|
+
} else {
|
|
323
|
+
website.dataStore.set(deriveCacheKey(entry.config), value);
|
|
324
|
+
}
|
|
323
325
|
}
|
|
324
326
|
}
|
|
325
327
|
function ensureThemeCss(uniweb, foundation) {
|
|
@@ -1157,7 +1159,7 @@ function blocksOf(page) {
|
|
|
1157
1159
|
for (const area of Object.values(page.getLayoutAreas?.() ?? {})) walk(area);
|
|
1158
1160
|
return out;
|
|
1159
1161
|
}
|
|
1160
|
-
async function loadPageData({ website, route, fetch: fetch2, dev = false, locale = null, prerender = "always" }) {
|
|
1162
|
+
async function loadPageData({ website, route, fetch: fetch2, dev = false, locale = null, prerender = "always", cache = null }) {
|
|
1161
1163
|
if (prerender !== "author" && prerender !== "always") {
|
|
1162
1164
|
throw new Error(`loadPageData: prerender must be 'author' or 'always', got ${JSON.stringify(prerender)}`);
|
|
1163
1165
|
}
|
|
@@ -1174,7 +1176,7 @@ async function loadPageData({ website, route, fetch: fetch2, dev = false, locale
|
|
|
1174
1176
|
throw new Error("loadPageData: `route` must be a route or a Page from this Website — page data is not enough to say what its render reads.");
|
|
1175
1177
|
}
|
|
1176
1178
|
const dispatcher = website.dispatcherFor({
|
|
1177
|
-
dataStore: new DataStore(),
|
|
1179
|
+
dataStore: cache ?? new DataStore(),
|
|
1178
1180
|
defaultFetcher: createDefaultFetcher({ basePath: website.config?.base || "", dev, fetch: fetch2 })
|
|
1179
1181
|
});
|
|
1180
1182
|
const entries = /* @__PURE__ */ new Map();
|
|
@@ -1204,108 +1206,6 @@ async function loadPageData({ website, route, fetch: fetch2, dev = false, locale
|
|
|
1204
1206
|
]);
|
|
1205
1207
|
return [...entries.values()];
|
|
1206
1208
|
}
|
|
1207
|
-
function parentPageOf(page, pages) {
|
|
1208
|
-
const byRoute = new Map(pages.filter((p) => p?.route).map((p) => [p.route, p]));
|
|
1209
|
-
const route = parentRouteOf(page.route, { declared: page.parent ?? null, has: (r) => byRoute.has(r) });
|
|
1210
|
-
return route ? byRoute.get(route) : null;
|
|
1211
|
-
}
|
|
1212
|
-
function layoutSectionsFor(content, page) {
|
|
1213
|
-
const sets = content?.layouts && typeof content.layouts === "object" ? content.layouts : {};
|
|
1214
|
-
const name = typeof page?.layout?.name === "string" && page.layout.name ? page.layout.name : null;
|
|
1215
|
-
const named = name ? findLayoutEntry(sets, name) : void 0;
|
|
1216
|
-
const chosen = name ? named ? [named] : [] : Object.values(sets);
|
|
1217
|
-
const out = [];
|
|
1218
|
-
const walk = (sections) => {
|
|
1219
|
-
for (const s of sections || []) {
|
|
1220
|
-
if (!s || typeof s !== "object") continue;
|
|
1221
|
-
out.push(s);
|
|
1222
|
-
walk(s.subsections);
|
|
1223
|
-
}
|
|
1224
|
-
};
|
|
1225
|
-
for (const set of chosen) for (const area of Object.values(set || {})) walk(area?.sections);
|
|
1226
|
-
return out;
|
|
1227
|
-
}
|
|
1228
|
-
function resolvePageFetchConfigs(content, route, { locale = null } = {}) {
|
|
1229
|
-
const { page, params } = findPageForRoute(content, route);
|
|
1230
|
-
if (!page) return [];
|
|
1231
|
-
const pages = content?.pages || [];
|
|
1232
|
-
const parent = parentPageOf(page, pages);
|
|
1233
|
-
const binding = isDynamicRoute(page.route) && Object.keys(params).length ? routeBinding(page.route, params, page.paramName ?? null) : null;
|
|
1234
|
-
const options = {
|
|
1235
|
-
locale,
|
|
1236
|
-
defaultLocale: resolveDefaultLocale$1(content?.config) ?? null,
|
|
1237
|
-
queries: content?.config?.queries ?? null,
|
|
1238
|
-
services: content?.config?.services ?? null,
|
|
1239
|
-
variables: binding?.variables ?? null
|
|
1240
|
-
};
|
|
1241
|
-
const siteFetch = content?.config?.fetch ?? null;
|
|
1242
|
-
const chosen = binding ? pageRouteQuery(page, {
|
|
1243
|
-
routeOf: (p) => p.route,
|
|
1244
|
-
parentOf: (p) => parentPageOf(p, pages),
|
|
1245
|
-
fetchOf: (p) => p.fetch ?? null,
|
|
1246
|
-
sectionsOf: (p) => p.sections,
|
|
1247
|
-
site: siteFetch
|
|
1248
|
-
}) : null;
|
|
1249
|
-
const routeSource = chosen?.nested ? chosen.config : null;
|
|
1250
|
-
const out = /* @__PURE__ */ new Map();
|
|
1251
|
-
const put = (cfg) => {
|
|
1252
|
-
const key = deriveCacheKey$1(cfg);
|
|
1253
|
-
if (!out.has(key)) out.set(key, cfg);
|
|
1254
|
-
};
|
|
1255
|
-
const add = (sources) => {
|
|
1256
|
-
const resolved = sources.flatMap((source) => fetchEntries(source).map((entry) => resolveFetchConfigs([entry], options).get(entry.as)));
|
|
1257
|
-
for (const cfg of resolved.filter(Boolean)) {
|
|
1258
|
-
const current = currentFor(cfg, chosen);
|
|
1259
|
-
if (current === "exclude") {
|
|
1260
|
-
put(othersView(cfg));
|
|
1261
|
-
continue;
|
|
1262
|
-
}
|
|
1263
|
-
if (current !== "only") {
|
|
1264
|
-
put(cfg);
|
|
1265
|
-
continue;
|
|
1266
|
-
}
|
|
1267
|
-
if (cfg.detail && binding.paramValue !== void 0) {
|
|
1268
|
-
const detailCfg = buildDetailConfig(cfg, { paramName: binding.paramName, paramValue: String(binding.paramValue) });
|
|
1269
|
-
if (detailCfg) put(detailCfg);
|
|
1270
|
-
}
|
|
1271
|
-
if (!cfg.ask) put(routeSelection(cfg));
|
|
1272
|
-
}
|
|
1273
|
-
};
|
|
1274
|
-
const siteForPage = siteReaches(parent) ? siteFetch : null;
|
|
1275
|
-
add([page.fetch ?? null, parent?.fetch ?? null, routeSource, siteForPage]);
|
|
1276
|
-
const walk = (sections) => {
|
|
1277
|
-
for (const s of sections || []) {
|
|
1278
|
-
if (s?.fetch) add([s.fetch, page.fetch ?? null, parent?.fetch ?? null, routeSource, siteForPage]);
|
|
1279
|
-
if (s?.subsections) walk(s.subsections);
|
|
1280
|
-
}
|
|
1281
|
-
};
|
|
1282
|
-
walk(page.sections);
|
|
1283
|
-
for (const s of layoutSectionsFor(content, page)) add([s.fetch ?? null, siteFetch]);
|
|
1284
|
-
return [...out.values()];
|
|
1285
|
-
}
|
|
1286
|
-
async function executeFetchConfigs(configs, { content, fetch: fetch2 = null, dev = false, prerender = "always", locale = null } = {}) {
|
|
1287
|
-
if (prerender !== "author" && prerender !== "always") {
|
|
1288
|
-
throw new Error(`executeFetchConfigs: prerender must be 'author' or 'always', got ${JSON.stringify(prerender)}`);
|
|
1289
|
-
}
|
|
1290
|
-
const fetcher = createDefaultFetcher({
|
|
1291
|
-
basePath: content?.config?.base || "",
|
|
1292
|
-
dev,
|
|
1293
|
-
fetch: fetch2
|
|
1294
|
-
});
|
|
1295
|
-
const ctx = { website: null, locale: locale ?? content?.config?.activeLocale ?? resolveDefaultLocale$1(content?.config) ?? null };
|
|
1296
|
-
return Promise.all((configs || []).filter(Boolean).map(async (config) => {
|
|
1297
|
-
if (prerender === "author" && config.prerender === false) {
|
|
1298
|
-
return { config, outcome: "skipped", data: null };
|
|
1299
|
-
}
|
|
1300
|
-
const result = await fetcher.resolve(config, ctx);
|
|
1301
|
-
if (result?.error) return { config, outcome: "failed", data: null, error: result.error };
|
|
1302
|
-
return { config, outcome: "fetched", data: result?.data ?? null, ...result?.meta ? { meta: result.meta } : {} };
|
|
1303
|
-
}));
|
|
1304
|
-
}
|
|
1305
|
-
async function prefetchPageData({ content, route, locale = null, fetch: fetch2 = null, dev = false, prerender = "always" }) {
|
|
1306
|
-
const configs = resolvePageFetchConfigs(content, route, { locale });
|
|
1307
|
-
return executeFetchConfigs(configs, { content, fetch: fetch2, dev, prerender, locale });
|
|
1308
|
-
}
|
|
1309
1209
|
function createPageRenderer({ website, shell }) {
|
|
1310
1210
|
if (!website) throw new Error("createPageRenderer: `website` is required");
|
|
1311
1211
|
if (typeof shell !== "string") throw new Error("createPageRenderer: `shell` must be an HTML string");
|
|
@@ -1379,8 +1279,7 @@ export {
|
|
|
1379
1279
|
collectSiteRecords,
|
|
1380
1280
|
createPageRenderer,
|
|
1381
1281
|
escapeHtml,
|
|
1382
|
-
|
|
1383
|
-
findPageForRoute2 as findPageForRoute,
|
|
1282
|
+
findPageForRoute,
|
|
1384
1283
|
generate404Html,
|
|
1385
1284
|
getComponentDefaults,
|
|
1386
1285
|
getComponentMeta,
|
|
@@ -1393,7 +1292,6 @@ export {
|
|
|
1393
1292
|
loadPageData,
|
|
1394
1293
|
prefetchAndHydrate,
|
|
1395
1294
|
prefetchIcons,
|
|
1396
|
-
prefetchPageData,
|
|
1397
1295
|
prepareProps,
|
|
1398
1296
|
renderAppearanceBootScript,
|
|
1399
1297
|
renderBackground,
|
|
@@ -1402,7 +1300,6 @@ export {
|
|
|
1402
1300
|
renderLayout,
|
|
1403
1301
|
renderPage,
|
|
1404
1302
|
resolvePage,
|
|
1405
|
-
resolvePageFetchConfigs,
|
|
1406
1303
|
sliceContentForLocale
|
|
1407
1304
|
};
|
|
1408
1305
|
//# sourceMappingURL=ssr.js.map
|