@absolutejs/absolute 0.19.0-beta.1095 → 0.19.0-beta.1097

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.
@@ -1129,6 +1129,343 @@ var normalizeSlug = (str) => str.trim().replace(/\s+/g, "-").replace(/[^A-Za-z0-
1129
1129
  return normalizeSlug(str).split(/[-_]/).filter(Boolean).map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1).toLowerCase()).join("");
1130
1130
  };
1131
1131
 
1132
+ // src/utils/resolveConvention.ts
1133
+ import { basename } from "path";
1134
+ var CONVENTIONS_KEY = "__absoluteConventions", isConventionsMap = (value) => Boolean(value) && typeof value === "object", getMap = () => {
1135
+ const value = Reflect.get(globalThis, CONVENTIONS_KEY);
1136
+ if (isConventionsMap(value))
1137
+ return value;
1138
+ const empty = {};
1139
+ return empty;
1140
+ }, derivePageName = (pagePath) => {
1141
+ const base = basename(pagePath);
1142
+ const dotIndex = base.indexOf(".");
1143
+ const name = dotIndex > 0 ? base.slice(0, dotIndex) : base;
1144
+ return toPascal(name);
1145
+ }, normalizeConventionPageName = (name) => toPascal(name).replace(/\d+$/, ""), hasErrorConvention = (framework) => {
1146
+ const conventions = getMap()[framework];
1147
+ if (!conventions)
1148
+ return false;
1149
+ if (conventions.defaults?.error)
1150
+ return true;
1151
+ return Object.values(conventions.pages ?? {}).some((page) => Boolean(page.error));
1152
+ }, resolveErrorConventionPath = (framework, pageName) => {
1153
+ const conventions = getMap()[framework];
1154
+ if (!conventions)
1155
+ return;
1156
+ const exact = conventions.pages?.[pageName]?.error;
1157
+ if (exact)
1158
+ return exact;
1159
+ const normalizedPageName = normalizeConventionPageName(pageName);
1160
+ for (const [candidate, page] of Object.entries(conventions.pages ?? {})) {
1161
+ if (normalizeConventionPageName(candidate) === normalizedPageName) {
1162
+ return page.error ?? conventions.defaults?.error;
1163
+ }
1164
+ }
1165
+ return conventions.defaults?.error;
1166
+ }, resolveNotFoundConventionPath = (framework) => getMap()[framework]?.defaults?.notFound, setConventions = (map) => {
1167
+ Reflect.set(globalThis, CONVENTIONS_KEY, map);
1168
+ }, isDev = () => true, buildErrorProps = (error) => {
1169
+ if (error instanceof Error) {
1170
+ return {
1171
+ name: error.name,
1172
+ message: error.message,
1173
+ ...isDev() && error.stack ? { stack: error.stack } : {}
1174
+ };
1175
+ }
1176
+ return { message: String(error), name: "Error" };
1177
+ }, renderReactError = async (conventionPath, errorProps) => {
1178
+ const { createElement } = await import("react");
1179
+ const { renderToReadableStream } = await import("react-dom/server");
1180
+ const mod = await import(conventionPath);
1181
+ const ErrorComponent = mod.default;
1182
+ if (typeof ErrorComponent !== "function")
1183
+ return null;
1184
+ const element = createElement(ErrorComponent, errorProps);
1185
+ const stream = await renderToReadableStream(element);
1186
+ return new Response(stream, {
1187
+ headers: { "Content-Type": "text/html" },
1188
+ status: 500
1189
+ });
1190
+ }, renderSvelteError = async (conventionPath, errorProps) => {
1191
+ const { render } = await import("svelte/server");
1192
+ const mod = await import(conventionPath);
1193
+ const ErrorComponent = mod.default;
1194
+ if (!ErrorComponent)
1195
+ return null;
1196
+ const { head, body } = render(ErrorComponent, {
1197
+ props: errorProps
1198
+ });
1199
+ const html = `<!DOCTYPE html><html><head>${head}</head><body>${body}</body></html>`;
1200
+ return new Response(html, {
1201
+ headers: { "Content-Type": "text/html" },
1202
+ status: 500
1203
+ });
1204
+ }, unescapeVueStyles = (ssrBody) => {
1205
+ let styles = "";
1206
+ const body = ssrBody.replace(/<style>([\s\S]*?)<\/style>/g, (_, css) => {
1207
+ styles += `<style>${css.replace(/&quot;/g, '"').replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">")}</style>`;
1208
+ return "";
1209
+ });
1210
+ return { body, styles };
1211
+ }, renderVueError = async (conventionPath, errorProps) => {
1212
+ const { createSSRApp, h } = await import("vue");
1213
+ const { renderToString } = await import("vue/server-renderer");
1214
+ const mod = await import(conventionPath);
1215
+ const ErrorComponent = mod.default;
1216
+ if (!ErrorComponent)
1217
+ return null;
1218
+ const app = createSSRApp({
1219
+ render: () => h(ErrorComponent, errorProps)
1220
+ });
1221
+ const rawBody = await renderToString(app);
1222
+ const { styles, body } = unescapeVueStyles(rawBody);
1223
+ const html = `<!DOCTYPE html><html><head>${styles}</head><body><div id="root">${body}</div></body></html>`;
1224
+ return new Response(html, {
1225
+ headers: { "Content-Type": "text/html" },
1226
+ status: 500
1227
+ });
1228
+ }, renderAngularError = async (conventionPath, errorProps) => {
1229
+ const mod = await import(conventionPath);
1230
+ const renderFn = mod.default;
1231
+ if (typeof renderFn !== "function")
1232
+ return null;
1233
+ const html = renderFn(errorProps);
1234
+ return new Response(html, {
1235
+ headers: { "Content-Type": "text/html" },
1236
+ status: 500
1237
+ });
1238
+ }, escapeHtml = (value) => value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;"), replaceErrorTokens = (template, errorProps) => template.replace(/\{\{\s*name\s*\}\}/g, escapeHtml(errorProps.name)).replace(/\{\{\s*message\s*\}\}/g, escapeHtml(errorProps.message)).replace(/\{\{\s*stack\s*\}\}/g, errorProps.stack ? escapeHtml(errorProps.stack) : ""), renderHtmlError = async (conventionPath, errorProps) => {
1239
+ const template = await Bun.file(conventionPath).text();
1240
+ const html = replaceErrorTokens(template, errorProps);
1241
+ return new Response(html, {
1242
+ headers: { "Content-Type": "text/html" },
1243
+ status: 500
1244
+ });
1245
+ }, logConventionRenderError = (framework, label, renderError) => {
1246
+ const message = renderError instanceof Error ? renderError.message : "";
1247
+ if (message.includes("Cannot find module") || message.includes("Cannot find package") || message.includes("not found in module")) {
1248
+ console.error(`[SSR] Convention ${label} page for ${framework} failed: missing framework package. Ensure the ${framework} runtime is installed (e.g. bun add ${framework === "react" ? "react react-dom" : framework}).`);
1249
+ return;
1250
+ }
1251
+ console.error(`[SSR] Failed to render ${framework} convention ${label} page:`, renderError);
1252
+ }, renderEmberError = async () => null, renderEmberNotFound = async () => null, ERROR_RENDERERS, tryFrameworkErrorConvention = async (framework, pageName, errorProps, error) => {
1253
+ let conventionPath = resolveErrorConventionPath(framework, pageName);
1254
+ if (!conventionPath && error instanceof Error && error.stack) {
1255
+ for (const match of error.stack.matchAll(/^\s*at\s+([A-Za-z_$][\w$]*)/gm)) {
1256
+ const candidate = match[1];
1257
+ if (!candidate)
1258
+ continue;
1259
+ conventionPath = resolveErrorConventionPath(framework, candidate);
1260
+ if (conventionPath)
1261
+ break;
1262
+ }
1263
+ }
1264
+ if (!conventionPath)
1265
+ return null;
1266
+ const renderer = ERROR_RENDERERS[framework];
1267
+ if (!renderer)
1268
+ return null;
1269
+ try {
1270
+ return await renderer(conventionPath, errorProps);
1271
+ } catch (renderError) {
1272
+ logConventionRenderError(framework, "error", renderError);
1273
+ }
1274
+ return null;
1275
+ }, renderConventionError = async (framework, pageName, error) => {
1276
+ const errorProps = buildErrorProps(error);
1277
+ const frameworkResponse = await tryFrameworkErrorConvention(framework, pageName, errorProps, error);
1278
+ if (frameworkResponse)
1279
+ return frameworkResponse;
1280
+ if (framework !== "html") {
1281
+ const htmlResponse = await tryFrameworkErrorConvention("html", pageName, errorProps, error);
1282
+ if (htmlResponse)
1283
+ return htmlResponse;
1284
+ }
1285
+ return null;
1286
+ }, renderReactNotFound = async (conventionPath) => {
1287
+ const { createElement } = await import("react");
1288
+ const { renderToReadableStream } = await import("react-dom/server");
1289
+ const mod = await import(conventionPath);
1290
+ const NotFoundComponent = mod.default;
1291
+ if (typeof NotFoundComponent !== "function")
1292
+ return null;
1293
+ const element = createElement(NotFoundComponent);
1294
+ const stream = await renderToReadableStream(element);
1295
+ return new Response(stream, {
1296
+ headers: { "Content-Type": "text/html" },
1297
+ status: 404
1298
+ });
1299
+ }, renderSvelteNotFound = async (conventionPath) => {
1300
+ const { render } = await import("svelte/server");
1301
+ const mod = await import(conventionPath);
1302
+ const NotFoundComponent = mod.default;
1303
+ if (!NotFoundComponent)
1304
+ return null;
1305
+ const { head, body } = render(NotFoundComponent);
1306
+ const html = `<!DOCTYPE html><html><head>${head}</head><body>${body}</body></html>`;
1307
+ return new Response(html, {
1308
+ headers: { "Content-Type": "text/html" },
1309
+ status: 404
1310
+ });
1311
+ }, renderVueNotFound = async (conventionPath) => {
1312
+ const { createSSRApp, h } = await import("vue");
1313
+ const { renderToString } = await import("vue/server-renderer");
1314
+ const mod = await import(conventionPath);
1315
+ const NotFoundComponent = mod.default;
1316
+ if (!NotFoundComponent)
1317
+ return null;
1318
+ const app = createSSRApp({
1319
+ render: () => h(NotFoundComponent)
1320
+ });
1321
+ const rawBody = await renderToString(app);
1322
+ const { styles, body } = unescapeVueStyles(rawBody);
1323
+ const html = `<!DOCTYPE html><html><head>${styles}</head><body><div id="root">${body}</div></body></html>`;
1324
+ return new Response(html, {
1325
+ headers: { "Content-Type": "text/html" },
1326
+ status: 404
1327
+ });
1328
+ }, renderAngularNotFound = async (conventionPath) => {
1329
+ const mod = await import(conventionPath);
1330
+ const renderFn = mod.default;
1331
+ if (typeof renderFn !== "function")
1332
+ return null;
1333
+ const html = renderFn();
1334
+ return new Response(html, {
1335
+ headers: { "Content-Type": "text/html" },
1336
+ status: 404
1337
+ });
1338
+ }, renderHtmlNotFound = async (conventionPath) => {
1339
+ const html = await Bun.file(conventionPath).text();
1340
+ return new Response(html, {
1341
+ headers: { "Content-Type": "text/html" },
1342
+ status: 404
1343
+ });
1344
+ }, NOT_FOUND_RENDERERS, renderConventionNotFound = async (framework) => {
1345
+ const conventionPath = resolveNotFoundConventionPath(framework);
1346
+ if (!conventionPath)
1347
+ return null;
1348
+ const renderer = NOT_FOUND_RENDERERS[framework];
1349
+ if (!renderer)
1350
+ return null;
1351
+ try {
1352
+ return await renderer(conventionPath);
1353
+ } catch (renderError) {
1354
+ logConventionRenderError(framework, "not-found", renderError);
1355
+ }
1356
+ return null;
1357
+ }, NOT_FOUND_PRIORITY, renderFirstNotFound = async () => {
1358
+ const renderNext = async (frameworks) => {
1359
+ const [framework, ...remaining] = frameworks;
1360
+ if (!framework) {
1361
+ return null;
1362
+ }
1363
+ if (!getMap()[framework]?.defaults?.notFound) {
1364
+ return renderNext(remaining);
1365
+ }
1366
+ const response = await renderConventionNotFound(framework);
1367
+ if (response) {
1368
+ return response;
1369
+ }
1370
+ return renderNext(remaining);
1371
+ };
1372
+ return renderNext(NOT_FOUND_PRIORITY);
1373
+ };
1374
+ var init_resolveConvention = __esm(() => {
1375
+ ERROR_RENDERERS = {
1376
+ angular: renderAngularError,
1377
+ ember: renderEmberError,
1378
+ html: renderHtmlError,
1379
+ react: renderReactError,
1380
+ svelte: renderSvelteError,
1381
+ vue: renderVueError
1382
+ };
1383
+ NOT_FOUND_RENDERERS = {
1384
+ angular: renderAngularNotFound,
1385
+ ember: renderEmberNotFound,
1386
+ html: renderHtmlNotFound,
1387
+ react: renderReactNotFound,
1388
+ svelte: renderSvelteNotFound,
1389
+ vue: renderVueNotFound
1390
+ };
1391
+ NOT_FOUND_PRIORITY = [
1392
+ "react",
1393
+ "svelte",
1394
+ "vue",
1395
+ "angular",
1396
+ "html"
1397
+ ];
1398
+ });
1399
+
1400
+ // src/utils/spaRouteManifest.ts
1401
+ import { basename as basename2 } from "path";
1402
+ var SPA_ROUTES_KEY = "__absoluteSpaRoutes", setSpaRouteManifest = (hosts) => {
1403
+ Reflect.set(globalThis, SPA_ROUTES_KEY, hosts);
1404
+ }, getSpaRouteManifest = () => {
1405
+ const value = Reflect.get(globalThis, SPA_ROUTES_KEY);
1406
+ return Array.isArray(value) ? value : [];
1407
+ }, normalizePath = (path) => {
1408
+ const withLeadingSlash = path.startsWith("/") ? path : `/${path}`;
1409
+ const trimmed = withLeadingSlash.replace(/\/+$/, "");
1410
+ return trimmed || "/";
1411
+ }, fullRoutePath = (baseHref, routePath) => {
1412
+ const base = normalizePath(baseHref);
1413
+ const route = normalizePath(routePath);
1414
+ if (base !== "/" && (route === base || route.startsWith(`${base}/`))) {
1415
+ return route;
1416
+ }
1417
+ if (base === "/")
1418
+ return route;
1419
+ return normalizePath(`${base}/${route.replace(/^\/+/, "")}`);
1420
+ }, routePattern = (path) => {
1421
+ const segments = normalizePath(path).split("/").filter(Boolean);
1422
+ let expression = "^";
1423
+ for (const segment of segments) {
1424
+ if (segment === "*" || segment === "**") {
1425
+ expression += "(?:/.*)?";
1426
+ continue;
1427
+ }
1428
+ const parameter = /^:[A-Za-z_$][A-Za-z0-9_$]*(?:\((.*)\))?(\?)?$/.exec(segment);
1429
+ if (parameter) {
1430
+ const valuePattern = parameter[1] || "[^/]+";
1431
+ expression += parameter[2] ? `(?:/${valuePattern})?` : `/${valuePattern}`;
1432
+ continue;
1433
+ }
1434
+ expression += `/${segment.replace(/[.+?^${}()|[\]\\]/g, "\\$&")}`;
1435
+ }
1436
+ return new RegExp(`${expression || "^/"}/?$`);
1437
+ }, sourcePageName = (sourceFile) => basename2(sourceFile).replace(/\.[^.]+$/, "").toLowerCase(), isKnownSpaRoute = (framework, pageName, request) => {
1438
+ if (!request)
1439
+ return true;
1440
+ let pathname;
1441
+ try {
1442
+ pathname = normalizePath(new URL(request.url).pathname);
1443
+ } catch {
1444
+ return true;
1445
+ }
1446
+ const hosts = getSpaRouteManifest().filter((host) => {
1447
+ if (host.framework !== framework)
1448
+ return false;
1449
+ if (sourcePageName(host.sourceFile) !== pageName.toLowerCase())
1450
+ return false;
1451
+ const base = normalizePath(host.baseHref);
1452
+ return base === "/" || pathname === base || pathname.startsWith(`${base}/`);
1453
+ });
1454
+ if (hosts.length === 0)
1455
+ return true;
1456
+ return hosts.some((host) => host.routes.some((route) => routePattern(fullRoutePath(host.baseHref, route.path)).test(pathname)));
1457
+ }, renderSpaNotFound = async (framework, pageName, request) => {
1458
+ if (isKnownSpaRoute(framework, pageName, request))
1459
+ return null;
1460
+ return await renderFirstNotFound() ?? new Response("Not found", {
1461
+ headers: { "Content-Type": "text/plain" },
1462
+ status: 404
1463
+ });
1464
+ };
1465
+ var init_spaRouteManifest = __esm(() => {
1466
+ init_resolveConvention();
1467
+ });
1468
+
1132
1469
  // src/core/streamingSlotRegistrar.ts
