ReviewOS

stacks/stx

{⁠{ }} interpolations silently fail (left as literal text + x-cloak) inside :if blocks; :text bindings work

#1689
Closed glennmichael123 opened this 23 days ago · 0 comments
23 days ago

Summary

{⁠{ expr }} interpolations inside an element rendered via :if are not processed — the literal {⁠{ expr }} text is left in the DOM and the wrapping element keeps its auto-injected x-cloak, so the entire section ends up invisible ([x-cloak] { display: none !important }). No console error; no warning. Replacing the same expression with a :text="..." binding on the same element renders correctly.

Repro

Page template (simplified from a real app):

@section('content')
  <script client>
    const dashboard = useDashboard  // a store from `@stores`
    const loading = derived(() => dashboard.loading())
    const error = derived(() => dashboard.error())

    const tabPassing = derived(() => {
      // tabPassing reads from dashboard.allRepos() (store signal), filters, returns a number
      return dashboard.allRepos().filter(r => r.status === 'success').length
    })
  </script>

  <div :if="!loading && !error">
    <!-- Broken: literal `{⁠{ tabPassing }} passing` is left in DOM, x-cloak retained -->
    <span class="text-emerald-600">{{ tabPassing }} passing</span>

    <!-- Works: same value renders correctly via :text -->
    <span class="text-emerald-600" :text="tabPassingText"></span>
  </div>
@endsection

(tabPassingText is just derived(() => tabPassing() + ' passing').)

Rendered HTML for the broken span (note x-cloak and unprocessed interpolation):

<span class="text-emerald-600 ..." x-cloak>{{ tabPassing }} passing</span>

Expected

{⁠{ expr }} interpolations should be processed and x-cloak removed once the :if flips true, identically to how :text="expr" works on the same element.

Actual

  • Interpolation expression is left as literal text in the DOM.
  • x-cloak is never removed → display: none !important hides the entire chain of affected elements.
  • No error or warning emitted.
  • Workaround: replace {⁠{ expr }} with :text="exprDerived" (where exprDerived returns the formatted string).

Notes

  • Same pattern works fine OUTSIDE the :if block.
  • Same pattern works fine in :for="x in xs" loops (e.g., {⁠{ x.foo }} interpolations on iterated items).
  • The expression I tested reads through a chain: derived → derived → store signal. Possibly relevant if the issue is in dependency tracking through derived chains during deferred :if mounting, but the :text workaround uses the same chain and works.

Environment

  • stx: linked workspace (@stacksjs/stx workspace package, current main)
  • bun: 1.3.10 macOS arm64
  • Project: SSR + client-side stores via @stores import

Why this matters

The failure is silent and the wrapping x-cloak makes the broken chunk invisible rather than visibly broken — easy to think the data isn't loading rather than that the template is mis-rendered. :text and {⁠{ }} are documented as interchangeable, so the divergence is surprising.

Sign in to comment on this issue.