Cache-bust wasm scripts, fix orchestration.sx paren balance
- Add wasm_hash (MD5 of sx_browser.bc.js) to shell template
- Script tags: /wasm/sx_browser.bc.js?v={hash}, /wasm/sx-platform.js?v={hash}
- Pass wasm_hash through helpers.py and ocaml_bridge.py
- Fix missing close paren in bind-sse-swap (broke SX parsing)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,7 @@ page elements (headers, search, etc.) from template context.
|
||||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
import os
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
@@ -884,12 +885,14 @@ def _get_shell_static() -> dict[str, Any]:
|
||||
sx_css_classes=sx_css_classes,
|
||||
sx_js_hash=_script_hash("sx-browser.js"),
|
||||
body_js_hash=_script_hash("body.js"),
|
||||
wasm_hash=_wasm_hash("sx_browser.bc.js"),
|
||||
asset_url=_ca.config.get("ASSET_URL", "/static"),
|
||||
head_scripts=_shell_cfg.get("head_scripts"),
|
||||
inline_css=_shell_cfg.get("inline_css"),
|
||||
inline_head_js=_shell_cfg.get("inline_head_js"),
|
||||
init_sx=_shell_cfg.get("init_sx"),
|
||||
body_scripts=_shell_cfg.get("body_scripts"),
|
||||
use_wasm=os.environ.get("SX_USE_WASM") == "1",
|
||||
)
|
||||
|
||||
t1 = time.monotonic()
|
||||
@@ -1081,8 +1084,11 @@ def sx_page_streaming_parts(ctx: dict, page_html: str, *,
|
||||
# Tail: bootstrap suspense resolver + scripts + close
|
||||
tail = (
|
||||
_SX_STREAMING_BOOTSTRAP + '\n'
|
||||
f'<script src="{asset_url}/scripts/sx-browser.js?v={sx_js_hash}"></script>\n'
|
||||
f'<script src="{asset_url}/scripts/body.js?v={body_js_hash}"></script>\n'
|
||||
+ (f'<script src="{asset_url}/wasm/sx_browser.bc.wasm.js"></script>\n'
|
||||
f'<script src="{asset_url}/wasm/sx-platform.js"></script>\n'
|
||||
if os.environ.get("SX_USE_WASM") == "1" else
|
||||
f'<script src="{asset_url}/scripts/sx-browser.js?v={sx_js_hash}"></script>\n')
|
||||
+ f'<script src="{asset_url}/scripts/body.js?v={body_js_hash}"></script>\n'
|
||||
)
|
||||
|
||||
return shell, tail
|
||||
@@ -1120,6 +1126,18 @@ def _script_hash(filename: str) -> str:
|
||||
return _SCRIPT_HASH_CACHE[filename]
|
||||
|
||||
|
||||
def _wasm_hash(filename: str) -> str:
|
||||
"""Compute MD5 hash of a static wasm file, cached for process lifetime."""
|
||||
key = "wasm/" + filename
|
||||
if key not in _SCRIPT_HASH_CACHE:
|
||||
try:
|
||||
data = (Path(__file__).resolve().parent.parent / "static" / "wasm" / filename).read_bytes()
|
||||
_SCRIPT_HASH_CACHE[key] = hashlib.md5(data).hexdigest()[:8]
|
||||
except OSError:
|
||||
_SCRIPT_HASH_CACHE[key] = "dev"
|
||||
return _SCRIPT_HASH_CACHE[key]
|
||||
|
||||
|
||||
def _get_csrf_token() -> str:
|
||||
"""Get the CSRF token from the current request context."""
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user