also looking at this
fix(includes): preserve {{ }} in @include partials that define their own signals (#1758)
#1759
3 files
+76
-6
| @@ -640,7 +640,7 @@ export function interpolateScriptsInTemplate( | ||
| 640 | 640 | /** |
| 641 | 641 | * Process template expressions including variables, filters, and operations |
| 642 | 642 | */ |
| 643 | export function processExpressions(template: string, context: Record<string, any>, filePath: string): string { | |
| 643 | export function processExpressions(template: string, context: Record<string, any>, filePath: string, options?: { forceSignals?: boolean }): string { | |
| 644 | 644 | let output = template |
| 645 | 645 | |
| 646 | 646 | // Protect <style> and <script> blocks that contain NO stx template |
| @@ -677,8 +677,13 @@ export function processExpressions(template: string, context: Record<string, any | ||
| 677 | 677 | output = maskInto(output, matchScriptElement, scriptBlocks, n => `<!--__STX_SCRIPT_EXPR_${n}__-->`) |
| 678 | 678 | |
| 679 | 679 | // Check if this template uses signals - if so, we need to preserve expressions |
| 680 | // that reference runtime variables (like loop variables or signal calls) | |
| 681 | const hasSignals = usesSignalsInScript(template) | |
| 680 | // that reference runtime variables (like loop variables or signal calls). | |
| 681 | // `forceSignals` is set by the @include path: a partial's <script> is stripped | |
| 682 | // (includes.ts) before this runs, so usesSignalsInScript(template) can't see its | |
| 683 | // own state()/derived(). The caller computes the gate on the partial's FULL | |
| 684 | // content and passes it here, so {{ }} over the partial's own signals are | |
| 685 | // preserved for the runtime — exactly like a top-level page. See stacksjs/stx#1758. | |
| 686 | const hasSignals = options?.forceSignals === true || usesSignalsInScript(template) | |
| 682 | 687 | |
| 683 | 688 | // Replace triple curly braces with unescaped expressions {{{ expr }}} - similar to {!! expr !!} |
| 684 | 689 | output = output.replace(/\{\{\{([\s\S]*?)\}\}\}/g, (match, expr, offset) => { |