Repository navigation
Description
Problem
For a named prop used only for rendering, such as the example below, the current descriptor-free spelling in Strong mode uses an explicit () => @{ ... } wrapper. The existing inline @{ ... } syntax parses, but still produces a descriptor around a compiled fragment renderer.
Could explicit TSRX render values compile directly to a descriptor-free body, without an authored function wrapper? This is a focused compiler follow-up to #2059's broader Strong-mode/descriptor-free policy discussion.
Minimal reproduction
Verified with [email protected], in production client and server compilation with strong: true, dev: false, hmr: false, and requireDirective: true.
/** @jsxImportSource octane */
function Slot(props) @{
<section>{props.content}</section>;
}
export function Example(props) @{
<Slot content={@{
<span>{props.label as string}</span>;
}} />;
}
The inline block is accepted, but emitted output calls createElementFromConfig with a hoisted fragment renderer and captured values. It therefore retains descriptor construction even though the value is only rendered.
The current workaround is:
export function Example(props) @{
<Slot content={() => @{
<span>{props.label as string}</span>;
}} />;
}
That emits a compiled body and no descriptor constructor in this example. By comparison, ordinary template children already get a compiler-generated markChildrenBlock(...) body without an authored wrapper:
function Slot(props) @{ <section>{props.children}</section>; }
export function Example(props) @{
<Slot><span>{props.label as string}</span></Slot>;
}
The five minimal forms were compiled separately for both targets:
| Form | Client descriptor helper | Server descriptor helper |
|---|---|---|
| Direct template output | none | none |
| Ordinary template children | none | none |
| Named prop containing ordinary JSX | createScopedElement |
createScopedElement |
Named prop containing inline @{ ... } |
createElementFromConfig |
createElementFromConfig |
Named prop containing () => @{ ... } |
none | none |
Why the explicit wrapper matters
The workaround adds repetitive authoring and can obscure the distinction between an ordinary callback, an inspectable element value, and an Octane-owned render body. In the minimal client output above, the wrapper also changes the enclosing compiler memo dependency from props.label to the whole props object. A new props object with the same label can therefore invalidate that region.
The output contains a captured function, and the runtime renders it through a retained child block/scope. A new function value does not itself imply a remount; the runtime can reuse the block. Compiler memoization can also skip recreating the function. This issue does not claim a measured CPU/GC regression, zero-cost rendering, or that all functions should disappear from compiler output.
Requested behavior
Please support descriptor-free render values without an authored function wrapper in Strong mode. For compiler-proven render-only positions or an explicit render-only contract, could the existing inline @{ ... } form lower directly to a compiled body? Otherwise, provide an equally concise distinct render-value form. Prefer reusing the existing compiled-body/children-block machinery over introducing another general-purpose runtime abstraction.
The compiler should own captures, lifetime and invalidation, preserving narrow dependencies where sound. Merely inserting the same broad-capturing function in generated output would improve authoring but would not address the optimization opportunity.
Ordinary JSX and existing inline @{ ... } values are currently inspectable descriptors. A blanket rewrite would change isValidElement, Children and cloneElement contracts, so preserve those consumers unless a documented Strong-specific render-only contract changes the semantics. The design should distinguish explicit render intent from descriptor data. Broader Strong-mode descriptor policy can remain in #2059.
Acceptance and validation
- Compile the explicit named-prop render value above without descriptor-construction helpers, for client and server.
- Once the render-value semantics are defined, evaluate object slots, portal bodies and callback results as follow-on coverage; those positions have additional contracts and are not established by this reproduction.
- Preserve capture values, render/provider/effect ownership, evaluation timing, branch/type/key identity, repeated mounting and cleanup. Include SSR/hydration parity and reactive-update coverage.
- Preserve ordinary JSX/descriptor inspection behavior and distinguish body values from callbacks that the consumer invokes itself.
- Check unchanged captured leaves with a new containing props object, so dependency broadening is visible.
- Compare emitted production code, complete bundle gzip and allocation/update behavior against the current explicit-wrapper form. Source brevity alone is not evidence of lower runtime cost.
Current upstream source
The executable probe above uses released 0.13.5. I also checked current upstream main at 74f22dd7c895aee7da2272af11528703b2c70ef7; this was source inspection, not a rebuild of that revision.
- The value-directive walker routes inline blocks through the client fragment descriptor path and corresponding server path.
- Explicit arrow bodies take a separate compiled-function path.
- The documented descriptor/children distinction is a compatibility constraint for this change.
Activity