Add component deps to page registry, check before client routing

Each page entry now includes a deps list of component names needed.
Client checks all deps are loaded before attempting eval — if any
are missing, falls through to server fetch with a clear log message.
No bundle bloat: server sends components for the current page only.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-06 22:06:28 +00:00
parent 3b00a7095a
commit 14c5316d17
3 changed files with 49 additions and 10 deletions

View File

@@ -14,7 +14,7 @@
// =========================================================================
var NIL = Object.freeze({ _nil: true, toString: function() { return "nil"; } });
var SX_VERSION = "2026-03-06T22:01:24Z";
var SX_VERSION = "2026-03-06T22:06:19Z";
function isNil(x) { return x === NIL || x === null || x === undefined; }
function isSxTruthy(x) { return x !== false && !isNil(x); }
@@ -1932,21 +1932,32 @@ return forEach(function(form) { return (isSxTruthy((isSxTruthy(!isSxTruthy(isPro
return bindBoostForm(form, method, action);
})()) : NIL); }, domQueryAll(container, "form")); };
// has-all-deps?
var hasAllDeps_p = function(deps) { return (function() {
var loaded = loadedComponentNames();
var missing = false;
{ var _c = deps; for (var _i = 0; _i < _c.length; _i++) { var dep = _c[_i]; if (isSxTruthy(!isSxTruthy(contains(loaded, dep)))) {
missing = dep;
} } }
return (isSxTruthy(missing) ? (logInfo((String("sx:route missing component ") + String(missing))), false) : true);
})(); };
// try-client-route
var tryClientRoute = function(pathname) { return (function() {
var match = findMatchingRoute(pathname, _pageRoutes);
return (isSxTruthy(isNil(match)) ? (logInfo((String("sx:route no match (") + String(len(_pageRoutes)) + String(" routes) ") + String(pathname))), false) : (isSxTruthy(get(match, "has-data")) ? (logInfo((String("sx:route server (has data) ") + String(pathname))), false) : (function() {
var contentSrc = get(match, "content");
var deps = sxOr(get(match, "deps"), []);
var closure = sxOr(get(match, "closure"), {});
var params = get(match, "params");
return (isSxTruthy(sxOr(isNil(contentSrc), isEmpty(contentSrc))) ? (logWarn((String("sx:route no content for ") + String(pathname))), false) : (function() {
return (isSxTruthy(sxOr(isNil(contentSrc), isEmpty(contentSrc))) ? (logWarn((String("sx:route no content for ") + String(pathname))), false) : (isSxTruthy(!isSxTruthy(hasAllDeps_p(deps))) ? (logInfo((String("sx:route server (missing deps) ") + String(pathname))), false) : (function() {
var env = merge(closure, params);
var rendered = tryEvalContent(contentSrc, env);
return (isSxTruthy(isNil(rendered)) ? (logWarn((String("sx:route eval failed for ") + String(pathname))), false) : (function() {
var target = domQueryById("main-panel");
return (isSxTruthy(isNil(target)) ? (logWarn("sx:route #main-panel not found"), false) : (domSetTextContent(target, ""), domAppend(target, rendered), hoistHeadElementsFull(target), processElements(target), sxHydrateElements(target), logInfo((String("sx:route client ") + String(pathname))), true));
})());
})());
})()));
})()));
})(); };