1133
1470
  var STREAMING_SLOT_REGISTRAR_KEY = Symbol.for("absolutejs.streamingSlotRegistrar");
1134
1471
  var STREAMING_SLOT_WARNING_STORAGE_KEY = Symbol.for("absolutejs.streamingSlotWarningController");
@@ -1569,303 +1906,10 @@ var captureStreamingSlotWarningCallsite = () => {
1569
1906
  return extractCallsiteFromStack(stack);
1570
1907
  };
1571
1908
  var runWithStreamingSlotWarningScope = (task, metadata) => ensureWarningStorage().run({ handlerCallsite: metadata?.handlerCallsite, hasWarned: false }, task);
1572
- // src/utils/resolveConvention.ts
1573
- import { basename } from "path";
1574
- var CONVENTIONS_KEY = "__absoluteConventions";
1575
- var isConventionsMap = (value) => Boolean(value) && typeof value === "object";
1576
- var getMap = () => {
1577
- const value = Reflect.get(globalThis, CONVENTIONS_KEY);
1578
- if (isConventionsMap(value))
1579
- return value;
1580
- const empty = {};
1581
- return empty;
1582
- };
1583
- var derivePageName = (pagePath) => {
1584
- const base = basename(pagePath);
1585
- const dotIndex = base.indexOf(".");
1586
- const name = dotIndex > 0 ? base.slice(0, dotIndex) : base;
1587
- return toPascal(name);
1588
- };
1589
- var normalizeConventionPageName = (name) => toPascal(name).replace(/\d+$/, "");
1590
- var hasErrorConvention = (framework) => {
1591
- const conventions = getMap()[framework];
1592
- if (!conventions)
1593
- return false;
1594
- if (conventions.defaults?.error)
1595
- return true;
1596
- return Object.values(conventions.pages ?? {}).some((page) => Boolean(page.error));
1597
- };
1598
- var resolveErrorConventionPath = (framework, pageName) => {
1599
- const conventions = getMap()[framework];
1600
- if (!conventions)
1601
- return;
1602
- const exact = conventions.pages?.[pageName]?.error;
1603
- if (exact)
1604
- return exact;
1605
- const normalizedPageName = normalizeConventionPageName(pageName);
1606
- for (const [candidate, page] of Object.entries(conventions.pages ?? {})) {
1607
- if (normalizeConventionPageName(candidate) === normalizedPageName) {
1608
- return page.error ?? conventions.defaults?.error;
1609
- }
1610
- }
1611
- return conventions.defaults?.error;
1612
- };
1613
- var resolveNotFoundConventionPath = (framework) => getMap()[framework]?.defaults?.notFound;
1614
- var setConventions = (map) => {
1615
- Reflect.set(globalThis, CONVENTIONS_KEY, map);
1616
- };
1617
- var isDev = () => true;
1618
- var buildErrorProps = (error) => {
1619
- if (error instanceof Error) {
1620
- return {
1621
- name: error.name,
1622
- message: error.message,
1623
- ...isDev() && error.stack ? { stack: error.stack } : {}
1624
- };
1625
- }
1626
- return { message: String(error), name: "Error" };
1627
- };
1628
- var renderReactError = async (conventionPath, errorProps) => {
1629
- const { createElement } = await import("react");
1630
- const { renderToReadableStream } = await import("react-dom/server");
1631
- const mod = await import(conventionPath);
1632
- const ErrorComponent = mod.default;
1633
- if (typeof ErrorComponent !== "function")
1634
- return null;
1635
- const element = createElement(ErrorComponent, errorProps);
1636
- const stream = await renderToReadableStream(element);
1637
- return new Response(stream, {
1638
- headers: { "Content-Type": "text/html" },
1639
- status: 500
1640
- });
1641
- };
1642
- var renderSvelteError = async (conventionPath, errorProps) => {
1643
- const { render } = await import("svelte/server");
1644
- const mod = await import(conventionPath);
1645
- const ErrorComponent = mod.default;
1646
- if (!ErrorComponent)
1647
- return null;
1648
- const { head, body } = render(ErrorComponent, {
1649
- props: errorProps
1650
- });
1651
- const html = `<!DOCTYPE html><html><head>${head}</head><body>${body}</body></html>`;
1652
- return new Response(html, {
1653
- headers: { "Content-Type": "text/html" },
1654
- status: 500
1655
- });
1656
- };
1657
- var unescapeVueStyles = (ssrBody) => {
1658
- let styles = "";
1659
- const body = ssrBody.replace(/<style>([\s\S]*?)<\/style>/g, (_, css) => {
1660
- styles += `<style>${css.replace(/&quot;/g, '"').replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">")}</style>`;
1661
- return "";
1662
- });
1663
- return { body, styles };
1664
- };
1665
- var renderVueError = async (conventionPath, errorProps) => {
1666
- const { createSSRApp, h } = await import("vue");
1667
- const { renderToString } = await import("vue/server-renderer");
1668
- const mod = await import(conventionPath);
1669
- const ErrorComponent = mod.default;
1670
- if (!ErrorComponent)
1671
- return null;
1672
- const app = createSSRApp({
1673
- render: () => h(ErrorComponent, errorProps)
1674
- });
1675
- const rawBody = await renderToString(app);
1676
- const { styles, body } = unescapeVueStyles(rawBody);
1677
- const html = `<!DOCTYPE html><html><head>${styles}</head><body><div id="root">${body}</div></body></html>`;
1678
- return new Response(html, {
1679
- headers: { "Content-Type": "text/html" },
1680
- status: 500
1681
- });
1682
- };
1683
- var renderAngularError = async (conventionPath, errorProps) => {
1684
- const mod = await import(conventionPath);
1685
- const renderFn = mod.default;
1686
- if (typeof renderFn !== "function")
1687
- return null;
1688
- const html = renderFn(errorProps);
1689
- return new Response(html, {
1690
- headers: { "Content-Type": "text/html" },
1691
- status: 500
1692
- });
1693
- };
1694
- var escapeHtml = (value) => value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
1695
- var replaceErrorTokens = (template, errorProps) => template.replace(/\{\{\s*name\s*\}\}/g, escapeHtml(errorProps.name)).replace(/\{\{\s*message\s*\}\}/g, escapeHtml(errorProps.message)).replace(/\{\{\s*stack\s*\}\}/g, errorProps.stack ? escapeHtml(errorProps.stack) : "");
1696
- var renderHtmlError = async (conventionPath, errorProps) => {
1697
- const template = await Bun.file(conventionPath).text();
1698
- const html = replaceErrorTokens(template, errorProps);
1699
- return new Response(html, {
1700
- headers: { "Content-Type": "text/html" },
1701
- status: 500
1702
- });
1703
- };
1704
- var logConventionRenderError = (framework, label, renderError) => {
1705
- const message = renderError instanceof Error ? renderError.message : "";
1706
- if (message.includes("Cannot find module") || message.includes("Cannot find package") || message.includes("not found in module")) {
1707
- console.error(`[SSR] Convention ${label} page for ${framework} failed: missing framework package. Ensure the ${framework} runtime is installed (e.g. bun add ${framework === "react" ? "react react-dom" : framework}).`);
1708
- return;
1709
- }
1710
- console.error(`[SSR] Failed to render ${framework} convention ${label} page:`, renderError);
1711
- };
1712
- var renderEmberError = async () => null;
1713
- var renderEmberNotFound = async () => null;
1714
- var ERROR_RENDERERS = {
1715
- angular: renderAngularError,
1716
- ember: renderEmberError,
1717
- html: renderHtmlError,
1718
- react: renderReactError,
1719
- svelte: renderSvelteError,
1720
- vue: renderVueError
1721
- };
1722
- var tryFrameworkErrorConvention = async (framework, pageName, errorProps, error) => {
1723
- let conventionPath = resolveErrorConventionPath(framework, pageName);
1724
- if (!conventionPath && error instanceof Error && error.stack) {
1725
- for (const match of error.stack.matchAll(/^\s*at\s+([A-Za-z_$][\w$]*)/gm)) {
1726
- const candidate = match[1];
1727
- if (!candidate)
1728
- continue;
1729
- conventionPath = resolveErrorConventionPath(framework, candidate);
1730
- if (conventionPath)
1731
- break;
1732
- }
1733
- }
1734
- if (!conventionPath)
1735
- return null;
1736
- const renderer = ERROR_RENDERERS[framework];
1737
- if (!renderer)
1738
- return null;
1739
- try {
1740
- return await renderer(conventionPath, errorProps);
1741
- } catch (renderError) {
1742
- logConventionRenderError(framework, "error", renderError);
1743
- }
1744
- return null;
1745
- };
1746
- var renderConventionError = async (framework, pageName, error) => {
1747
- const errorProps = buildErrorProps(error);
1748
- const frameworkResponse = await tryFrameworkErrorConvention(framework, pageName, errorProps, error);
1749
- if (frameworkResponse)
1750
- return frameworkResponse;
1751
- if (framework !== "html") {
1752
- const htmlResponse = await tryFrameworkErrorConvention("html", pageName, errorProps, error);
1753
- if (htmlResponse)
1754
- return htmlResponse;
1755
- }
1756
- return null;
1757
- };
1758
- var renderReactNotFound = async (conventionPath) => {
1759
- const { createElement } = await import("react");
1760
- const { renderToReadableStream } = await import("react-dom/server");
1761
- const mod = await import(conventionPath);
1762
- const NotFoundComponent = mod.default;
1763
- if (typeof NotFoundComponent !== "function")
1764
- return null;
1765
- const element = createElement(NotFoundComponent);
1766
- const stream = await renderToReadableStream(element);
1767
- return new Response(stream, {
1768
- headers: { "Content-Type": "text/html" },
1769
- status: 404
1770
- });
1771
- };
1772
- var renderSvelteNotFound = async (conventionPath) => {
1773
- const { render } = await import("svelte/server");
1774
- const mod = await import(conventionPath);
1775
- const NotFoundComponent = mod.default;
1776
- if (!NotFoundComponent)
1777
- return null;
1778
- const { head, body } = render(NotFoundComponent);
1779
- const html = `<!DOCTYPE html><html><head>${head}</head><body>${body}</body></html>`;
1780
- return new Response(html, {
1781
- headers: { "Content-Type": "text/html" },
1782
- status: 404
1783
- });
1784
- };
1785
- var renderVueNotFound = async (conventionPath) => {
1786
- const { createSSRApp, h } = await import("vue");
1787
- const { renderToString } = await import("vue/server-renderer");
1788
- const mod = await import(conventionPath);
1789
- const NotFoundComponent = mod.default;
1790
- if (!NotFoundComponent)
1791
- return null;
1792
- const app = createSSRApp({
1793
- render: () => h(NotFoundComponent)
1794
- });
1795
- const rawBody = await renderToString(app);
1796
- const { styles, body } = unescapeVueStyles(rawBody);
1797
- const html = `<!DOCTYPE html><html><head>${styles}</head><body><div id="root">${body}</div></body></html>`;
1798
- return new Response(html, {
1799
- headers: { "Content-Type": "text/html" },
1800
- status: 404
1801
- });
1802
- };
1803
- var renderAngularNotFound = async (conventionPath) => {
1804
- const mod = await import(conventionPath);
1805
- const renderFn = mod.default;
1806
- if (typeof renderFn !== "function")
1807
- return null;
1808
- const html = renderFn();
1809
- return new Response(html, {
1810
- headers: { "Content-Type": "text/html" },
1811
- status: 404
1812
- });
1813
- };
1814
- var renderHtmlNotFound = async (conventionPath) => {
1815
- const html = await Bun.file(conventionPath).text();
1816
- return new Response(html, {
1817
- headers: { "Content-Type": "text/html" },
1818
- status: 404
1819
- });
1820
- };
1821
- var NOT_FOUND_RENDERERS = {
1822
- angular: renderAngularNotFound,
1823
- ember: renderEmberNotFound,
1824
- html: renderHtmlNotFound,
1825
- react: renderReactNotFound,
1826
- svelte: renderSvelteNotFound,
1827
- vue: renderVueNotFound
1828
- };
1829
- var renderConventionNotFound = async (framework) => {
1830
- const conventionPath = resolveNotFoundConventionPath(framework);
1831
- if (!conventionPath)
1832
- return null;
1833
- const renderer = NOT_FOUND_RENDERERS[framework];
1834
- if (!renderer)
1835
- return null;
1836
- try {
1837
- return await renderer(conventionPath);
1838
- } catch (renderError) {
1839
- logConventionRenderError(framework, "not-found", renderError);
1840
- }
1841
- return null;
1842
- };
1843
- var NOT_FOUND_PRIORITY = [
1844
- "react",
1845
- "svelte",
1846
- "vue",
1847
- "angular",
1848
- "html"
1849
- ];
1850
- var renderFirstNotFound = async () => {
1851
- const renderNext = async (frameworks) => {
1852
- const [framework, ...remaining] = frameworks;
1853
- if (!framework) {
1854
- return null;
1855
- }
1856
- if (!getMap()[framework]?.defaults?.notFound) {
1857
- return renderNext(remaining);
1858
- }
1859
- const response = await renderConventionNotFound(framework);
1860
- if (response) {
1861
- return response;
1862
- }
1863
- return renderNext(remaining);
1864
- };
1865
- return renderNext(NOT_FOUND_PRIORITY);
1866
- };
1867
1909
 
