ReviewOS

also looking at this

stacks/stx

feat(dx): dev-mode warning for unbalanced template tags (#1769)

#1770
Merged glennmichael123 wants to merge feat/1769-tag-balance-dev-warning into main
4 files +277 -0
packages/stx/src/includes.tsmodified+15-0
Changes to packages/stx/src/includes.ts
@@ -69,6 +69,7 @@
6969import type { StxOptions } from './types'
7070import path from 'node:path'
7171import { processConditionals } from './conditionals'
72import { isProduction, isTest } from './env'
7273import { processExpressions, usesSignalsInScript } from './expressions'
7374import { LRUCache } from './performance-utils'
7475import { createSafeFunction, isExpressionSafe, safeEvaluate, safeEvaluateObject } from './safe-evaluator'
@@ -880,6 +881,20 @@ catch (error: unknown) {
880881 partialContent = processStreamDirectives(partialContent, context)
881882 }
882883
884 // #1769: dev-mode tag-balance heads-up on the RAW partial, before SFC
885 // extraction / directive processing auto-closes anything. A dropped
886 // </div> silently re-parents following siblings and blanks the page with
887 // no error at any layer; a coarse per-tag open/close count catches it.
888 // On by default in development; opt-in via `debug` elsewhere; off in prod
889 // + the test runner. Pre-gated so the dynamic import is dev-only.
890 if (partialContent && (options.debug || (!isProduction() && !isTest()))) {
891 try {
892 const { warnUnbalancedTags } = await import('./template-tag-balance')
893 warnUnbalancedTags(partialContent, includeFilePath)
894 }
895 catch {}
896 }
897
883898 // SFC Support: Extract <template>, <script>, and <style> sections
884899 let workingContent = partialContent
885900