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

@@ -644,12 +644,14 @@ def _build_pages_sx(service: str) -> str:
Returns SX dict literals (one per page) parseable by the client's
``parse`` function. Each dict has keys: name, path, auth, has-data,
content, closure.
content, closure, deps.
"""
import logging
_log = logging.getLogger("sx.pages")
from .pages import get_all_pages
from .parser import serialize as sx_serialize
from .deps import components_needed
from .jinja_bridge import _COMPONENT_ENV
pages = get_all_pages(service)
_log.debug("_build_pages_sx(%s): %d pages in registry", service, len(pages))
@@ -666,6 +668,12 @@ def _build_pages_sx(service: str) -> str:
auth = page_def.auth if isinstance(page_def.auth, str) else "custom"
has_data = "true" if page_def.data_expr is not None else "false"
# Component deps needed to render this page client-side
deps: set[str] = set()
if content_src and page_def.data_expr is None:
deps = components_needed(content_src, _COMPONENT_ENV)
deps_sx = "(" + " ".join(_sx_literal(d) for d in sorted(deps)) + ")"
# Build closure as SX dict
closure_parts: list[str] = []
for k, v in page_def.closure.items():
@@ -679,6 +687,7 @@ def _build_pages_sx(service: str) -> str:
+ " :auth " + _sx_literal(auth)
+ " :has-data " + has_data
+ " :content " + _sx_literal(content_src)
+ " :deps " + deps_sx
+ " :closure " + closure_sx + "}"
)
entries.append(entry)
@@ -702,6 +711,7 @@ def _sx_literal(v: object) -> str:
return "nil"
def sx_page(ctx: dict, page_sx: str, *,
meta_html: str = "") -> str:
"""Return a minimal HTML shell that boots the page from sx source.