Stream extra component defs with resolve scripts

Resolved SX content may reference components not in the initial shell
scan (e.g. ~cart-mini from IO-generated headers). Diff the needed
components against what the shell already sent and prepend any extra
defcomps as a <script type="text/sx"> block before the resolve script.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-07 19:08:32 +00:00
parent 7294f07f5b
commit 47448a6d37
2 changed files with 48 additions and 6 deletions

View File

@@ -944,13 +944,22 @@ def sx_page_streaming_parts(ctx: dict, page_html: str, *,
return shell, tail
def sx_streaming_resolve_script(suspension_id: str, sx_source: str) -> str:
"""Build a <script> tag that resolves a streaming suspense placeholder."""
def sx_streaming_resolve_script(suspension_id: str, sx_source: str,
extra_components: str = "") -> str:
"""Build a <script> tag that resolves a streaming suspense placeholder.
If *extra_components* is non-empty, a ``<script type="text/sx">`` block
is prepended so the client loads those component defs before resolving.
"""
import json
return _SX_STREAMING_RESOLVE.format(
parts = []
if extra_components:
parts.append(f'<script type="text/sx">{extra_components}</script>')
parts.append(_SX_STREAMING_RESOLVE.format(
id=json.dumps(suspension_id),
sx=json.dumps(sx_source),
)
))
return "\n".join(parts)
_SCRIPT_HASH_CACHE: dict[str, str] = {}