@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.
- package/dist/action-accessor.d.ts +159 -0
- package/dist/action-accessor.d.ts.map +1 -0
- package/dist/adapters/env-signal.d.ts +0 -8
- package/dist/adapters/env-signal.d.ts.map +1 -1
- package/dist/adapters/interface.d.ts +12 -0
- package/dist/adapters/interface.d.ts.map +1 -1
- package/dist/adapters/jsx-adapter.d.ts.map +1 -1
- package/dist/analyzer.d.ts +61 -1
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/async-action-refusal.d.ts +45 -0
- package/dist/async-action-refusal.d.ts.map +1 -0
- package/dist/builtin-lowering-plugins.d.ts.map +1 -1
- package/dist/compiler.d.ts.map +1 -1
- package/dist/component-root-scope-comment.d.ts +36 -0
- package/dist/component-root-scope-comment.d.ts.map +1 -0
- package/dist/debug.d.ts +61 -5
- package/dist/debug.d.ts.map +1 -1
- package/dist/errors.d.ts +7 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/event-handler-name.d.ts +13 -0
- package/dist/event-handler-name.d.ts.map +1 -0
- package/dist/expression-parser.d.ts +9 -0
- package/dist/expression-parser.d.ts.map +1 -1
- package/dist/format-date-refusal.d.ts +33 -0
- package/dist/format-date-refusal.d.ts.map +1 -0
- package/dist/index.d.ts +6 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3260 -1914
- package/dist/ir-to-client-js/build-references.d.ts.map +1 -1
- package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
- package/dist/ir-to-client-js/compute-inlinability.d.ts.map +1 -1
- package/dist/ir-to-client-js/compute-scope.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-branch-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-component-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-composite-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-loop-child-arm.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/insert.d.ts +2 -0
- package/dist/ir-to-client-js/control-flow/plan/insert.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/lazy-row-eligibility.d.ts +1 -1
- package/dist/ir-to-client-js/control-flow/plan/loop.d.ts +57 -12
- package/dist/ir-to-client-js/control-flow/plan/loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/shared.d.ts +44 -3
- package/dist/ir-to-client-js/control-flow/shared.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/stringify/component-loop.d.ts +7 -5
- package/dist/ir-to-client-js/control-flow/stringify/component-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/csr-substitute.d.ts.map +1 -1
- package/dist/ir-to-client-js/declaration-sort.d.ts +2 -1
- package/dist/ir-to-client-js/declaration-sort.d.ts.map +1 -1
- package/dist/ir-to-client-js/emit-module-level.d.ts.map +1 -1
- package/dist/ir-to-client-js/emit-reactive.d.ts +43 -2
- package/dist/ir-to-client-js/emit-reactive.d.ts.map +1 -1
- package/dist/ir-to-client-js/emit-registration.d.ts.map +1 -1
- package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
- package/dist/ir-to-client-js/plan/declaration-emit.d.ts +7 -5
- package/dist/ir-to-client-js/plan/declaration-emit.d.ts.map +1 -1
- package/dist/ir-to-client-js/prop-handling.d.ts.map +1 -1
- package/dist/ir-to-client-js/reactivity.d.ts +9 -1
- package/dist/ir-to-client-js/reactivity.d.ts.map +1 -1
- package/dist/ir-to-client-js/source-map.d.ts.map +1 -1
- package/dist/ir-to-client-js/types.d.ts +4 -0
- package/dist/ir-to-client-js/types.d.ts.map +1 -1
- package/dist/ir-to-client-js/utils.d.ts +66 -1
- package/dist/ir-to-client-js/utils.d.ts.map +1 -1
- package/dist/jsx-to-ir.d.ts.map +1 -1
- package/dist/opaque-local-accessor.d.ts +27 -0
- package/dist/opaque-local-accessor.d.ts.map +1 -0
- package/dist/signal-initializer.d.ts +24 -0
- package/dist/signal-initializer.d.ts.map +1 -0
- package/dist/template-position-walk.d.ts +68 -0
- package/dist/template-position-walk.d.ts.map +1 -0
- package/dist/to-locale-date-lowering.d.ts +7 -4
- package/dist/to-locale-date-lowering.d.ts.map +1 -1
- package/dist/types.d.ts +104 -17
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +878 -4528
- package/src/__tests__/action-accessor.test.ts +166 -0
- package/src/__tests__/binding-scope-ratchet.test.ts +21 -10
- package/src/__tests__/branch-local-in-raw-capture.test.ts +1 -1
- package/src/__tests__/branch-local-same-name-collision.test.ts +9 -9
- package/src/__tests__/client-js-generation.test.ts +175 -0
- package/src/__tests__/component-root-scope-comment.test.ts +106 -0
- package/src/__tests__/create-mutation.test.ts +220 -0
- package/src/__tests__/create-query.test.ts +644 -0
- package/src/__tests__/csr-fragment-root-scope-shape.test.ts +156 -0
- package/src/__tests__/debug.test.ts +222 -0
- package/src/__tests__/doc-examples.test.ts +78 -25
- package/src/__tests__/event-handler-name.test.ts +74 -0
- package/src/__tests__/flatmap-segments.test.ts +11 -9
- package/src/__tests__/format-date-refusal.test.ts +134 -0
- package/src/__tests__/fragment-wrapped-conditional-return-branch.test.ts +132 -0
- package/src/__tests__/hydrate-template.test.ts +9 -1
- package/src/__tests__/issue-2798-static-nested-loop-bindings.test.ts +2 -2
- package/src/__tests__/issue-3009-loop-branch-ref.test.ts +2 -2
- package/src/__tests__/issue-3044-nested-prop-object-array-not-static.test.ts +213 -0
- package/src/__tests__/issue-3113-init-fn-name-collision.test.ts +133 -0
- package/src/__tests__/jsx-return-type-assertion.test.ts +2 -2
- package/src/__tests__/lazy-row-eligibility.test.ts +5 -4
- package/src/__tests__/loop-row-child-children-reactive-attrs.test.ts +108 -0
- package/src/__tests__/loop-row-child-text-children-markers.test.ts +158 -0
- package/src/__tests__/opaque-local-accessor.test.ts +90 -0
- package/src/__tests__/profiler-e2e.test.ts +13 -8
- package/src/__tests__/props-destructuring.test.ts +79 -4
- package/src/__tests__/reactive-factory-arity.test.ts +311 -0
- package/src/__tests__/ref-attr-absent-at-ssr.test.ts +472 -0
- package/src/__tests__/ssr-portal-ref-callback.test.ts +219 -0
- package/src/action-accessor.ts +289 -0
- package/src/adapters/env-signal.ts +2 -21
- package/src/adapters/interface.ts +13 -0
- package/src/adapters/jsx-adapter.ts +17 -0
- package/src/analyzer.ts +589 -60
- package/src/async-action-refusal.ts +254 -0
- package/src/builtin-lowering-plugins.ts +0 -2
- package/src/compiler.ts +27 -0
- package/src/component-root-scope-comment.ts +59 -0
- package/src/debug.ts +318 -103
- package/src/errors.ts +83 -1
- package/src/event-handler-name.ts +14 -0
- package/src/expression-parser.ts +41 -17
- package/src/format-date-refusal.ts +147 -0
- package/src/index.ts +14 -3
- package/src/ir-to-client-js/build-references.ts +6 -2
- package/src/ir-to-client-js/child-components.ts +8 -3
- package/src/ir-to-client-js/collect-elements.ts +28 -13
- package/src/ir-to-client-js/compute-inlinability.ts +2 -1
- package/src/ir-to-client-js/compute-scope.ts +3 -1
- package/src/ir-to-client-js/control-flow/plan/build-branch-loop.ts +2 -4
- package/src/ir-to-client-js/control-flow/plan/build-component-loop.ts +67 -5
- package/src/ir-to-client-js/control-flow/plan/build-composite-loop.ts +3 -6
- package/src/ir-to-client-js/control-flow/plan/build-insert.ts +1 -0
- package/src/ir-to-client-js/control-flow/plan/build-loop-child-arm.ts +2 -1
- package/src/ir-to-client-js/control-flow/plan/build-loop.ts +23 -11
- package/src/ir-to-client-js/control-flow/plan/insert.ts +2 -0
- package/src/ir-to-client-js/control-flow/plan/lazy-row-eligibility.ts +3 -3
- package/src/ir-to-client-js/control-flow/plan/loop.ts +51 -10
- package/src/ir-to-client-js/control-flow/shared.ts +78 -5
- package/src/ir-to-client-js/control-flow/stringify/component-loop.ts +25 -12
- package/src/ir-to-client-js/control-flow/stringify/insert.ts +1 -1
- package/src/ir-to-client-js/csr-substitute.ts +11 -3
- package/src/ir-to-client-js/declaration-sort.ts +7 -3
- package/src/ir-to-client-js/emit-module-level.ts +7 -4
- package/src/ir-to-client-js/emit-reactive.ts +140 -10
- package/src/ir-to-client-js/emit-registration.ts +6 -11
- package/src/ir-to-client-js/generate-init.ts +2 -2
- package/src/ir-to-client-js/html-template.ts +41 -19
- package/src/ir-to-client-js/index.ts +9 -3
- package/src/ir-to-client-js/phases/ref-callbacks.ts +1 -1
- package/src/ir-to-client-js/plan/build-declaration-emit.ts +16 -15
- package/src/ir-to-client-js/plan/declaration-emit.ts +7 -5
- package/src/ir-to-client-js/prop-handling.ts +4 -0
- package/src/ir-to-client-js/reactivity.ts +21 -16
- package/src/ir-to-client-js/source-map.ts +2 -1
- package/src/ir-to-client-js/stringify/declaration-emit.ts +14 -7
- package/src/ir-to-client-js/types.ts +4 -0
- package/src/ir-to-client-js/utils.ts +89 -7
- package/src/jsx-to-ir.ts +772 -50
- package/src/opaque-local-accessor.ts +44 -0
- package/src/rich-type-refusal.ts +1 -1
- package/src/signal-initializer.ts +36 -0
- package/src/template-position-walk.ts +203 -0
- package/src/to-locale-date-lowering.ts +7 -4
- package/src/types.ts +103 -15
- package/dist/format-date-lowering.d.ts +0 -30
- package/dist/format-date-lowering.d.ts.map +0 -1
- package/src/__tests__/create-selector.test.ts +0 -124
- package/src/__tests__/format-date-lowering.test.ts +0 -125
- package/src/format-date-lowering.ts +0 -55
|
@@ -17,7 +17,7 @@ import { buildBranchLoopDelegationPlan } from './build-event-delegation.ts'
|
|
|
17
17
|
import { buildReactiveEffectsPlan } from './build-reactive-effects.ts'
|
|
18
18
|
import { buildPlainRowCore } from './build-plain-row.ts'
|
|
19
19
|
import type { LazyRowScopeInfo } from './lazy-row-eligibility.ts'
|
|
20
|
-
import { loopKeyFn, buildChildRefBindings } from '../shared.ts'
|
|
20
|
+
import { loopKeyFn, buildChildRefBindings, hasReactiveLoopBindings } from '../shared.ts'
|
|
21
21
|
import type {
|
|
22
22
|
BranchCompositeLoopPlan,
|
|
23
23
|
BranchLoopPlan,
|
|
@@ -43,9 +43,7 @@ export function buildBranchLoopPlan(
|
|
|
43
43
|
return composite
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
const hasReactiveEffects = loop.bindings
|
|
47
|
-
|| loop.bindings.reactiveTexts.length > 0
|
|
48
|
-
|| loop.bindings.conditionals.length > 0
|
|
46
|
+
const hasReactiveEffects = hasReactiveLoopBindings(loop.bindings)
|
|
49
47
|
|
|
50
48
|
// flatMap descriptor mode — see buildPlainLoopPlan (build-loop.ts).
|
|
51
49
|
const fm = loop.flatMapClient
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
import type { TopLevelLoop } from '../../types.ts'
|
|
15
|
+
import type { IRNode } from '../../../types.ts'
|
|
15
16
|
import {
|
|
16
17
|
buildChainedArrayExpr,
|
|
17
18
|
varSlotId,
|
|
@@ -25,12 +26,39 @@ import {
|
|
|
25
26
|
buildCompSelector,
|
|
26
27
|
isTextOnlyConditional,
|
|
27
28
|
buildChildRefBindings,
|
|
29
|
+
hasReactiveLoopBindings,
|
|
30
|
+
buildChildrenTextEffect,
|
|
28
31
|
} from '../shared.ts'
|
|
29
32
|
import { irChildrenToJsExpr, renderPreamble } from '../../html-template.ts'
|
|
30
33
|
import { buildReactiveEffectsPlan } from './build-reactive-effects.ts'
|
|
31
34
|
import type { ComponentLoopPlan, NestedComponentInit } from './types.ts'
|
|
32
35
|
import { internalInvariant } from '../../../errors.ts'
|
|
33
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Collect the `slotId` of every `expression` leaf reachable through
|
|
39
|
+
* `nodes` — recursing only through `text`/`expression`/text-only
|
|
40
|
+
* `conditional` nodes, mirroring exactly the shape `isTextOnlyConditional`
|
|
41
|
+
* validates. Used to find which of a component-root loop's own
|
|
42
|
+
* `elem.bindings.reactiveTexts` entries (collected via the generic,
|
|
43
|
+
* depth-unaware `collectLoopChildBindings` walk — see the comment below)
|
|
44
|
+
* are already patched by a NESTED child component's `childrenTextEffect`,
|
|
45
|
+
* so the row-level wiring doesn't ALSO patch them (#3143 follow-up: two
|
|
46
|
+
* independent effects racing to write — and, before #3064's marker-aware
|
|
47
|
+
* patch, one destroying the other's `<!--bf:^sN-->` markers outright —
|
|
48
|
+
* caught by `update-expected-html` fixture drift on `data-table`, whose
|
|
49
|
+
* `TableRow` loop forwards `<TableCell>{payment.id}</TableCell>` nested
|
|
50
|
+
* components).
|
|
51
|
+
*/
|
|
52
|
+
function collectTextOnlySlotIds(nodes: readonly IRNode[], into: Set<string>): void {
|
|
53
|
+
for (const node of nodes) {
|
|
54
|
+
if (node.type === 'expression') {
|
|
55
|
+
if (node.slotId) into.add(node.slotId)
|
|
56
|
+
} else if (node.type === 'conditional' && isTextOnlyConditional(node)) {
|
|
57
|
+
collectTextOnlySlotIds([node.whenTrue, node.whenFalse], into)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
34
62
|
/** @internal — prefer `buildLoopPlan`. */
|
|
35
63
|
export function buildComponentLoopPlan(elem: TopLevelLoop, profileComponentName?: string): ComponentLoopPlan {
|
|
36
64
|
const { name } = elem.childComponent!
|
|
@@ -56,6 +84,11 @@ export function buildComponentLoopPlan(elem: TopLevelLoop, profileComponentName?
|
|
|
56
84
|
|
|
57
85
|
// Only init components at loopDepth 0 — inner-loop components are handled by their own loop
|
|
58
86
|
const outerNestedComps = (elem.nestedComponents ?? []).filter(c => !c.loopDepth)
|
|
87
|
+
const wrap = (expr: string) => wrapLoopParamAsAccessor(expr, elem.param, elem.paramBindings, elem.index)
|
|
88
|
+
// Slot ids already patched by a nested component's OWN `childrenTextEffect`
|
|
89
|
+
// below — collected up front so the row-level reactive-texts wiring further
|
|
90
|
+
// down can exclude them (see the comment on that filter for why).
|
|
91
|
+
const nestedChildrenTextEffectSlotIds = new Set<string>()
|
|
59
92
|
const nestedComps: NestedComponentInit[] = outerNestedComps.map(comp => {
|
|
60
93
|
const isTextOnly = comp.children?.length
|
|
61
94
|
? comp.children.every(c => c.type === 'expression' || c.type === 'text' || isTextOnlyConditional(c))
|
|
@@ -64,17 +97,46 @@ export function buildComponentLoopPlan(elem: TopLevelLoop, profileComponentName?
|
|
|
64
97
|
const childrenFreeIds = isTextOnly && comp.children ? irChildrenFreeIds(comp.children) : undefined
|
|
65
98
|
const childrenRefsLoop = rawChildrenExpr != null && childrenFreeIds != null
|
|
66
99
|
&& (childrenFreeIds.has(elem.param) || (!!elem.index && childrenFreeIds.has(elem.index)))
|
|
100
|
+
if (childrenRefsLoop && comp.children) {
|
|
101
|
+
collectTextOnlySlotIds(comp.children, nestedChildrenTextEffectSlotIds)
|
|
102
|
+
}
|
|
67
103
|
return {
|
|
68
104
|
componentName: comp.name,
|
|
69
105
|
selector: buildCompSelector(comp),
|
|
70
106
|
propsExpr: buildComponentPropsExpr(comp, elem.param, undefined, elem.index),
|
|
107
|
+
// #3064: marker-scoped where possible — see `buildChildrenTextEffect`.
|
|
71
108
|
childrenTextEffect: childrenRefsLoop
|
|
72
|
-
?
|
|
109
|
+
? buildChildrenTextEffect(comp.children!, rawChildrenExpr!, wrap)
|
|
73
110
|
: null,
|
|
74
111
|
}
|
|
75
112
|
})
|
|
76
113
|
|
|
77
|
-
|
|
114
|
+
// #3143: a component-root loop's own reactive attrs/texts — collected via
|
|
115
|
+
// `collectLoopChildBindings` into `elem.bindings` the same way as every
|
|
116
|
+
// other loop shape (`collect-elements.ts`'s `loop:` visitor calls it
|
|
117
|
+
// unconditionally) — used to be silently dropped here: this builder only
|
|
118
|
+
// ever read `elem.bindings.conditionals`, never `.reactiveAttrs` /
|
|
119
|
+
// `.reactiveTexts`. Those two collectors DO reach a forwarded element
|
|
120
|
+
// inside the root component's own `<Chip>...</Chip>` JSX-children body
|
|
121
|
+
// (`traverseElements`'s default `walkIR` descent into an `IRComponent`
|
|
122
|
+
// node's `.children` — no `component:` visitor override needed, unlike
|
|
123
|
+
// the JSX-children PROP form), so the bindings were computed and then
|
|
124
|
+
// thrown away. Routing them through the same `ReactiveEffectsPlan` the
|
|
125
|
+
// conditionals already used fixes it — see `stringifyComponentLoop`'s
|
|
126
|
+
// gate, widened alongside this to actually emit the effects on the
|
|
127
|
+
// no-nested-components ("simple") path too.
|
|
128
|
+
//
|
|
129
|
+
// The SAME depth-unaware collector also reaches text expressions that
|
|
130
|
+
// are a NESTED component's own children (`<TableRow><TableCell>
|
|
131
|
+
// {payment.id}</TableCell></TableRow>`) — those already get their own
|
|
132
|
+
// patch via `nestedComps[].childrenTextEffect` above, so wiring them
|
|
133
|
+
// AGAIN here would emit two independent effects for the same slot (see
|
|
134
|
+
// `collectTextOnlySlotIds`'s doc comment). Filtered out before either
|
|
135
|
+
// the presence check or the plan itself sees them.
|
|
136
|
+
const rowReactiveTexts = nestedChildrenTextEffectSlotIds.size > 0
|
|
137
|
+
? elem.bindings.reactiveTexts.filter(t => !nestedChildrenTextEffectSlotIds.has(t.slotId))
|
|
138
|
+
: elem.bindings.reactiveTexts
|
|
139
|
+
const hasReactiveEffects = hasReactiveLoopBindings({ ...elem.bindings, reactiveTexts: rowReactiveTexts })
|
|
78
140
|
|
|
79
141
|
return {
|
|
80
142
|
kind: 'component',
|
|
@@ -101,10 +163,10 @@ export function buildComponentLoopPlan(elem: TopLevelLoop, profileComponentName?
|
|
|
101
163
|
// `childRefs`) is preserved; populated as empty.
|
|
102
164
|
childRefs: buildChildRefBindings(elem.bindings.refs, elem.param, elem.paramBindings, elem.index),
|
|
103
165
|
profileLoopId: profileComponentName ? `${profileComponentName}#binding:${elem.slotId}` : undefined,
|
|
104
|
-
|
|
166
|
+
reactiveEffects: hasReactiveEffects
|
|
105
167
|
? buildReactiveEffectsPlan({
|
|
106
|
-
attrs:
|
|
107
|
-
texts:
|
|
168
|
+
attrs: elem.bindings.reactiveAttrs,
|
|
169
|
+
texts: rowReactiveTexts,
|
|
108
170
|
conditionals: elem.bindings.conditionals,
|
|
109
171
|
loopParam: elem.param,
|
|
110
172
|
loopParamBindings: elem.paramBindings,
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
destructureLoopParam,
|
|
21
21
|
buildDepthLevels,
|
|
22
22
|
buildChildRefBindings,
|
|
23
|
+
hasReactiveLoopBindings,
|
|
23
24
|
} from '../shared.ts'
|
|
24
25
|
import { buildReactiveEffectsPlan } from './build-reactive-effects.ts'
|
|
25
26
|
import { buildInnerLoopsPlan } from './build-inner-loop.ts'
|
|
@@ -170,13 +171,9 @@ function filterCondCompsOut(
|
|
|
170
171
|
}
|
|
171
172
|
|
|
172
173
|
function hasReactive(elem: TopLevelLoop): boolean {
|
|
173
|
-
return elem.bindings
|
|
174
|
-
|| elem.bindings.reactiveTexts.length > 0
|
|
175
|
-
|| elem.bindings.conditionals.length > 0
|
|
174
|
+
return hasReactiveLoopBindings(elem.bindings)
|
|
176
175
|
}
|
|
177
176
|
|
|
178
177
|
function hasReactiveBranch(loop: BranchLoop): boolean {
|
|
179
|
-
return loop.bindings
|
|
180
|
-
|| loop.bindings.reactiveTexts.length > 0
|
|
181
|
-
|| loop.bindings.conditionals.length > 0
|
|
178
|
+
return hasReactiveLoopBindings(loop.bindings)
|
|
182
179
|
}
|
|
@@ -79,6 +79,7 @@ function buildArmBody(branch: BranchSummary, options: BuildInsertOptions): ArmBo
|
|
|
79
79
|
refs: branch.refs.map(r => ({
|
|
80
80
|
slotId: r.slotId,
|
|
81
81
|
callback: r.callback,
|
|
82
|
+
...(r.ssrPortalOwner && { ssrPortalOwner: true }),
|
|
82
83
|
})),
|
|
83
84
|
childComponents: branch.childComponents.map(c => ({
|
|
84
85
|
name: c.name,
|
|
@@ -63,6 +63,7 @@ function wrapAttrValueExpression(value: AttrValue, wrap: (s: string) => string):
|
|
|
63
63
|
}
|
|
64
64
|
import { destructureLoopParam, loopKeyFn, buildCompSelector, nestedLoopIndexAlias } from '../shared.ts'
|
|
65
65
|
import { BF_HOST, BF_AT } from '@barefootjs/shared'
|
|
66
|
+
import { isEventHandlerName } from '../../../event-handler-name.ts'
|
|
66
67
|
import type {
|
|
67
68
|
BranchChildComponentInit,
|
|
68
69
|
BranchChildComponentInitsPlan,
|
|
@@ -174,7 +175,7 @@ export function buildBranchChildComponentInitsPlan(
|
|
|
174
175
|
const propsEntries = comp.props
|
|
175
176
|
.filter(p => p.name !== 'key')
|
|
176
177
|
.map(p => {
|
|
177
|
-
if (
|
|
178
|
+
if (isEventHandlerName(p.name)) {
|
|
178
179
|
return `${quotePropName(p.name)}: ${wrap(attrValueToString(p.value) ?? 'undefined')}`
|
|
179
180
|
}
|
|
180
181
|
switch (p.value.kind) {
|
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
loopKeyFn,
|
|
34
34
|
buildChildRefBindings,
|
|
35
35
|
buildStaticChildRefBindings,
|
|
36
|
+
hasReactiveLoopBindings,
|
|
36
37
|
} from '../shared.ts'
|
|
37
38
|
import { buildLoopReactiveEffectsPlan } from './build-reactive-effects.ts'
|
|
38
39
|
import { buildPlainRowCore } from './build-plain-row.ts'
|
|
@@ -112,9 +113,7 @@ export function buildPlainLoopPlan(
|
|
|
112
113
|
profileComponentName?: string,
|
|
113
114
|
lazyScope?: LazyRowScopeInfo,
|
|
114
115
|
): PlainLoopPlan {
|
|
115
|
-
const hasReactive = elem.bindings
|
|
116
|
-
|| elem.bindings.reactiveTexts.length > 0
|
|
117
|
-
|| elem.bindings.conditionals.length > 0
|
|
116
|
+
const hasReactive = hasReactiveLoopBindings(elem.bindings)
|
|
118
117
|
|
|
119
118
|
// flatMap descriptor mode: reconcile the FLATTENED leaves. The source
|
|
120
119
|
// accessor runs the flatMap body (plain items — per-item signals don't
|
|
@@ -216,16 +215,29 @@ export function buildPlainLoopPlan(
|
|
|
216
215
|
export function buildStaticLoopPlan(elem: TopLevelLoop, unsafeLocalNames: Set<string>, profileComponentName?: string): StaticLoopPlan {
|
|
217
216
|
// Group reactive attrs by their child slot id, preserving the legacy
|
|
218
217
|
// declaration-order Map-iteration semantics.
|
|
218
|
+
//
|
|
219
|
+
// #3143: this used to skip the whole loop (`if (!elem.childComponent)`)
|
|
220
|
+
// whenever the static array's row root is a child component
|
|
221
|
+
// (`<Chip>...</Chip>`, e.g. `opts.map(opt => <Chip>...)` for a plain
|
|
222
|
+
// array `opts`) — a migration-era artifact from when this builder was
|
|
223
|
+
// mechanically split out of the legacy `emitStaticArrayUpdates` emitter
|
|
224
|
+
// (#1253), not a deliberate exclusion: `texts` a few lines below has
|
|
225
|
+
// never had the equivalent guard, and the stringifier
|
|
226
|
+
// (`stringifyStaticLoop`) patches both through the exact same
|
|
227
|
+
// `qsa(__iterEl, '[bf="<slot>"]')` lookup — a descendant CSS query that
|
|
228
|
+
// reaches an attribute on an element forwarded as the child component's
|
|
229
|
+
// OWN `children` (`^`-prefixed slot id) just as readily as one on
|
|
230
|
+
// `__iterEl` itself. Dropping the guard lets the forwarded `<a>`'s
|
|
231
|
+
// `href`/`data-current` (this fixture) get the same reactive-attribute
|
|
232
|
+
// effect a plain-element static row's own attrs already get.
|
|
219
233
|
const attrsBySlotMap = new Map<string, LoopChildReactiveAttr[]>()
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
attrsBySlotMap.set(attr.childSlotId, bucket)
|
|
226
|
-
}
|
|
227
|
-
bucket.push(attr)
|
|
234
|
+
for (const attr of elem.bindings.reactiveAttrs) {
|
|
235
|
+
let bucket = attrsBySlotMap.get(attr.childSlotId)
|
|
236
|
+
if (!bucket) {
|
|
237
|
+
bucket = []
|
|
238
|
+
attrsBySlotMap.set(attr.childSlotId, bucket)
|
|
228
239
|
}
|
|
240
|
+
bucket.push(attr)
|
|
229
241
|
}
|
|
230
242
|
|
|
231
243
|
const indexParam = elem.index || '__idx'
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
* may be defined as getters over the parent's signals), or a name the
|
|
43
43
|
* compiler cannot classify at all — is `opaque` and makes the loop
|
|
44
44
|
* ineligible. Imports and component-local functions are opaque TOO
|
|
45
|
-
* (`const isSelected =
|
|
45
|
+
* (`const isSelected = someFactory(selected)` is an ordinary local
|
|
46
46
|
* whose CALL is the reactive read), so they refuse the loop as well —
|
|
47
47
|
* the `inert` set names them only so the refusal can say which one.
|
|
48
48
|
* Genuinely ignorable are the names that cannot carry a reactive read
|
|
@@ -471,8 +471,8 @@ export function classifyLazyBinding(args: {
|
|
|
471
471
|
// Everything else is OPAQUE, and deliberately so — this is where the
|
|
472
472
|
// conservative line has to sit, because a reactive accessor can hide
|
|
473
473
|
// behind an ordinary-looking name:
|
|
474
|
-
// - `const isSelected =
|
|
475
|
-
// whose CALL is reactive
|
|
474
|
+
// - `const isSelected = someFactory(selected)` is a local `const`
|
|
475
|
+
// whose CALL is reactive,
|
|
476
476
|
// - a local function's body can read a signal,
|
|
477
477
|
// - a prop may be defined as a getter over the parent's signals,
|
|
478
478
|
// - an imported name may be another module's `@client` module signal.
|
|
@@ -192,12 +192,17 @@ interface PlainLoopVariant extends DynamicLoopCommon {
|
|
|
192
192
|
* Loop body is a single child component (with or without nested child
|
|
193
193
|
* components inside it).
|
|
194
194
|
*
|
|
195
|
-
* `nestedComps.length === 0`
|
|
196
|
-
*
|
|
197
|
-
*
|
|
195
|
+
* `nestedComps.length === 0 && reactiveEffects === null` → simple two-line
|
|
196
|
+
* renderItem.
|
|
197
|
+
* otherwise → SSR/CSR split that initialises the outer
|
|
198
|
+
* component, each nested child, and any
|
|
199
|
+
* reactive effect on the outer component's
|
|
200
|
+
* own forwarded children / conditionals.
|
|
198
201
|
*
|
|
199
|
-
* `
|
|
200
|
-
*
|
|
202
|
+
* `reactiveEffects` is non-null when the row has a reactive attr/text on an
|
|
203
|
+
* element forwarded as the ROOT component's own `children` (#3143) or a
|
|
204
|
+
* reactive conditional in the body; same plan shape as plain/composite
|
|
205
|
+
* `reactiveEffects`.
|
|
201
206
|
*/
|
|
202
207
|
interface ComponentLoopVariant extends DynamicLoopCommon {
|
|
203
208
|
kind: 'component'
|
|
@@ -209,8 +214,15 @@ interface ComponentLoopVariant extends DynamicLoopCommon {
|
|
|
209
214
|
keyExpr: string
|
|
210
215
|
/** Nested child component initialisers; empty for the simple case. */
|
|
211
216
|
nestedComps: NestedComponentInit[]
|
|
212
|
-
/**
|
|
213
|
-
|
|
217
|
+
/**
|
|
218
|
+
* Reactive-effects plan for the loop ROOT component's own reactive attrs /
|
|
219
|
+
* texts / conditionals — i.e. bindings on elements forwarded as the root
|
|
220
|
+
* component's `children` (`<Chip><a href={...}>...</a></Chip>`, #3143),
|
|
221
|
+
* plus any reactive conditional in the row. Named to match
|
|
222
|
+
* `PlainLoopVariant.reactiveEffects` (not just `childConditionalEffects` —
|
|
223
|
+
* it used to carry only conditionals, before #3143 widened it).
|
|
224
|
+
*/
|
|
225
|
+
reactiveEffects: ReactiveEffectsPlan | null
|
|
214
226
|
/**
|
|
215
227
|
* Profile-mode loop id (#1690, #1795 Phase 3) for the component loop's
|
|
216
228
|
* `mapArray`. Undefined off → byte-identical (SR8).
|
|
@@ -320,11 +332,40 @@ export type ComponentLoopPlan = Extract<LoopPlan, { kind: 'component' }>
|
|
|
320
332
|
export type CompositeLoopPlan = Extract<LoopPlan, { kind: 'composite' }>
|
|
321
333
|
export type StaticLoopPlan = Extract<LoopPlan, { kind: 'static' }>
|
|
322
334
|
|
|
335
|
+
/**
|
|
336
|
+
* How a loop-row nested/forwarded child component's text-only `children`
|
|
337
|
+
* should be kept in sync with the loop's per-row signal (#3064).
|
|
338
|
+
*
|
|
339
|
+
* `'markers'` (preferred): one patch per `expression`-type child, each
|
|
340
|
+
* writing through its own SSR-emitted `<!--bf:^sN-->…<!--/-->` marker pair
|
|
341
|
+
* via the marker-aware `$t` primitive — the row's own text markers and
|
|
342
|
+
* static text siblings (e.g. the `"$"` in a `${amount}` cell) are left
|
|
343
|
+
* untouched, matching how a parent-owned text patches everywhere else.
|
|
344
|
+
*
|
|
345
|
+
* `'textContent'` (legacy fallback): the whole joined value is written with
|
|
346
|
+
* a single `.textContent =` assignment, discarding any marker/text
|
|
347
|
+
* structure in the child root. Used only when the children mix in a
|
|
348
|
+
* text-only CONDITIONAL (`isTextOnlyConditional`) — which patches through
|
|
349
|
+
* its own `insert()`, not a stable per-slot marker this scheme can target —
|
|
350
|
+
* or, defensively, if some `expression` child was never granted a slot id.
|
|
351
|
+
*
|
|
352
|
+
* Built by `buildChildrenTextEffect` and stringified by
|
|
353
|
+
* `stringifyChildrenTextEffect` (both `../shared.ts`) — defined here, not
|
|
354
|
+
* there, so `shared.ts` (which the whole `plan`/`stringify` tree feeds data
|
|
355
|
+
* through, per this file's one-way dependency note) doesn't need a type
|
|
356
|
+
* import pointing back at `plan/loop.ts`, mirroring how `shared.ts` already
|
|
357
|
+
* imports `LoopChildRefBinding`/`PreambleRegionPlan` FROM here.
|
|
358
|
+
*/
|
|
359
|
+
export type NestedChildrenTextEffect =
|
|
360
|
+
| { readonly kind: 'markers'; readonly slotPatches: ReadonlyArray<{ readonly slotId: string; readonly wrappedExpr: string }> }
|
|
361
|
+
| { readonly kind: 'textContent'; readonly wrappedChildren: string }
|
|
362
|
+
|
|
323
363
|
/**
|
|
324
364
|
* One nested child component to initialise inside a renderItem body.
|
|
325
365
|
* `childrenTextEffect` is non-null when the component's children are
|
|
326
366
|
* text-equivalent AND reference the outer loop param — in that case the
|
|
327
|
-
* stringifier emits a
|
|
367
|
+
* stringifier emits a reactive effect (marker-scoped where possible, #3064)
|
|
368
|
+
* that keeps the child's forwarded text in sync alongside `initChild`.
|
|
328
369
|
*/
|
|
329
370
|
export interface NestedComponentInit {
|
|
330
371
|
componentName: string
|
|
@@ -332,8 +373,8 @@ export interface NestedComponentInit {
|
|
|
332
373
|
selector: string
|
|
333
374
|
/** Pre-built props object expression for the nested component. */
|
|
334
375
|
propsExpr: string
|
|
335
|
-
/** When non-null, emit a reactive
|
|
336
|
-
childrenTextEffect:
|
|
376
|
+
/** When non-null, emit a reactive children-text effect alongside `initChild` — see `NestedChildrenTextEffect` (../shared.ts). */
|
|
377
|
+
childrenTextEffect: NestedChildrenTextEffect | null
|
|
337
378
|
}
|
|
338
379
|
|
|
339
380
|
/**
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
* control-flow.ts -> control-flow/{plan,stringify}/* -> shared.ts
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import type { LoopChildEvent, LoopChildRef, TopLevelLoop, NestedLoop, CollectedLoop } from '../types.ts'
|
|
16
|
-
import type { IRLoopChildComponent, LoopParamBinding } from '../../types.ts'
|
|
15
|
+
import type { LoopChildBindings, LoopChildEvent, LoopChildRef, TopLevelLoop, NestedLoop, CollectedLoop } from '../types.ts'
|
|
16
|
+
import type { IRLoopChildComponent, IRExpression, IRNode, LoopParamBinding } from '../../types.ts'
|
|
17
17
|
import { preambleAnalysisText } from '../../types.ts'
|
|
18
18
|
import { quotePropName, wrapLoopParamAsAccessor, irChildrenFreeIds, attrValueToString } from '../utils.ts'
|
|
19
19
|
import { irChildrenToJsExpr, jsxChildrenPropGetterExpr } from '../html-template.ts'
|
|
@@ -21,7 +21,7 @@ import { spliceChildValue } from '../safe-html.ts'
|
|
|
21
21
|
import { emitListenerBlock } from './stringify/event-listener.ts'
|
|
22
22
|
import { nameForRegistryRef } from '../component-scope.ts'
|
|
23
23
|
import { BF_SCOPE, BF_HOST, BF_AT } from '@barefootjs/shared'
|
|
24
|
-
import type { LoopChildRefBinding, PreambleRegionPlan } from './plan/loop.ts'
|
|
24
|
+
import type { LoopChildRefBinding, PreambleRegionPlan, NestedChildrenTextEffect } from './plan/loop.ts'
|
|
25
25
|
import type { PreambleRegionSource } from '../../types.ts'
|
|
26
26
|
import {
|
|
27
27
|
extractFreeIdentifiersFromText,
|
|
@@ -406,6 +406,21 @@ export function buildCompSelector(comp: { slotId?: string | null; name: string }
|
|
|
406
406
|
* For new elements (CSR): replaces placeholders with createComponent.
|
|
407
407
|
* For SSR elements (hydration): finds scope elements and calls initChild.
|
|
408
408
|
*/
|
|
409
|
+
/**
|
|
410
|
+
* Whether a loop row's collected bindings need a `ReactiveEffectsPlan` at
|
|
411
|
+
* all (#3143). The three-field check (`reactiveAttrs` / `reactiveTexts` /
|
|
412
|
+
* `conditionals`) was independently duplicated across the plain, static,
|
|
413
|
+
* composite and component-root loop builders — see CLAUDE.md's "One
|
|
414
|
+
* decision, two implementations" note. This is the single implementation;
|
|
415
|
+
* builders that build their own `LoopChildBindings`-shaped value (e.g. a
|
|
416
|
+
* `BranchLoop`'s `.bindings`) call it too since the field shape is shared.
|
|
417
|
+
*/
|
|
418
|
+
export function hasReactiveLoopBindings(bindings: LoopChildBindings): boolean {
|
|
419
|
+
return bindings.reactiveAttrs.length > 0
|
|
420
|
+
|| bindings.reactiveTexts.length > 0
|
|
421
|
+
|| bindings.conditionals.length > 0
|
|
422
|
+
}
|
|
423
|
+
|
|
409
424
|
/** Check if an IR node is a conditional whose branches are text/expression only. */
|
|
410
425
|
export function isTextOnlyConditional(node: { type: string; [k: string]: any }): boolean {
|
|
411
426
|
if (node.type !== 'conditional') return false
|
|
@@ -414,6 +429,64 @@ export function isTextOnlyConditional(node: { type: string; [k: string]: any }):
|
|
|
414
429
|
return checkNode(node.whenTrue) && checkNode(node.whenFalse)
|
|
415
430
|
}
|
|
416
431
|
|
|
432
|
+
/**
|
|
433
|
+
* Decide which `NestedChildrenTextEffect` shape (`./plan/loop.ts`) applies to a nested/forwarded
|
|
434
|
+
* child component's text-only `children` (#3064). Called only once the
|
|
435
|
+
* caller has already confirmed the children are text-only AND reference the
|
|
436
|
+
* loop's item/index (`childrenRefsLoop` at both call sites below) — this is
|
|
437
|
+
* the single implementation both used to duplicate (`build-component-loop.ts`'s
|
|
438
|
+
* `nestedComps` map and `emitComponentAndEventSetup` here), one for
|
|
439
|
+
* component-root loops, one for composite loops.
|
|
440
|
+
*
|
|
441
|
+
* `rawChildrenExpr` is the already-computed `irChildrenToJsExpr(children)`
|
|
442
|
+
* (both call sites need it for their own `childrenFreeIds` gate too, so it's
|
|
443
|
+
* passed in rather than recomputed) — used verbatim for the `'textContent'`
|
|
444
|
+
* fallback; each `'markers'` patch instead re-derives its OWN wrapped
|
|
445
|
+
* expression from just that one child, not the joined array.
|
|
446
|
+
*/
|
|
447
|
+
export function buildChildrenTextEffect(
|
|
448
|
+
children: readonly IRNode[],
|
|
449
|
+
rawChildrenExpr: string,
|
|
450
|
+
wrap: (expr: string) => string,
|
|
451
|
+
): NestedChildrenTextEffect {
|
|
452
|
+
const exprChildren = children.filter((c): c is IRExpression => c.type === 'expression')
|
|
453
|
+
const hasConditional = children.some(c => c.type === 'conditional')
|
|
454
|
+
if (!hasConditional && exprChildren.length > 0 && exprChildren.every(c => c.slotId != null)) {
|
|
455
|
+
return {
|
|
456
|
+
kind: 'markers',
|
|
457
|
+
slotPatches: exprChildren.map(c => ({ slotId: c.slotId!, wrappedExpr: wrap(c.expr) })),
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
return { kind: 'textContent', wrappedChildren: wrap(rawChildrenExpr) }
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* Stringify a `NestedChildrenTextEffect` into the effect-only snippet
|
|
465
|
+
* (everything after `initChild(...)`/`upsertChild(...)` inside the
|
|
466
|
+
* `if (__c) { ... }` guard) — callers embed it in their own surrounding
|
|
467
|
+
* `{ const __c = <lookup>; if (__c) { ...; <this> } }` wrapper, since how
|
|
468
|
+
* `__c` is obtained differs (component-root loops resolve it via
|
|
469
|
+
* `qsa` + an explicit `initChild`; composite loops resolve AND init it in
|
|
470
|
+
* one `upsertChild` call).
|
|
471
|
+
*
|
|
472
|
+
* The `'textContent'` branch is byte-identical to the pre-#3064 inline
|
|
473
|
+
* emission at both call sites, so a row whose forwarded children mix in a
|
|
474
|
+
* text-only conditional (the one shape this fix doesn't cover, see
|
|
475
|
+
* `NestedChildrenTextEffect`'s docstring) keeps its exact prior output.
|
|
476
|
+
*/
|
|
477
|
+
export function stringifyChildrenTextEffect(effect: NestedChildrenTextEffect): string {
|
|
478
|
+
if (effect.kind === 'markers') {
|
|
479
|
+
const { slotPatches } = effect
|
|
480
|
+
const ids = slotPatches.map(p => `'${p.slotId}'`).join(', ')
|
|
481
|
+
const varNames = slotPatches.map((_, i) => `__ct${i}`)
|
|
482
|
+
const writes = slotPatches
|
|
483
|
+
.map((p, i) => `if (${varNames[i]}) ${varNames[i]}.data = String(${p.wrappedExpr} ?? '')`)
|
|
484
|
+
.join('; ')
|
|
485
|
+
return `{ const [${varNames.join(', ')}] = $t(__c, ${ids}); createEffect(() => { ${writes} }) }`
|
|
486
|
+
}
|
|
487
|
+
return `createEffect(() => { const __v = ${effect.wrappedChildren}; __c.textContent = Array.isArray(__v) ? __v.join('') : String(__v ?? '') })`
|
|
488
|
+
}
|
|
489
|
+
|
|
417
490
|
/**
|
|
418
491
|
* Emit child component initialisation + event listener setup for a list of
|
|
419
492
|
* components and events on `elVar`. Mode-independent: each comp emits a
|
|
@@ -465,8 +538,8 @@ export function emitComponentAndEventSetup(
|
|
|
465
538
|
const upsertCall = `${upsertFn}(${elVar}, '${nameForRegistryRef(comp.name)}', ${slotIdLit}, ${propsExpr}${keyArg}, __scope)`
|
|
466
539
|
|
|
467
540
|
if (childrenRefsLoop) {
|
|
468
|
-
const
|
|
469
|
-
ls.push(`${indent}{ const __c = ${upsertCall}; if (__c) {
|
|
541
|
+
const effect = buildChildrenTextEffect(comp.children!, rawChildrenExpr!, wrap)
|
|
542
|
+
ls.push(`${indent}{ const __c = ${upsertCall}; if (__c) { ${stringifyChildrenTextEffect(effect)} } }`)
|
|
470
543
|
} else {
|
|
471
544
|
ls.push(`${indent}${upsertCall}`)
|
|
472
545
|
}
|
|
@@ -2,27 +2,29 @@
|
|
|
2
2
|
* Stringify a `ComponentLoopPlan` to source lines.
|
|
3
3
|
*
|
|
4
4
|
* Two output shapes (preserved byte-identical from the legacy
|
|
5
|
-
* `emitComponentLoopReconciliation`):
|
|
5
|
+
* `emitComponentLoopReconciliation` for the case it covered):
|
|
6
6
|
*
|
|
7
|
-
* nestedComps.length === 0 (simple) —
|
|
7
|
+
* nestedComps.length === 0 AND reactiveEffects === null (simple) —
|
|
8
|
+
* two-line renderItem body:
|
|
8
9
|
* <i>mapArray(() => <arr>, <container>, <keyFn>, (<head>, <idx>, __existing) => {
|
|
9
10
|
* <i> <unwrap?>
|
|
10
11
|
* <i> if (__existing) { initChild('<C>', __existing, <props>); return __existing }
|
|
11
12
|
* <i> return createComponent('<C>', <props>, <key>)
|
|
12
13
|
* <i>})
|
|
13
14
|
*
|
|
14
|
-
*
|
|
15
|
+
* otherwise (nested comps and/or the root's own reactiveEffects) —
|
|
16
|
+
* SSR/CSR split:
|
|
15
17
|
* <i>mapArray(...) => {
|
|
16
18
|
* <i> <unwrap?>
|
|
17
19
|
* <i> if (__existing) {
|
|
18
20
|
* <i> initChild('<C>', __existing, <props>)
|
|
19
21
|
* <i> {<each nested initChild + optional createEffect>}
|
|
20
|
-
* <i> <stringifyReactiveEffects on __existing if
|
|
22
|
+
* <i> <stringifyReactiveEffects on __existing if reactiveEffects>
|
|
21
23
|
* <i> return __existing
|
|
22
24
|
* <i> }
|
|
23
25
|
* <i> const __csrEl = createComponent('<C>', <props>, <key>)
|
|
24
26
|
* <i> {<each nested initChild + optional createEffect>}
|
|
25
|
-
* <i> <stringifyReactiveEffects on __csrEl if
|
|
27
|
+
* <i> <stringifyReactiveEffects on __csrEl if reactiveEffects>
|
|
26
28
|
* <i> return __csrEl
|
|
27
29
|
* <i>})
|
|
28
30
|
*
|
|
@@ -33,6 +35,7 @@
|
|
|
33
35
|
import { stringifyReactiveEffects } from './reactive-effects.ts'
|
|
34
36
|
import type { ComponentLoopPlan, NestedComponentInit } from '../plan/types.ts'
|
|
35
37
|
import { nameForRegistryRef } from '../../component-scope.ts'
|
|
38
|
+
import { stringifyChildrenTextEffect } from '../shared.ts'
|
|
36
39
|
|
|
37
40
|
export function stringifyComponentLoop(lines: string[], plan: ComponentLoopPlan): void {
|
|
38
41
|
const {
|
|
@@ -47,7 +50,7 @@ export function stringifyComponentLoop(lines: string[], plan: ComponentLoopPlan)
|
|
|
47
50
|
componentPropsExpr,
|
|
48
51
|
keyExpr,
|
|
49
52
|
nestedComps,
|
|
50
|
-
|
|
53
|
+
reactiveEffects,
|
|
51
54
|
profileLoopId,
|
|
52
55
|
mapPreambleWrapped,
|
|
53
56
|
} = plan
|
|
@@ -64,7 +67,17 @@ export function stringifyComponentLoop(lines: string[], plan: ComponentLoopPlan)
|
|
|
64
67
|
|
|
65
68
|
const scopedComp = nameForRegistryRef(componentName)
|
|
66
69
|
|
|
67
|
-
|
|
70
|
+
// #3143: the "simple" 2-line shape must be reserved for a row with
|
|
71
|
+
// NEITHER nested comps NOR any reactive effect of its own (attrs/texts on
|
|
72
|
+
// an element forwarded as ITS OWN `children`, or a reactive conditional
|
|
73
|
+
// in the row) — it returns straight from `initChild`/`createComponent`
|
|
74
|
+
// with no handle to run an effect against. Gating on `nestedComps.length
|
|
75
|
+
// === 0` alone (the pre-#3143 condition) silently skipped `reactiveEffects`
|
|
76
|
+
// whenever a component-root loop had no nested child COMPONENTS, which is
|
|
77
|
+
// exactly the `<Chip><a href={...}>...</a></Chip>` shape: `<a>` isn't a
|
|
78
|
+
// component, so `nestedComps` was always empty, and the "simple" path
|
|
79
|
+
// never even looked at `reactiveEffects`.
|
|
80
|
+
if (nestedComps.length === 0 && !reactiveEffects) {
|
|
68
81
|
lines.push(` if (__existing) { initChild('${scopedComp}', __existing, ${componentPropsExpr}); return __existing }`)
|
|
69
82
|
lines.push(` return createComponent('${scopedComp}', ${componentPropsExpr}, ${keyExpr})`)
|
|
70
83
|
lines.push(` }, '${markerId}'${loopBfId})`)
|
|
@@ -75,8 +88,8 @@ export function stringifyComponentLoop(lines: string[], plan: ComponentLoopPlan)
|
|
|
75
88
|
lines.push(` if (__existing) {`)
|
|
76
89
|
lines.push(` initChild('${scopedComp}', __existing, ${componentPropsExpr})`)
|
|
77
90
|
for (const nc of nestedComps) emitNestedInit(lines, ' ', '__existing', nc)
|
|
78
|
-
if (
|
|
79
|
-
stringifyReactiveEffects(lines,
|
|
91
|
+
if (reactiveEffects) {
|
|
92
|
+
stringifyReactiveEffects(lines, reactiveEffects, { indent: ' ', elVar: '__existing' })
|
|
80
93
|
}
|
|
81
94
|
lines.push(` return __existing`)
|
|
82
95
|
lines.push(` }`)
|
|
@@ -84,8 +97,8 @@ export function stringifyComponentLoop(lines: string[], plan: ComponentLoopPlan)
|
|
|
84
97
|
// CSR side
|
|
85
98
|
lines.push(` const __csrEl = createComponent('${scopedComp}', ${componentPropsExpr}, ${keyExpr})`)
|
|
86
99
|
for (const nc of nestedComps) emitNestedInit(lines, ' ', '__csrEl', nc)
|
|
87
|
-
if (
|
|
88
|
-
stringifyReactiveEffects(lines,
|
|
100
|
+
if (reactiveEffects) {
|
|
101
|
+
stringifyReactiveEffects(lines, reactiveEffects, { indent: ' ', elVar: '__csrEl' })
|
|
89
102
|
}
|
|
90
103
|
lines.push(` return __csrEl`)
|
|
91
104
|
lines.push(` }, '${markerId}'${loopBfId})`)
|
|
@@ -94,7 +107,7 @@ export function stringifyComponentLoop(lines: string[], plan: ComponentLoopPlan)
|
|
|
94
107
|
function emitNestedInit(lines: string[], indent: string, parentVar: string, nc: NestedComponentInit): void {
|
|
95
108
|
const scopedNc = nameForRegistryRef(nc.componentName)
|
|
96
109
|
if (nc.childrenTextEffect) {
|
|
97
|
-
lines.push(`${indent}{ const __c = qsa(${parentVar}, ${nc.selector}); if (__c) { initChild('${scopedNc}', __c, ${nc.propsExpr});
|
|
110
|
+
lines.push(`${indent}{ const __c = qsa(${parentVar}, ${nc.selector}); if (__c) { initChild('${scopedNc}', __c, ${nc.propsExpr}); ${stringifyChildrenTextEffect(nc.childrenTextEffect)} } }`)
|
|
98
111
|
} else {
|
|
99
112
|
lines.push(`${indent}{ const __c = qsa(${parentVar}, ${nc.selector}); if (__c) initChild('${scopedNc}', __c, ${nc.propsExpr}) }`)
|
|
100
113
|
}
|
|
@@ -124,7 +124,7 @@ function emitArmBody(
|
|
|
124
124
|
|
|
125
125
|
for (const ref of body.refs) {
|
|
126
126
|
const v = varSlotId(ref.slotId)
|
|
127
|
-
lines.push(`${indent}if (_${v}) ${emitRefCall(ref.callback, `_${v}
|
|
127
|
+
lines.push(`${indent}if (_${v}) ${emitRefCall(ref.callback, `_${v}`, ref.ssrPortalOwner)}`)
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
// 3. Child component initializations from the branch swap.
|
|
@@ -31,6 +31,7 @@ import { extractFreeIdentifiersFromNode } from '../analyzer.ts'
|
|
|
31
31
|
import type { ConstantInfo, MemoInfo, SignalInfo } from '../types.ts'
|
|
32
32
|
import type { BindingScope } from '../scope/binding-scope.ts'
|
|
33
33
|
import { resolveAliasOrigin } from '../props-binding.ts'
|
|
34
|
+
import { signalSecondBinding } from '../signal-initializer.ts'
|
|
34
35
|
|
|
35
36
|
/**
|
|
36
37
|
* CSR-substituted const value: the const's initializer with every
|
|
@@ -600,8 +601,12 @@ export function buildSignalMemoEnv(
|
|
|
600
601
|
// that shim directly, with no thunk-wrapping needed. `s.setter` is
|
|
601
602
|
// null for the setter-elided declaration form (`const [count] =
|
|
602
603
|
// createSignal(...)`), which has no name to register.
|
|
603
|
-
|
|
604
|
-
|
|
604
|
+
// An async factory's action (#3165) gets the same no-op: forwarding it as
|
|
605
|
+
// a value (`<Retry run={fetchItems} />`) is allowed, and every read of
|
|
606
|
+
// its accessors in a template position is refused before emit (BF117).
|
|
607
|
+
const second = signalSecondBinding(s)
|
|
608
|
+
if (second) {
|
|
609
|
+
substitutions.set(second, { kind: 'identifier', replacement: '() => {}', freeIdentifiers: new Set() })
|
|
605
610
|
}
|
|
606
611
|
}
|
|
607
612
|
for (const m of memos) {
|
|
@@ -639,7 +644,10 @@ function normalizeSignalInitial(signal: SignalInfo, propsObjectName: string | nu
|
|
|
639
644
|
const initialValue = signal.initialValue
|
|
640
645
|
const propsName = propsObjectName ?? 'props'
|
|
641
646
|
const propsPrefix = `${propsName}.`
|
|
642
|
-
|
|
647
|
+
// An async factory's `initial` (#3165) renders exactly as given: an absent
|
|
648
|
+
// prop means no obtained result, so the value is `undefined` on the server
|
|
649
|
+
// too, never a type default.
|
|
650
|
+
if (!signal.factory && initialValue.startsWith(propsPrefix) && !initialValue.includes('??')) {
|
|
643
651
|
return `${initialValue} ?? ${inferDefaultValue(signal.type)}`
|
|
644
652
|
}
|
|
645
653
|
// Destructured mode (#2265): `templateInitialValue` (when present) has
|