Fix highlight undefined symbol by expanding component strings server-side

Page helpers returning SX component call strings (e.g. "(~docs-intro-content)")
were sent to the client unexpanded. Components containing Python-only helpers
like `highlight` then failed with "Undefined symbol" on the client. Now
async_eval_slot_to_sx re-parses and expands these strings server-side.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-05 01:45:04 +00:00
parent 0144220427
commit b15025befd

View File

@@ -1064,7 +1064,16 @@ async def async_eval_slot_to_sx(
if result is None or result is NIL:
return SxExpr("")
if isinstance(result, str):
# Plain strings from page helpers are already sx source — don't quote.
# Page helpers return sx source strings. If the string is a
# component call (starts with "(~"), re-parse and expand it
# server-side so that Python-only helpers like ``highlight``
# inside the component body get evaluated here, not on the client.
stripped = result.strip()
if stripped.startswith("(~"):
from .parser import parse_all
parsed = parse_all(stripped)
if parsed:
return await async_eval_slot_to_sx(parsed[0], env, ctx)
return SxExpr(result)
return SxExpr(serialize(result))