also looking at this
fix(client): preserve client-signal {{ }} + bind SVG classes via setAttribute
#1774
4 files
+354
-293
| @@ -507,8 +507,15 @@ function expressionUsesOnlyContextVars(expr: string, context: Record<string, any | ||
| 507 | 507 | if (!inTpl && ch === '`') { inTpl = true; tplDepth = 0; continue } |
| 508 | 508 | if (inTpl) { |
| 509 | 509 | if (ch === '`' && tplDepth === 0) { inTpl = false; continue } |
| 510 | if (ch === '$' && exprWithoutStrings[ti + 1] === '{') { tplDepth++; ti++; continue } | |
| 510 | // Separator so adjacent interpolations `${a}${b}` (or ones split only by | |
| 511 | // literal text, which we drop) don't fuse into one bogus identifier `ab`. | |
| 512 | if (ch === '$' && exprWithoutStrings[ti + 1] === '{') { tplDepth++; ti++; tplResult += ' '; continue } | |
| 511 | 513 | if (ch === '}' && tplDepth > 0) { tplDepth--; continue } |
| 514 | // Inside a `${ ... }` interpolation we're looking at an EXPRESSION, not string | |
| 515 | // text — keep it so its identifiers (e.g. a client-only signal `rating` in | |
| 516 | // `` `${rating}/5` ``) are still detected. Only the literal text between | |
| 517 | // interpolations (tplDepth === 0) is dropped. | |
| 518 | if (tplDepth > 0) { tplResult += ch; continue } | |
| 512 | 519 | continue |
| 513 | 520 | } |
| 514 | 521 | tplResult += ch |
| @@ -775,11 +782,15 @@ export function processExpressions(template: string, context: Record<string, any | ||
| 775 | 782 | try { |
| 776 | 783 | const value = evaluateExpression(expr, context) |
| 777 | 784 | |
| 778 | // For signal-based templates: if evaluation returned undefined and the expression | |
| 779 | // references variables NOT in the server-side context, preserve for client-side processing. | |
| 780 | // evaluateExpression() internally catches ReferenceError and returns undefined, | |
| 781 | // so we must check here rather than relying on the catch block below. | |
| 782 | if (value === undefined && hasSignals && !expressionUsesOnlyContextVars(trimmedExpr, context)) { | |
| 785 | // For signal-based templates: if the expression references variables NOT in the | |
| 786 | // server-side context (i.e. client-only signals), preserve it for client-side | |
| 787 | // processing REGARDLESS of the server-evaluated value. Gating on `value === undefined` | |
| 788 | // only preserved BARE `{{ signal }}` (which server-evaluates to undefined); a COMPOUND | |
| 789 | // expression like `{{ liked ? … : likes + ' people' }}` server-evaluates to a *defined* | |
| 790 | // string ("undefined people…") and so was wrongly baked into static HTML instead of | |
| 791 | // handed to the client — freezing it at the undefined-substituted text. Mirror the | |
| 792 | // catch-block logic below, which already preserves on the same condition. | |
| 793 | if (hasSignals && !expressionUsesOnlyContextVars(trimmedExpr, context)) { | |
| 783 | 794 | return match // Preserve {{ expr }} for runtime evaluation |
| 784 | 795 | } |
| 785 | 796 | |