@barefootjs/jsx 0.37.1 → 0.39.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (168) hide show
  1. package/dist/action-accessor.d.ts +159 -0
  2. package/dist/action-accessor.d.ts.map +1 -0
  3. package/dist/adapters/env-signal.d.ts +0 -8
  4. package/dist/adapters/env-signal.d.ts.map +1 -1
  5. package/dist/adapters/interface.d.ts +12 -0
  6. package/dist/adapters/interface.d.ts.map +1 -1
  7. package/dist/adapters/jsx-adapter.d.ts.map +1 -1
  8. package/dist/analyzer.d.ts +61 -1
  9. package/dist/analyzer.d.ts.map +1 -1
  10. package/dist/async-action-refusal.d.ts +45 -0
  11. package/dist/async-action-refusal.d.ts.map +1 -0
  12. package/dist/builtin-lowering-plugins.d.ts.map +1 -1
  13. package/dist/compiler.d.ts.map +1 -1
  14. package/dist/component-root-scope-comment.d.ts +36 -0
  15. package/dist/component-root-scope-comment.d.ts.map +1 -0
  16. package/dist/debug.d.ts +61 -5
  17. package/dist/debug.d.ts.map +1 -1
  18. package/dist/errors.d.ts +7 -0
  19. package/dist/errors.d.ts.map +1 -1
  20. package/dist/event-handler-name.d.ts +13 -0
  21. package/dist/event-handler-name.d.ts.map +1 -0
  22. package/dist/expression-parser.d.ts +9 -0
  23. package/dist/expression-parser.d.ts.map +1 -1
  24. package/dist/format-date-refusal.d.ts +33 -0
  25. package/dist/format-date-refusal.d.ts.map +1 -0
  26. package/dist/index.d.ts +6 -4
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +3260 -1914
  29. package/dist/ir-to-client-js/build-references.d.ts.map +1 -1
  30. package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
  31. package/dist/ir-to-client-js/compute-inlinability.d.ts.map +1 -1
  32. package/dist/ir-to-client-js/compute-scope.d.ts.map +1 -1
  33. package/dist/ir-to-client-js/control-flow/plan/build-branch-loop.d.ts.map +1 -1
  34. package/dist/ir-to-client-js/control-flow/plan/build-component-loop.d.ts.map +1 -1
  35. package/dist/ir-to-client-js/control-flow/plan/build-composite-loop.d.ts.map +1 -1
  36. package/dist/ir-to-client-js/control-flow/plan/build-loop-child-arm.d.ts.map +1 -1
  37. package/dist/ir-to-client-js/control-flow/plan/build-loop.d.ts.map +1 -1
  38. package/dist/ir-to-client-js/control-flow/plan/insert.d.ts +2 -0
  39. package/dist/ir-to-client-js/control-flow/plan/insert.d.ts.map +1 -1
  40. package/dist/ir-to-client-js/control-flow/plan/lazy-row-eligibility.d.ts +1 -1
  41. package/dist/ir-to-client-js/control-flow/plan/loop.d.ts +57 -12
  42. package/dist/ir-to-client-js/control-flow/plan/loop.d.ts.map +1 -1
  43. package/dist/ir-to-client-js/control-flow/shared.d.ts +44 -3
  44. package/dist/ir-to-client-js/control-flow/shared.d.ts.map +1 -1
  45. package/dist/ir-to-client-js/control-flow/stringify/component-loop.d.ts +7 -5
  46. package/dist/ir-to-client-js/control-flow/stringify/component-loop.d.ts.map +1 -1
  47. package/dist/ir-to-client-js/csr-substitute.d.ts.map +1 -1
  48. package/dist/ir-to-client-js/declaration-sort.d.ts +2 -1
  49. package/dist/ir-to-client-js/declaration-sort.d.ts.map +1 -1
  50. package/dist/ir-to-client-js/emit-module-level.d.ts.map +1 -1
  51. package/dist/ir-to-client-js/emit-reactive.d.ts +43 -2
  52. package/dist/ir-to-client-js/emit-reactive.d.ts.map +1 -1
  53. package/dist/ir-to-client-js/emit-registration.d.ts.map +1 -1
  54. package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
  55. package/dist/ir-to-client-js/plan/declaration-emit.d.ts +7 -5
  56. package/dist/ir-to-client-js/plan/declaration-emit.d.ts.map +1 -1
  57. package/dist/ir-to-client-js/prop-handling.d.ts.map +1 -1
  58. package/dist/ir-to-client-js/reactivity.d.ts +9 -1
  59. package/dist/ir-to-client-js/reactivity.d.ts.map +1 -1
  60. package/dist/ir-to-client-js/source-map.d.ts.map +1 -1
  61. package/dist/ir-to-client-js/types.d.ts +4 -0
  62. package/dist/ir-to-client-js/types.d.ts.map +1 -1
  63. package/dist/ir-to-client-js/utils.d.ts +66 -1
  64. package/dist/ir-to-client-js/utils.d.ts.map +1 -1
  65. package/dist/jsx-to-ir.d.ts.map +1 -1
  66. package/dist/opaque-local-accessor.d.ts +27 -0
  67. package/dist/opaque-local-accessor.d.ts.map +1 -0
  68. package/dist/signal-initializer.d.ts +24 -0
  69. package/dist/signal-initializer.d.ts.map +1 -0
  70. package/dist/template-position-walk.d.ts +68 -0
  71. package/dist/template-position-walk.d.ts.map +1 -0
  72. package/dist/to-locale-date-lowering.d.ts +7 -4
  73. package/dist/to-locale-date-lowering.d.ts.map +1 -1
  74. package/dist/types.d.ts +104 -17
  75. package/dist/types.d.ts.map +1 -1
  76. package/package.json +2 -2
  77. package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +878 -4528
  78. package/src/__tests__/action-accessor.test.ts +166 -0
  79. package/src/__tests__/binding-scope-ratchet.test.ts +21 -10
  80. package/src/__tests__/branch-local-in-raw-capture.test.ts +1 -1
  81. package/src/__tests__/branch-local-same-name-collision.test.ts +9 -9
  82. package/src/__tests__/client-js-generation.test.ts +175 -0
  83. package/src/__tests__/component-root-scope-comment.test.ts +106 -0
  84. package/src/__tests__/create-mutation.test.ts +220 -0
  85. package/src/__tests__/create-query.test.ts +644 -0
  86. package/src/__tests__/csr-fragment-root-scope-shape.test.ts +156 -0
  87. package/src/__tests__/debug.test.ts +222 -0
  88. package/src/__tests__/doc-examples.test.ts +78 -25
  89. package/src/__tests__/event-handler-name.test.ts +74 -0
  90. package/src/__tests__/flatmap-segments.test.ts +11 -9
  91. package/src/__tests__/format-date-refusal.test.ts +134 -0
  92. package/src/__tests__/fragment-wrapped-conditional-return-branch.test.ts +132 -0
  93. package/src/__tests__/hydrate-template.test.ts +9 -1
  94. package/src/__tests__/issue-2798-static-nested-loop-bindings.test.ts +2 -2
  95. package/src/__tests__/issue-3009-loop-branch-ref.test.ts +2 -2
  96. package/src/__tests__/issue-3044-nested-prop-object-array-not-static.test.ts +213 -0
  97. package/src/__tests__/issue-3113-init-fn-name-collision.test.ts +133 -0
  98. package/src/__tests__/jsx-return-type-assertion.test.ts +2 -2
  99. package/src/__tests__/lazy-row-eligibility.test.ts +5 -4
  100. package/src/__tests__/loop-row-child-children-reactive-attrs.test.ts +108 -0
  101. package/src/__tests__/loop-row-child-text-children-markers.test.ts +158 -0
  102. package/src/__tests__/opaque-local-accessor.test.ts +90 -0
  103. package/src/__tests__/profiler-e2e.test.ts +13 -8
  104. package/src/__tests__/props-destructuring.test.ts +79 -4
  105. package/src/__tests__/reactive-factory-arity.test.ts +311 -0
  106. package/src/__tests__/ref-attr-absent-at-ssr.test.ts +472 -0
  107. package/src/__tests__/ssr-portal-ref-callback.test.ts +219 -0
  108. package/src/action-accessor.ts +289 -0
  109. package/src/adapters/env-signal.ts +2 -21
  110. package/src/adapters/interface.ts +13 -0
  111. package/src/adapters/jsx-adapter.ts +17 -0
  112. package/src/analyzer.ts +589 -60
  113. package/src/async-action-refusal.ts +254 -0
  114. package/src/builtin-lowering-plugins.ts +0 -2
  115. package/src/compiler.ts +27 -0
  116. package/src/component-root-scope-comment.ts +59 -0
  117. package/src/debug.ts +318 -103
  118. package/src/errors.ts +83 -1
  119. package/src/event-handler-name.ts +14 -0
  120. package/src/expression-parser.ts +41 -17
  121. package/src/format-date-refusal.ts +147 -0
  122. package/src/index.ts +14 -3
  123. package/src/ir-to-client-js/build-references.ts +6 -2
  124. package/src/ir-to-client-js/child-components.ts +8 -3
  125. package/src/ir-to-client-js/collect-elements.ts +28 -13
  126. package/src/ir-to-client-js/compute-inlinability.ts +2 -1
  127. package/src/ir-to-client-js/compute-scope.ts +3 -1
  128. package/src/ir-to-client-js/control-flow/plan/build-branch-loop.ts +2 -4
  129. package/src/ir-to-client-js/control-flow/plan/build-component-loop.ts +67 -5
  130. package/src/ir-to-client-js/control-flow/plan/build-composite-loop.ts +3 -6
  131. package/src/ir-to-client-js/control-flow/plan/build-insert.ts +1 -0
  132. package/src/ir-to-client-js/control-flow/plan/build-loop-child-arm.ts +2 -1
  133. package/src/ir-to-client-js/control-flow/plan/build-loop.ts +23 -11
  134. package/src/ir-to-client-js/control-flow/plan/insert.ts +2 -0
  135. package/src/ir-to-client-js/control-flow/plan/lazy-row-eligibility.ts +3 -3
  136. package/src/ir-to-client-js/control-flow/plan/loop.ts +51 -10
  137. package/src/ir-to-client-js/control-flow/shared.ts +78 -5
  138. package/src/ir-to-client-js/control-flow/stringify/component-loop.ts +25 -12
  139. package/src/ir-to-client-js/control-flow/stringify/insert.ts +1 -1
  140. package/src/ir-to-client-js/csr-substitute.ts +11 -3
  141. package/src/ir-to-client-js/declaration-sort.ts +7 -3
  142. package/src/ir-to-client-js/emit-module-level.ts +7 -4
  143. package/src/ir-to-client-js/emit-reactive.ts +140 -10
  144. package/src/ir-to-client-js/emit-registration.ts +6 -11
  145. package/src/ir-to-client-js/generate-init.ts +2 -2
  146. package/src/ir-to-client-js/html-template.ts +41 -19
  147. package/src/ir-to-client-js/index.ts +9 -3
  148. package/src/ir-to-client-js/phases/ref-callbacks.ts +1 -1
  149. package/src/ir-to-client-js/plan/build-declaration-emit.ts +16 -15
  150. package/src/ir-to-client-js/plan/declaration-emit.ts +7 -5
  151. package/src/ir-to-client-js/prop-handling.ts +4 -0
  152. package/src/ir-to-client-js/reactivity.ts +21 -16
  153. package/src/ir-to-client-js/source-map.ts +2 -1
  154. package/src/ir-to-client-js/stringify/declaration-emit.ts +14 -7
  155. package/src/ir-to-client-js/types.ts +4 -0
  156. package/src/ir-to-client-js/utils.ts +89 -7
  157. package/src/jsx-to-ir.ts +772 -50
  158. package/src/opaque-local-accessor.ts +44 -0
  159. package/src/rich-type-refusal.ts +1 -1
  160. package/src/signal-initializer.ts +36 -0
  161. package/src/template-position-walk.ts +203 -0
  162. package/src/to-locale-date-lowering.ts +7 -4
  163. package/src/types.ts +103 -15
  164. package/dist/format-date-lowering.d.ts +0 -30
  165. package/dist/format-date-lowering.d.ts.map +0 -1
  166. package/src/__tests__/create-selector.test.ts +0 -124
  167. package/src/__tests__/format-date-lowering.test.ts +0 -125
  168. package/src/format-date-lowering.ts +0 -55