1868
1910
  // src/react/pageHandler.ts
1911
+ init_spaRouteManifest();
1912
+ init_resolveConvention();
1869
1913
  var resolveRequestPathname = (request) => {
1870
1914
  if (!request)
1871
1915
  return;
@@ -1892,6 +1936,9 @@ var handleReactPageRequest = async (input) => {
1892
1936
  } : userProps;
1893
1937
  const pageName = Page.name || Page.displayName || "";
1894
1938
  try {
1939
+ const spaNotFound = await renderSpaNotFound("react", pageName, input.request);
1940
+ if (spaNotFound)
1941
+ return withPageCacheHeaders(spaNotFound, input.request);
1895
1942
  const handlerCallsite = options?.collectStreamingSlots === true ? undefined : getCurrentRouteRegistrationCallsite() ?? captureStreamingSlotWarningCallsite();
1896
1943
  const renderPageResponse = async () => {
1897
1944
  const { createElement } = await import("react");
@@ -1937,5 +1984,5 @@ export {
1937
1984
  handleReactPageRequest
1938
1985
  };
1939
1986
 
1940
- //# debugId=1A2978A6A06E690464756E2164756E21
1987
+ //# debugId=C6A90A3BEC2CC84964756E2164756E21
1941
1988
  //# sourceMappingURL=server.js.map