Summary
On a signals page, a reactive @if(sig()) … @else … @endif chain whose @else branch contains a nested reactive @if produces malformed markup. A full page load hides it (the browser normalizes the stray tags), but the SPA router's innerHTML swap reproduces it verbatim, nesting a second <main> inside the swap container and aborting the View Transition (InvalidStateError: Transition was aborted).
Found while debugging why SPA navigation "couldn't be nailed" in a real app (a forgot-password page: @if(sent()) … @else〈form with @if(error())〉@endif).
Root cause — three stacked bugs
convertSignalDirectivesToAttributes— overlapping replacements. After matching the outer@ifblock, the top-level@if(scan also matched the nested@ifinside the else branch and pushed a second replacement whose range overlaps the outer one. Applying the two end-to-start (with stale indices) drops the inner branch content and leaves an unbalanced</template>.- Template-strip drops
<template @else>. The<template>preserve-lists (two inbun-plugin/serve.ts, one inincludes.ts) listed@ifbut not@else/@else-if, so the else arm's opening tag was stripped while its</template>survived — unbalanced markup → duplicate<main>on the router's innerHTML swap. bindIfChaincan't render<template>branches.bindIf/bindForclone template.content;bindIfChaininserted the inert<template>element directly, so a multi-element@else/@else-ifbranch rendered blank once the markup was well-formed.
Fix
- Recurse into branch bodies + skip the consumed block in the converter (no overlapping replacements).
- Add
@else/:else/x-elseto the<template>preserve-lists (shared constant to prevent drift). - Teach
bindIfChainto clone<template>branch content into a stable node set it toggles (mirroringbindIf/bindFor).
Includes unit + real-DOM regression tests.