Fix defmacro expansion in _aser: check for macros before serializing ~components
The ~component check in _aser immediately serialized all names starting with ~ as unexpanded component calls. This meant defmacro definitions like ~root-header-auto were sent to the client unexpanded, causing "Undefined symbol: root-header-ctx" errors since IO primitives only exist server-side. Now checks env for Macro instances first. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1127,8 +1127,12 @@ async def _aser(expr: Any, env: dict[str, Any], ctx: RequestContext) -> Any:
|
||||
if name.startswith("html:"):
|
||||
return await _aser_call(name[5:], expr[1:], env, ctx)
|
||||
|
||||
# Component call — serialize (don't expand)
|
||||
# Component call — expand macros, serialize regular components
|
||||
if name.startswith("~"):
|
||||
val = env.get(name)
|
||||
if isinstance(val, Macro):
|
||||
expanded = _expand_macro(val, expr[1:], env)
|
||||
return await _aser(expanded, env, ctx)
|
||||
return await _aser_call(name, expr[1:], env, ctx)
|
||||
|
||||
# Serialize-mode special/HO forms (checked BEFORE HTML_TAGS
|
||||
|
||||
Reference in New Issue
Block a user