Verified against the fork at main (dc048673a3), rendered through renderView — no dev server, no app.
Symptom
A signal-driven @if/@else chain around a builtin component writes stx's internal sentinel, including a literal NUL byte, into the response:
<a @else="�stx-boolean-attribute" href="/pricing" class="b" data-stx-link ...>The response stops being valid UTF-8. That matters more than the stray attribute:
filereports the page asdatarather thanHTML document text.grepgoes silent on it. It treats the file as binary, sogrep -cprints nothing at all — not0, nothing. Any verification step that greps rendered HTML returns an empty string and reads as a pass. I only noticed because a count column in my own check came back blank instead of0.
Minimal reproduction
Two files, no app:
{{-- page.stx --}}
<script client>
const pro = state(false)
</script>
<div>
@if (pro())
<StxLink to="/pricing" class="a">Manage</StxLink>
@else
<StxLink to="/pricing" class="b">Upgrade</StxLink>
@endif
</div>const { renderView } = await import('./dist/build-views.js')
const html = await renderView('page.stx', {}, { componentsDir: './components' })
console.log('NUL bytes:', (html.match(/\0/g) || []).length)
console.log(html.match(/<a [^>]*@else[^>]*>/g))NUL bytes: 1
anchors carrying @else: 1
"<a @else=\"stx-boolean-attribute\" href=\"/pricing\" class=\"b\" data-stx-link ...>"Both conditions are required, and each one alone renders clean:
| variant | NUL bytes |
|---|---|
@if (pro()) signal-driven + <StxLink> builtin | 1 |
@if (pro) plain server value + <StxLink> | 0 |
@if (pro()) signal-driven + a user component (<Btn>) | 0 |
@if/@else around plain <a> | 0 |
The server-value case never reaches this code — the chain is resolved during render and the branch is simply dropped. Only a signal-driven chain is rewritten into element-level directives, which is where the sentinel gets a chance to escape.
Cause
signal-processing.ts turns a signal-driven chain into element attributes, documented at signal-processing.ts:428-433:
@if(a()) <p>A</p> @elseif(b()) <p>B</p> @else <p>C</p> @endif
-> <p @if="a()">A</p>
<p @else-if="b()">B</p>
<p @else>C</p>@else is correctly valueless there. When that element is a component, parseAllAttributes records a valueless attribute as the sentinel (component-renderer.ts:371):
else {
// Boolean attribute
props[name] = BOOLEAN_ATTRIBUTE_SENTINEL // '\0stx-boolean-attribute'
}Then component-renderer.ts:154 classifies every @-prefixed attribute as an event handler and stores the value verbatim:
// --- Event attributes: @click, @submit.prevent, etc. ---
if (attrName.startsWith('@')) {
resolved.events[attrName] = attrValue
continue
}The comment names the intent — @click, @submit.prevent — but the structural directives @if / @else-if / @else land here too. They are not events. A builtin that forwards unconsumed props onto real markup then emits the sentinel as an attribute value.
Two sibling branches already handle the sentinel (:173 for events resolved as props, :283 mapping it to 'true' for plain static attributes). The path that forwards @-attributes to markup does not.
Why @if survives and only @else breaks
@if carries a real expression, so events['@if'] = 'pro()' and it emits @if="pro()" — which is exactly what the runtime wants, so it works by luck rather than by design. @else carries no value, so it gets the sentinel. From the same rendered page:
<a @if="pro()" href="/pricing" class="a" data-stx-link ...> <!-- fine -->
<a @else="�stx-boolean-attribute" href="/pricing" class="b" ...> <!-- broken -->There is an ALPINE_PASSTHROUGH set (component-renderer.ts:103) listing x-if, x-for, x-show … so the x- structural family is explicitly protected. There is no equivalent for the @ structural family.
BOOLEAN_ATTRIBUTE_SENTINEL has no test referencing it — grep -rn 'BOOLEAN_ATTRIBUTE_SENTINEL\|stx-boolean-attribute' packages/stx/test returns nothing.
How it shows up in practice
The authored source is idiomatic and gives no hint:
@if (pro())
<StxLink to="/pricing" class="btn btn-ghost">Manage plan</StxLink>
@else
<StxLink to="/pricing" class="btn btn-primary">Upgrade to Pro</StxLink>
@endifI hit this converting plain anchors to StxLink across an app. The same conditional was correct for as long as it wrapped <a>, and became a malformed, non-UTF-8 response the moment the branches became a builtin component — with no error, no warning, and a page that still looks right.
Workaround
Avoid @else immediately before a component; two @if blocks render the same states:
@if (pro())
<StxLink to="/pricing" class="btn btn-ghost">Manage plan</StxLink>
@endif
@if (!pro())
<StxLink to="/pricing" class="btn btn-primary">Upgrade to Pro</StxLink>
@endifVerified: 0 NUL bytes and 0 stray @else across all 14 routes of the app, both states still rendered, both links still routed.
Suggested fix
I have not written a patch, so treating this as a report rather than asserting the shape. The narrow fix is to stop classifying structural directives as events at :154 — route @if / @else-if / @else to passthrough the way ALPINE_PASSTHROUGH handles the x- family, and emit a valueless attribute rather than the sentinel.
Worth considering separately: the sentinel is a raw NUL, so any path that fails to strip it produces an invalid response and silences downstream text tooling. A sentinel that cannot appear verbatim in valid output — or an assertion at emit time that no \0 reaches the wire — would turn this class of bug from silent into loud.