@@ -9,6 +9,7 @@
9
9
 
10
10
  import type { ConstantInfo, FunctionInfo, MemoInfo, ReferencesGraph, SignalInfo } from '../types.ts'
11
11
  import { graphDeclarationReferences } from './build-references.ts'
12
+ import { signalSecondBinding } from '../signal-initializer.ts'
12
13
 
13
14
  // =============================================================================
14
15
  // Declaration types
@@ -22,14 +23,17 @@ export type Declaration =
22
23
 
23
24
  /**
24
25
  * Return the names defined by a declaration.
25
- * Signals define both getter and setter names.
26
+ * Signals define both getter and setter names (an async factory's second
27
+ * binding is its action, #3165).
26
28
  */
27
29
  export function providedNames(decl: Declaration): string[] {
28
30
  switch (decl.kind) {
29
31
  case 'constant':
30
32
  return [decl.info.name]
31
- case 'signal':
32
- return decl.info.setter ? [decl.info.getter, decl.info.setter] : [decl.info.getter]
33
+ case 'signal': {
34
+ const second = signalSecondBinding(decl.info)
35
+ return second ? [decl.info.getter, second] : [decl.info.getter]
36
+ }
33
37
  case 'memo':
34
38
  return [decl.info.name]
35
39
  case 'function':
@@ -26,6 +26,7 @@ import {
26
26
  collectUserDomImports,
27
27
  detectUsedImports,
28
28
  } from './imports.ts'
29
+ import { signalFactoryInitializer, signalSecondBinding } from '../signal-initializer.ts'
29
30
 
30
31
  /**
31
32
  * Build the module-level code block that replaces `MODULE_CONSTANTS_PLACEHOLDER`.
@@ -70,13 +71,15 @@ export function emitModuleLevelDeclarations(
70
71
  }
71
72
  for (const signal of moduleLevelSignals) {
72
73
  const tupleVar = `__bf_m_${signal.getter}_tuple`
74
+ const initializer = signalFactoryInitializer(signal) ?? `createSignal(${signal.initialValue})`
75
+ const second = signalSecondBinding(signal)
73
76
  if (signal.isExported) {
74
- lines.push(`export const [${signal.getter}${signal.setter ? `, ${signal.setter}` : ''}] = createSignal(${signal.initialValue})`)
77
+ lines.push(`export const [${signal.getter}${second ? `, ${second}` : ''}] = ${initializer}`)
75
78
  } else {
76
- lines.push(`var ${tupleVar} = ${tupleVar} ?? createSignal(${signal.initialValue})`)
79
+ lines.push(`var ${tupleVar} = ${tupleVar} ?? ${initializer}`)
77
80
  lines.push(`var ${signal.getter} = ${tupleVar}[0]`)
78
- if (signal.setter) {
79
- lines.push(`var ${signal.setter} = ${tupleVar}[1]`)
81
+ if (second) {
82
+ lines.push(`var ${second} = ${tupleVar}[1]`)
80
83
  }
81
84
  }
82
85
  }
@@ -47,6 +47,25 @@ function bindingIdArg(ctx: ClientJsContext, slotId: string | undefined): string
47
47
  * hazard for anything that duck-types form controls via `'value' in el`
48
48
  * (#2716).
49
49
  *
50
+ * A single-selection `<select>` gets one more step (#3066,
51
+ * `select-out-of-range-selected-index`): if the assigned value matches no
52
+ * `<option>`, the browser resolves `select.value = __val` to no selection
53
+ * at all (`selectedIndex` -1) — but #2852 made SSR select a hidden
54
+ * placeholder `<option value="">` (`selectedIndex` 0) for exactly this
55
+ * case. Falling back to `selectedIndex = 0` here keeps the live post-
56
+ * hydration state equal to what SSR already rendered, instead of the two
57
+ * legs agreeing only visually (both blank) while their actual selection
58
+ * state diverges. `!target.multiple && target.size <= 1` excludes list
59
+ * boxes — mirroring `jsx-to-ir.ts`'s `isMultiSelection`, which skips the
60
+ * SSR placeholder for EITHER `multiple` OR a `size` > 1 (a `<select
61
+ * size={2}>` is a list box even without the `multiple` attribute): an
62
+ * unmatched value already leaves a `multiple`/`size>1` select with nothing
63
+ * selected on both legs (see `select-multiple-value-no-match-ssr`'s
64
+ * docstring), so there is no placeholder to reconcile against there and
65
+ * forcing a selection would be a behavior change of its own — checking
66
+ * `multiple` alone would wrongly force `selectedIndex = 0` on a bare
67
+ * `size={2}` select whose SSR leg (correctly) left nothing selected.
68
+ *
50
69
  * NOT for the child-component-root `value` MIRROR (`emitReactivePropBindings`
51
70
  * / `emitReactiveChildProps` reflecting a named prop onto a child's root
52
71
  * element) — that mechanism has no SSR-rendered counterpart at all
@@ -56,7 +75,7 @@ function bindingIdArg(ctx: ClientJsContext, slotId: string | undefined): string
56
75
  function emitValueUpdateStatements(target: string, expression: string): string[] {
57
76
  return [
58
77
  `const __val = String(${expression})`,
59
- `if ('value' in ${target}) { if (${target}.value !== __val) ${target}.value = __val } else { ${target}.setAttribute('value', __val) }`,
78
+ `if ('value' in ${target}) { if (${target}.value !== __val) { ${target}.value = __val; if (${target}.tagName === 'SELECT' && !${target}.multiple && ${target}.size <= 1 && ${target}.value !== __val) ${target}.selectedIndex = 0 } } else { ${target}.setAttribute('value', __val) }`,
60
79
  ]
61
80
  }
62
81
 
@@ -89,8 +108,41 @@ function emitChildValueMirrorStatements(target: string, expression: string): str
89
108
  *
90
109
  * Per-kind WRITE dispatch only — an effect body must never call this
91
110
  * directly, only through `emitDedupedAttrUpdate` below (#2869).
111
+ *
112
+ * `mirrorSeed` (child-prop-mirror-attr-ssr): set only by the two
113
+ * CHILD-ROOT MIRROR callers (`emitReactivePropBindings` /
114
+ * `emitReactiveChildProps`) writing a parent-passed named prop onto a
115
+ * child component's root element, never for an element's OWN attribute
116
+ * binding. Unlike a developer-authored attribute on an element the
117
+ * compiler controls, this mirror has no way to know whether the CHILD
118
+ * actually renders `attrName` at all — the child may consume the prop as
119
+ * text, a class token, or not render it anywhere, in which case SSR never
120
+ * emits the attribute and an unconditional write here would plant one
121
+ * hydration alone created (the exact defect `child-prop-mirror-attr-ssr`
122
+ * tracked). So the generic/presence branches gate on whether the child's
123
+ * OWN render (SSR markup, or the child's own template on a client mount)
124
+ * put the attribute there — never CREATING an attribute SSR wouldn't have.
125
+ *
126
+ * The answer is read from the DOM ONCE, on the effect's first run, and
127
+ * remembered in the caller's `MIRROR_SEED_STORE_DECL` slot
128
+ * (`__m[i] ??= target.hasAttribute(name)`), never re-read: this branch's
129
+ * own `removeAttribute` (value went `null`) is what would flip a live
130
+ * `hasAttribute` read to `false`, and a live gate would then ratchet a
131
+ * one-time removal into a permanent stop — a forwarded prop that goes
132
+ * `null` and back would never be re-applied. Seeding once keeps the
133
+ * decision about the CHILD, not about the mirror's own last write.
134
+ * `class`/`value`/boolean stay ungated: `class` mirrors an established,
135
+ * separately-relied-on forwarding convention (icon components), and
136
+ * `value`/boolean already have their own no-SSR-fallback handling
137
+ * (`emitChildValueMirrorStatements`, #2716) this flag doesn't touch.
92
138
  */
93
- export function emitAttrUpdate(target: string, attrName: string, expression: string, meta: AttrMeta): string[] {
139
+ export function emitAttrUpdate(
140
+ target: string,
141
+ attrName: string,
142
+ expression: string,
143
+ meta: AttrMeta,
144
+ mirrorSeed: MirrorSeed | null = null,
145
+ ): string[] {
94
146
  const htmlName = toHtmlAttrName(attrName)
95
147
  if (attrName === 'dangerouslySetInnerHTML' || htmlName === 'dangerouslySetInnerHTML') {
96
148
  // `{ __html }` is not an attribute — it replaces the element's content.
@@ -115,16 +167,39 @@ export function emitAttrUpdate(target: string, attrName: string, expression: str
115
167
  return emitValueUpdateStatements(target, expression)
116
168
  }
117
169
  if (isBooleanAttr(htmlName)) {
170
+ // CHILD-ROOT MIRROR case (`mirrorSeed` set): same reasoning as the
171
+ // `presenceOrUndefined`/generic branches below — a boolean-IDL name
172
+ // like `open`/`checked` is only a REAL property on the elements that
173
+ // natively expose it (`<details>`, `<dialog>`, form controls); the
174
+ // compiler can't know whether the CHILD's own root is one of those or
175
+ // an ordinary `<div>` that merely happens to receive a prop sharing
176
+ // that name. An unconditional `target.open = …` plants a live DOM
177
+ // property SSR never had (and never reflects to a visible attribute
178
+ // on a plain element), so gate it the same way: seed once from
179
+ // whether the child's OWN render already put the attribute there.
180
+ if (mirrorSeed) {
181
+ return [`if (${mirrorSeedGate(mirrorSeed, target, htmlName)}) ${target}.${htmlName} = !!(${expression})`]
182
+ }
118
183
  return [`${target}.${htmlName} = !!(${expression})`]
119
184
  }
120
185
  if (meta.presenceOrUndefined) {
121
186
  // aria-* requires explicit "true" value per WAI-ARIA spec
122
187
  const attrVal = htmlName.startsWith('aria-') ? 'true' : ''
188
+ if (mirrorSeed) {
189
+ return [
190
+ `if (${mirrorSeedGate(mirrorSeed, target, htmlName)}) { if (${expression}) ${target}.setAttribute('${htmlName}', '${attrVal}'); else ${target}.removeAttribute('${htmlName}') }`,
191
+ ]
192
+ }
123
193
  return [
124
194
  `if (${expression}) ${target}.setAttribute('${htmlName}', '${attrVal}')`,
125
195
  `else ${target}.removeAttribute('${htmlName}')`,
126
196
  ]
127
197
  }
198
+ if (mirrorSeed) {
199
+ return [
200
+ `if (${mirrorSeedGate(mirrorSeed, target, htmlName)}) { const __v = ${expression}; if (__v != null) ${target}.setAttribute('${htmlName}', String(__v)); else ${target}.removeAttribute('${htmlName}') }`,
201
+ ]
202
+ }
128
203
  return [
129
204
  `{ const __v = ${expression}; if (__v != null) ${target}.setAttribute('${htmlName}', String(__v)); else ${target}.removeAttribute('${htmlName}') }`,
130
205
  ]
@@ -144,6 +219,27 @@ export function emitAttrUpdate(target: string, attrName: string, expression: str
144
219
  */
145
220
  export const DEDUP_STORE_DECL = 'const __l = []'
146
221
 
222
+ /**
223
+ * Per-effect store for the child-root mirror's seeded presence answers
224
+ * (`emitAttrUpdate`'s `mirrorSeed`) — `const __m = []`, declared once in
225
+ * the block that creates the mirror effect, indexed by the prop's ordinal
226
+ * within that effect.
227
+ */
228
+ export const MIRROR_SEED_STORE_DECL = 'const __m = []'
229
+
230
+ /** Where one mirrored prop keeps its seeded "does the child render this attribute?" answer. */
231
+ export interface MirrorSeed {
232
+ /** The store variable declared by `MIRROR_SEED_STORE_DECL` in the enclosing block. */
233
+ store: string
234
+ /** This prop's slot in that store — unique within the effect. */
235
+ index: number
236
+ }
237
+
238
+ /** The seeded gate: read `hasAttribute` on the first run only, then reuse the answer. */
239
+ function mirrorSeedGate(seed: MirrorSeed, target: string, htmlName: string): string {
240
+ return `${seed.store}[${seed.index}] ??= ${target}.hasAttribute('${htmlName}')`
241
+ }
242
+
147
243
  /**
148
244
  * `__l`-backed dedup test. `in` (not a truthiness check) so a legitimately
149
245
  * `undefined` value still records and still writes once; `!(N in __l)` on
@@ -191,8 +287,9 @@ export function emitDedupedAttrUpdate(
191
287
  meta: AttrMeta,
192
288
  ordinal: number,
193
289
  guard: string | null = dedupGuard(ordinal),
290
+ mirrorSeed: MirrorSeed | null = null,
194
291
  ): string[] {
195
- const write = emitAttrUpdate(target, attrName, '__x', meta)
292
+ const write = emitAttrUpdate(target, attrName, '__x', meta, mirrorSeed)
196
293
  const lines = [`{ const __x = ${expression}`]
197
294
  if (guard) {
198
295
  lines.push(`if (${guard}) {`)
@@ -602,7 +699,22 @@ export function emitReactivePropBindings(lines: string[], ctx: ClientJsContext):
602
699
  if (ctx.reactiveProps.length > 0) {
603
700
  lines.push('')
604
701
  lines.push(` // Reactive prop bindings`)
702
+ // The generic named-prop mirror AND the boolean-IDL mirror below both
703
+ // seed their presence answer once per prop (`emitAttrUpdate`'s
704
+ // `mirrorSeed`) — same CHILD-ROOT MIRROR reasoning `emitAttrUpdate`'s
705
+ // docstring gives for `emitReactiveChildProps`'s identical boolean
706
+ // branch: the compiler can't know whether this slot's root is one of
707
+ // the elements that natively expose e.g. `open`/`checked`, so an
708
+ // unconditional `target.open = …` here would plant a live DOM property
709
+ // SSR never rendered (`child-prop-mirror-attr-ssr`). The store is
710
+ // declared only when some prop takes one of those two paths, so
711
+ // effects made of `selected` / `value` mirrors alone keep their shape.
712
+ const usesMirrorSeed = (prop: ClientJsContext['reactiveProps'][number]): boolean =>
713
+ prop.propName !== 'selected' && prop.propName !== 'value'
714
+ const needsSeedStore = ctx.reactiveProps.some(usesMirrorSeed)
715
+ if (needsSeedStore) lines.push(` { ${MIRROR_SEED_STORE_DECL}`)
605
716
  lines.push(` createEffect(() => {`)
717
+ let seedIndex = 0
606
718
 
607
719
  const propsBySlot = new Map<string, typeof ctx.reactiveProps>()
608
720
  for (const prop of ctx.reactiveProps) {
@@ -646,16 +758,27 @@ export function emitReactivePropBindings(lines: string[], ctx: ClientJsContext):
646
758
  // truthy, so setAttribute('disabled', 'false') still disables the element.
647
759
  } else if (prop.propName === 'value') {
648
760
  for (const stmt of emitChildValueMirrorStatements(ref, value)) lines.push(` ${stmt}`)
649
- } else if (isBooleanAttr(prop.propName)) {
650
- lines.push(` ${ref}.${prop.propName} = !!(${value})`)
651
761
  } else {
652
- lines.push(` ${ref}.setAttribute('${prop.propName}', String(${value}))`)
762
+ // Generic AND boolean-IDL named-prop mirror alike
763
+ // (child-prop-mirror-attr-ssr): `mirrorSeed` restricts the write
764
+ // to when the child's OWN render already put the
765
+ // `${prop.propName}` attribute on `ref` — see `emitAttrUpdate`'s
766
+ // docstring, which dispatches boolean-IDL names (`open`,
767
+ // `checked`, …) to its own gated branch internally. Routed
768
+ // through the shared dispatcher instead of a hand-rolled
769
+ // `target.x = !!(...)` / `setAttribute` so this and
770
+ // `emitReactiveChildProps`'s identical mirror share one
771
+ // implementation of the gate — a second hand-rolled boolean
772
+ // write here previously bypassed it entirely
773
+ // (child-prop-mirror-attr-ssr reopened via this parallel path).
774
+ const seed: MirrorSeed = { store: '__m', index: seedIndex++ }
775
+ for (const stmt of emitAttrUpdate(ref, prop.propName, value, {}, seed)) lines.push(` ${stmt}`)
653
776
  }
654
777
  }
655
778
  lines.push(` }`)
656
779
  }
657
780
 
658
- lines.push(` }${bindingIdArg(ctx, ctx.reactiveProps[0]?.slotId)})`)
781
+ lines.push(` }${bindingIdArg(ctx, ctx.reactiveProps[0]?.slotId)})${needsSeedStore ? ' }' : ''}`)
659
782
  }
660
783
  }
661
784
 
@@ -664,7 +787,7 @@ export function emitReactiveChildProps(lines: string[], ctx: ClientJsContext): v
664
787
  if (ctx.reactiveChildProps.length > 0) {
665
788
  lines.push('')
666
789
  lines.push(` // Reactive child component props`)
667
- lines.push(` { ${DEDUP_STORE_DECL}`)
790
+ lines.push(` { ${DEDUP_STORE_DECL}; ${MIRROR_SEED_STORE_DECL}`)
668
791
  lines.push(` createEffect(() => {`)
669
792
 
670
793
  const propsByComponent = new Map<string, typeof ctx.reactiveChildProps>()
@@ -697,9 +820,16 @@ export function emitReactiveChildProps(lines: string[], ctx: ClientJsContext): v
697
820
  // of `emitAttrUpdate`'s generic (attribute-fallback) dispatch;
698
821
  // see `emitChildValueMirrorStatements`'s docstring (#2716). It has
699
822
  // its own DOM-compare and consumes no dedup ordinal (#2869).
700
- const stmts = toHtmlAttrName(prop.attrName) === 'value'
823
+ // `mirrorSeed` (child-prop-mirror-attr-ssr) — this is the
824
+ // CHILD-ROOT MIRROR, not an element's own attribute binding; see
825
+ // `emitAttrUpdate`'s docstring for why only the generic/presence
826
+ // branches gate on the child's rendered attribute, seeded once.
827
+ // The dedup ordinal doubles as the seed slot: unique per prop here.
828
+ const isValueMirror = toHtmlAttrName(prop.attrName) === 'value'
829
+ const stmts = isValueMirror
701
830
  ? emitChildValueMirrorStatements(varName, prop.expression)
702
- : emitDedupedAttrUpdate(varName, prop.attrName, prop.expression, prop, ordinal++)
831
+ : emitDedupedAttrUpdate(varName, prop.attrName, prop.expression, prop, ordinal, dedupGuard(ordinal), { store: '__m', index: ordinal })
832
+ if (!isValueMirror) ordinal++
703
833
  for (const stmt of stmts) {
704
834
  lines.push(` ${stmt}`)
705
835
  }
@@ -4,9 +4,9 @@
4
4
  * and the final hydrate() call emission.
5
5
  */
6
6
 
7
- import type { ComponentIR, IRFragment, IRNode, ReferencesGraph, SignalInfo } from '../types.ts'
7
+ import type { ComponentIR, IRNode, ReferencesGraph, SignalInfo } from '../types.ts'
8
8
  import type { ClientJsContext } from './types.ts'
9
- import { PROPS_PARAM, isCommentScopedRoot } from './utils.ts'
9
+ import { PROPS_PARAM, componentDefScopeFlags, initFunctionName } from './utils.ts'
10
10
  import { computeInlinability, toLegacyInlinability } from './compute-inlinability.ts'
11
11
  import { canGenerateStaticTemplate, irToComponentTemplate, generateCsrTemplate, createStringProtector } from './html-template.ts'
12
12
  import { markupSlotIdsOf } from './markup-slots.ts'
@@ -214,11 +214,11 @@ export function emitRegistrationAndHydration(
214
214
  // ITS OWN real scope id — the wrapping comment marks a scope with no
215
215
  // DOM presence of its own, and `materializeComponent` must leave
216
216
  // `scopeId` null so it doesn't stamp over (or duplicate) the child's.
217
- const isFragmentRoot = _ir.root.type === 'fragment' && !!(_ir.root as IRFragment).needsScopeComment
218
- const isCommentScope = isCommentScopedRoot(_ir.root)
217
+ // Both flags come from `componentDefScopeFlags` (utils.ts), shared with
218
+ // the template-only registration path (`generateTemplateOnlyMount`).
219
219
 
220
220
  // Build ComponentDef object for hydrate()
221
- const defParts: string[] = [`init: init${name}`]
221
+ const defParts: string[] = [`init: ${initFunctionName(name)}`]
222
222
  if (canGenerateStaticTemplate(_ir.root, propNamesForStaticCheck, inlinableConstants, unsafeLocalNames)) {
223
223
  const markupSlotIds = markupSlotIdsOf(ctx)
224
224
  const templateHtml = irToComponentTemplate(_ir.root, inlinableConstants, restSpreadNames, ctx.propsObjectName, markupSlotIds, ctx.restPropsName)
@@ -243,12 +243,7 @@ export function emitRegistrationAndHydration(
243
243
  }
244
244
  }
245
245
  // No else: top-level-only components skip template entirely (save bytes)
246
- if (isCommentScope) {
247
- defParts.push('comment: true')
248
- }
249
- if (isFragmentRoot) {
250
- defParts.push('fragmentRoot: true')
251
- }
246
+ defParts.push(...componentDefScopeFlags(_ir.root))
252
247
 
253
248
  const registryKey = nameForRegistryRef(name)
254
249
  // When the registry key was file-scoped (`Name__<8hex>`, for a
@@ -10,7 +10,7 @@
10
10
 
11
11
  import type { ComponentIR } from '../types.ts'
12
12
  import type { ClientJsContext } from './types.ts'
13
- import { PROPS_PARAM, isCommentScopedRoot } from './utils.ts'
13
+ import { PROPS_PARAM, isCommentScopedRoot, initFunctionName } from './utils.ts'
14
14
  import { buildReferencesGraph } from './build-references.ts'
15
15
  import { computePropUsage } from './compute-prop-usage.ts'
16
16
  import { IMPORT_PLACEHOLDER, MODULE_CONSTANTS_PLACEHOLDER } from './imports.ts'
@@ -40,7 +40,7 @@ export function generateInitFunction(
40
40
  emitChildComponentImports(lines, ctx, new Set(siblingComponents || []))
41
41
  lines.push('')
42
42
  lines.push(MODULE_CONSTANTS_PLACEHOLDER)
43
- lines.push(`export function init${name}(__scope, ${PROPS_PARAM} = {}) {`)
43
+ lines.push(`export function ${initFunctionName(name)}(__scope, ${PROPS_PARAM} = {}) {`)
44
44
  lines.push(` if (!__scope) return`)
45
45
  // Host scope id for (bf-h, bf-m) child lookups inside this init body
46
46
  // (#1249). Compile-time selectors emit
@@ -11,12 +11,13 @@ import { assertNever } from './walker.ts'
11
11
  import { buildSignalMemoEnv, csrSubstitute, type CsrEnv } from './csr-substitute.ts'
12
12
  import { rewritePropsObjectRef } from './rewrite-props-object.ts'
13
13
  import type { ClientJsContext } from './types.ts'
14
- import { BF_PARENT_SCOPE_PLACEHOLDER, BF_SCOPE, classifyDOMProp, escapeHtml } from '@barefootjs/shared'
14
+ import { BF_KEY, BF_PARENT_SCOPE_PLACEHOLDER, BF_SCOPE, classifyDOMProp, escapeHtml } from '@barefootjs/shared'
15
15
  import { buildLoopChainExpr } from '../loop-chain.ts'
16
16
  import { renderChildScopeArgs } from '../adapters/child-scope.ts'
17
17
  import { BindingScope } from '../scope/binding-scope.ts'
18
18
  import { interp, spliceChildValue, conditionalMarkup, renderChildCall, mappedRowsMarkup, dangerousInnerHtml, EMPTY_MARKUP } from './safe-html.ts'
19
19
  import { markupSlotIdsOf } from './markup-slots.ts'
20
+ import { isEventHandlerName } from '../event-handler-name.ts'
20
21
 
21
22
  /**
22
23
  * Protect string literals from regex-based replacements.
@@ -644,10 +645,30 @@ export function flatMapLeafKeyExpr(ir: IRNode): string | null {
644
645
  }
645
646
  }
646
647
 
647
- /** Copy of `ir` with the loop `key` attribute removed (element leaves only). */
648
- function stripLeafKeyAttr(ir: IRNode): IRNode {
648
+ /**
649
+ * Copy of `ir` with the loop `key` attribute replaced by the reconciliation
650
+ * attribute the runtime keys on: `data-key={String(<key>)}` (element leaves
651
+ * only; a keyless leaf just loses nothing). This is the one client-side
652
+ * rendering of a flatMap leaf's key — the hydrate template, the CSR
653
+ * descriptor and the module-scope template all go through it — and it
654
+ * mirrors what SSR emits from the rawBody (`flatMapRawBodyWithLeafKeys`,
655
+ * jsx-to-ir.ts) and what `mapArray` stamps on adoption/creation (`BF_KEY`;
656
+ * the descriptor path never passes a depth-suffixed name), so every
657
+ * construction path agrees on the attribute. Rendered as an ordinary
658
+ * expression attribute, so it is escaped like one.
659
+ */
660
+ function leafKeyAsDataKeyAttr(ir: IRNode): IRNode {
649
661
  if (ir.type !== 'element') return ir
650
- return { ...ir, attrs: ir.attrs.filter((a) => a.name !== 'key') }
662
+ const keyExpr = flatMapLeafKeyExpr(ir)
663
+ if (keyExpr === null) return { ...ir, attrs: ir.attrs.filter((a) => a.name !== 'key') }
664
+ // In place, not appended: SSR splices `data-key` at the `key` attribute's
665
+ // position, so the attribute order matches byte-for-byte.
666
+ return {
667
+ ...ir,
668
+ attrs: ir.attrs.map((a) =>
669
+ a.name === 'key' ? { ...a, name: BF_KEY, value: { kind: 'expression' as const, expr: `String(${keyExpr})` } } : a,
670
+ ),
671
+ }
651
672
  }
652
673
 
653
674
  /**
@@ -675,7 +696,7 @@ export function renderFlatMapClientBody(
675
696
  rawLeaf: true,
676
697
  renderLeaf: (ir) => {
677
698
  const key = flatMapLeafKeyExpr(ir)
678
- const html = irToHtmlTemplate(stripLeafKeyAttr(ir), restSpreadNames, 1, undefined, undefined)
699
+ const html = irToHtmlTemplate(leafKeyAsDataKeyAttr(ir), restSpreadNames, 1, undefined, undefined)
679
700
  return `({ k: ${key ?? 'undefined'}, h: \`${html}\` })`
680
701
  },
681
702
  })
@@ -871,7 +892,7 @@ export function irToHtmlTemplate(node: IRNode, restSpreadNames?: ReadonlySet<str
871
892
  // during module-scope string rendering, and a ref closing over an
872
893
  // init-scope setter would leak it into the template (#2468). The
873
894
  // init path re-applies refs once real DOM exists.
874
- .filter(p => p.name !== 'ref' && !(p.name.startsWith('on') && p.name.length > 2 && p.name[2] === p.name[2].toUpperCase()))
895
+ .filter(p => p.name !== 'ref' && !(isEventHandlerName(p.name)))
875
896
  .map(p => {
876
897
  // `/* @client */` defers the prop to hydrate via initChild.
877
898
  if (p.clientOnly) return null
@@ -974,12 +995,13 @@ export function irToHtmlTemplate(node: IRNode, restSpreadNames?: ReadonlySet<str
974
995
  if (node.flatMapCallback) {
975
996
  // Complex flatMap: the body is structured segments, rendered through
976
997
  // the same single door as map preambles.
977
- // Leaf `key` is stripped from the string form: SSR (Hono rawBody)
978
- // never emits data-key for flatMap leaves, and reconciliation
979
- // identity is stamped by mapArray via setAttribute — emitting it
980
- // here was the CSR/SSR data-key asymmetry (unescaped, client-only).
998
+ // The leaf `key` renders as `data-key={String(<key>)}` here, in the
999
+ // CSR descriptor (`renderFlatMapClientBody`) and in the SSR rawBody
1000
+ // (`flatMapRawBodyWithLeafKeys`, jsx-to-ir.ts) alike — the attribute
1001
+ // `mapArray` stamps on adoption/creation, so SSR, hydrate template and
1002
+ // csr-mount agree on it (see `leafKeyAsDataKeyAttr`).
981
1003
  const body = renderPreamble(node.flatMapCallback, {
982
- renderLeaf: (ir) => irToHtmlTemplate(stripLeafKeyAttr(ir), restSpreadNames, loopDepth + 1, loopParams, branchSlotsVar),
1004
+ renderLeaf: (ir) => irToHtmlTemplate(leafKeyAsDataKeyAttr(ir), restSpreadNames, loopDepth + 1, loopParams, branchSlotsVar),
983
1005
  })
984
1006
  mapExpr = interp(mappedRowsMarkup(wrappedArray, 'flatMap', node.flatMapCallback.params, body))
985
1007
  } else if (node.preamble) {
@@ -1445,8 +1467,8 @@ export function irToPlaceholderTemplate(node: IRNode, restSpreadNames?: Readonly
1445
1467
  let mapExpr: string
1446
1468
  if (node.flatMapCallback) {
1447
1469
  const body = renderPreamble(node.flatMapCallback, {
1448
- // Leaf `key` stripped — see the irToHtmlTemplate site above.
1449
- renderLeaf: (ir) => irToPlaceholderTemplate(stripLeafKeyAttr(ir), restSpreadNames, loopDepth + 1, loopParams),
1470
+ // Leaf `key` → `data-key` — see the irToHtmlTemplate site above.
1471
+ renderLeaf: (ir) => irToPlaceholderTemplate(leafKeyAsDataKeyAttr(ir), restSpreadNames, loopDepth + 1, loopParams),
1450
1472
  })
1451
1473
  mapExpr = interp(mappedRowsMarkup(wrappedArray, 'flatMap', node.flatMapCallback.params, body))
1452
1474
  } else if (node.preamble) {
@@ -1537,7 +1559,7 @@ function irNodeToJsExprs(node: IRNode, brandMarkup = false): string[] {
1537
1559
  const propsEntries: string[] = node.props
1538
1560
  .filter(p => p.name !== 'key' && p.name !== '...' && !p.name.startsWith('...'))
1539
1561
  .map(p => {
1540
- if (p.name.startsWith('on') && p.name.length > 2 && p.name[2] === p.name[2].toUpperCase()) {
1562
+ if (isEventHandlerName(p.name)) {
1541
1563
  return `${quotePropName(p.name)}: ${attrValueToString(p.value) ?? 'undefined'}`
1542
1564
  }
1543
1565
  switch (p.value.kind) {
@@ -2020,7 +2042,7 @@ function irToComponentTemplateWithOpts(node: IRNode, opts: TemplateOptions): str
2020
2042
  // during module-scope string rendering, and a ref closing over an
2021
2043
  // init-scope setter would leak it into the template (#2468). The
2022
2044
  // init path re-applies refs once real DOM exists.
2023
- .filter(p => p.name !== 'ref' && !(p.name.startsWith('on') && p.name.length > 2 && p.name[2] === p.name[2].toUpperCase()))
2045
+ .filter(p => p.name !== 'ref' && !(isEventHandlerName(p.name)))
2024
2046
  .map(p => {
2025
2047
  // `/* @client */` defers the prop to hydrate via initChild.
2026
2048
  if (p.clientOnly) return null
@@ -2401,7 +2423,7 @@ export function computeDeferredChildSlots(
2401
2423
  // `component` emit below so the deferral decision matches output.
2402
2424
  if (p.name === '...' || p.name.startsWith('...') || p.name === 'key') return false
2403
2425
  if (p.name === 'ref') return false
2404
- if (p.name.startsWith('on') && p.name.length > 2 && p.name[2] === p.name[2].toUpperCase()) return false
2426
+ if (isEventHandlerName(p.name)) return false
2405
2427
  if (p.clientOnly) return false
2406
2428
  return propResolvesUnsafe(p, env, unsafeLocalNames)
2407
2429
  })
@@ -2671,7 +2693,7 @@ function generateCsrTemplateWithOpts(node: IRNode, opts: TemplateOptions): strin
2671
2693
  // during module-scope string rendering, and a ref closing over an
2672
2694
  // init-scope setter would leak it into the template (#2468). The
2673
2695
  // init path re-applies refs once real DOM exists.
2674
- .filter(p => p.name !== 'ref' && !(p.name.startsWith('on') && p.name.length > 2 && p.name[2] === p.name[2].toUpperCase()))
2696
+ .filter(p => p.name !== 'ref' && !(isEventHandlerName(p.name)))
2675
2697
  .map(p => {
2676
2698
  // `/* @client */` defers the prop to hydrate. Drop from the
2677
2699
  // SSR `renderChild` props — `initChild`'s `propsExpr` getter
@@ -2791,8 +2813,8 @@ function generateCsrTemplateWithOpts(node: IRNode, opts: TemplateOptions): strin
2791
2813
  const body = renderPreamble(node.flatMapCallback, {
2792
2814
  textVariant: 'template',
2793
2815
  transformJs: (t) => rewritePropsObjectRef(t, propsObjectName ?? null, restPropsName ?? null, { enclosingScope: childScope }),
2794
- // Leaf `key` stripped — see the irToHtmlTemplate site above.
2795
- renderLeaf: (ir) => recurseInLoopBody(stripLeafKeyAttr(ir)),
2816
+ // Leaf `key` → `data-key` — see the irToHtmlTemplate site above.
2817
+ renderLeaf: (ir) => recurseInLoopBody(leafKeyAsDataKeyAttr(ir)),
2796
2818
  })
2797
2819
  mapExpr = interp(mappedRowsMarkup(iterArrayExpr, 'flatMap', node.flatMapCallback.params, body))
2798
2820
  } else if (node.preamble) {
@@ -16,7 +16,7 @@ import { buildReferencesGraph, graphUsedIdentifiers } from './build-references.t
16
16
  import { addConstantPropRefsToSet } from './init-declarations.ts'
17
17
  import { canGenerateStaticTemplate, irToComponentTemplate, generateCsrTemplate } from './html-template.ts'
18
18
  import { markupSlotIdsOf } from './markup-slots.ts'
19
- import { PROPS_PARAM } from './utils.ts'
19
+ import { PROPS_PARAM, initFunctionName, componentDefScopeFlags } from './utils.ts'
20
20
  import { buildInlinableConstants, csrInlinableConstantsFromCtx } from './emit-registration.ts'
21
21
  import { buildEnvFromCtx } from './compute-inlinability.ts'
22
22
  import { nameForRegistryRef, buildImportAliasMap, setActiveImportAliases } from './component-scope.ts'
@@ -356,13 +356,19 @@ function generateTemplateOnlyMount(ir: ComponentIR, ctx: ClientJsContext): strin
356
356
 
357
357
  lines.push(IMPORT_PLACEHOLDER)
358
358
  lines.push('')
359
- lines.push(`function init${name}() {}`)
359
+ const initName = initFunctionName(name)
360
+ lines.push(`function ${initName}() {}`)
360
361
  lines.push('')
361
362
  // `name: '...'` only when the key was file-scoped — same reason as in
362
363
  // `emitRegistrationAndHydration`: the hashed key must not reach `bf-s`
363
364
  // (#2518).
364
365
  const nameField = registryKey !== name ? `, name: '${name}'` : ''
365
- lines.push(`hydrate('${registryKey}', { init: init${name}, template: (${PROPS_PARAM}) => \`${templateHtml}\`${nameField} })`)
366
+ // Scope-shape flags from the same helper `emitRegistrationAndHydration`
367
+ // uses — a fragment-rooted stateless child must declare `comment` /
368
+ // `fragmentRoot` too, or `renderChild()` stamps `bf-s` onto its first
369
+ // element while SSR scopes it with a comment pair.
370
+ const scopeFlags = componentDefScopeFlags(ir.root).map((f) => `, ${f}`).join('')
371
+ lines.push(`hydrate('${registryKey}', { init: ${initName}, template: (${PROPS_PARAM}) => \`${templateHtml}\`${scopeFlags}${nameField} })`)
366
372
  // See `emitRegistrationAndHydration` (./emit-registration.ts) for the
367
373
  // rationale on why the component is also emitted as a callable
368
374
  // shim. The same applies for template-only components since they
@@ -16,6 +16,6 @@ export function emitRefCallbacks(
16
16
  for (const elem of ctx.refElements) {
17
17
  if (conditionalSlotIds.has(elem.slotId)) continue
18
18
  const v = varSlotId(elem.slotId)
19
- lines.push(` if (_${v}) ${emitRefCall(elem.callback, `_${v}`)}`)
19
+ lines.push(` if (_${v}) ${emitRefCall(elem.callback, `_${v}`, elem.ssrPortalOwner)}`)
20
20
  }
21
21
  }
@@ -14,7 +14,7 @@ import type { ClientJsContext } from '../types.ts'
14
14
  import type { ParamInfo, SignalInfo } from '../../types.ts'
15
15
  import { inferDefaultValue, PROPS_PARAM } from '../utils.ts'
16
16
  import { livePropReadExpr } from '../../props-binding.ts'
17
- import { ENV_SIGNAL_CLIENT_FACTORY } from '../../adapters/env-signal.ts'
17
+ import { signalFactoryInitializer, signalSecondBinding } from '../../signal-initializer.ts'
18
18
  import type {
19
19
  ControlledSignalEffectPlan,
20
20
  DeclarationEmitPlan,
@@ -87,20 +87,21 @@ function buildSignalPlan(
87
87
  ctx: ClientJsContext,
88
88
  lookups: DeclarationEmitLookups,
89
89
  ): SignalEmitPlan {
90
- if (signal.envReader) {
91
- // Emit the factory as written (alias / namespace aware, #2057), falling back
92
- // to the canonical name if the callee text wasn't captured.
93
- const factory = signal.envFactory ?? ENV_SIGNAL_CLIENT_FACTORY[signal.envReader]
94
- if (factory) {
95
- return {
96
- kind: 'signal',
97
- getter: signal.getter,
98
- setter: signal.setter,
99
- getterElided: signal.getterElided,
100
- initialValueExpr: '',
101
- controlledEffect: null,
102
- initializerOverride: `${factory}()`,
103
- }
90
+ // Env signals (#2057) and async factories (#3165) re-emit their own factory
91
+ // call, as written (alias / namespace aware), instead of `createSignal`.
92
+ const initializerOverride = signalFactoryInitializer(signal)
93
+ if (initializerOverride) {
94
+ return {
95
+ kind: 'signal',
96
+ getter: signal.getter,
97
+ setter: signalSecondBinding(signal),
98
+ getterElided: signal.getterElided,
99
+ initialValueExpr: '',
100
+ controlledEffect: null,
101
+ initializerOverride,
102
+ // An env signal is a stable request-scoped view, emitted unconditionally;
103
+ // an async factory owns a request, so it is created only on its branch.
104
+ branchCondition: signal.factory ? signal.branchCondition : undefined,
104
105
  }
105
106
  }
106
107
  const controlledEffect = buildControlledSignalEffect(signal, lookups)
@@ -62,11 +62,13 @@ export interface SignalEmitPlan {
62
62
  bfId?: string
63
63
  /**
64
64
  * When set, the full initializer expression to emit verbatim instead of
65
- * `createSignal(<initialValueExpr>)`. Env signals (#2057) emit their own
66
- * factory call — e.g. `createSearchParams()` — with no baked initial value,
67
- * profile id, controlled effect, or branch condition (the tuple is a stable
68
- * request-scoped view, not stored state). When present the stringifier emits
69
- * `const [<getter>, <setter>] = <initializerOverride>` and nothing else.
65
+ * `createSignal(<initialValueExpr>)`. Env signals (#2057) and async
66
+ * factories (#3165) emit their own factory call — e.g.
67
+ * `createSearchParams()`, `createQuery(fn, options)` — with no baked initial
68
+ * value, profile id, or controlled effect; `setter` then holds the tuple's
69
+ * second binding (an async factory's action). When present the stringifier
70
+ * emits `const [<getter>, <setter>] = <initializerOverride>` (or the
71
+ * `branchCondition` form, which only an async factory sets) and nothing else.
70
72
  */
71
73
  initializerOverride?: string
72
74
  }
@@ -189,6 +189,10 @@ export function getControlledPropName(
189
189
  propsParams: ParamInfo[],
190
190
  propsObjectName: string | null = null
191
191
  ): string | null {
192
+ // An async factory's value (`createQuery(fn, { initial: props.posts })`,
193
+ // #3165) takes `initial` once; later values come from its own requests, so
194
+ // it is never re-synced from the prop.
195
+ if (signal.factory) return null
192
196
  const initialValue = signal.initialValue.trim()
193
197
  const isDefaultProp = (propName: string) => propName.startsWith('default')
194
198
  // Use the source-level props name for pattern matching (not the generated PROPS_PARAM)