@barefootjs/jsx 0.37.1 → 0.38.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/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/analyzer.d.ts +31 -0
- package/dist/analyzer.d.ts.map +1 -1
- 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/errors.d.ts +3 -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 +37 -0
- package/dist/format-date-refusal.d.ts.map +1 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2421 -1787
- package/dist/ir-to-client-js/collect-elements.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/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/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/html-template.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/utils.d.ts +26 -0
- 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/to-locale-date-lowering.d.ts +7 -4
- package/dist/to-locale-date-lowering.d.ts.map +1 -1
- package/dist/types.d.ts +53 -17
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +724 -4564
- 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__/doc-examples.test.ts +12 -22
- 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__/ref-attr-absent-at-ssr.test.ts +472 -0
- package/src/__tests__/ssr-portal-ref-callback.test.ts +217 -0
- package/src/adapters/env-signal.ts +2 -21
- package/src/adapters/interface.ts +13 -0
- package/src/analyzer.ts +31 -27
- package/src/builtin-lowering-plugins.ts +0 -2
- package/src/compiler.ts +24 -0
- package/src/component-root-scope-comment.ts +59 -0
- package/src/errors.ts +44 -1
- package/src/event-handler-name.ts +14 -0
- package/src/expression-parser.ts +41 -17
- package/src/format-date-refusal.ts +266 -0
- package/src/index.ts +12 -2
- package/src/ir-to-client-js/child-components.ts +8 -3
- package/src/ir-to-client-js/collect-elements.ts +27 -13
- 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-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/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/emit-reactive.ts +140 -10
- package/src/ir-to-client-js/emit-registration.ts +2 -2
- 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 +4 -3
- package/src/ir-to-client-js/reactivity.ts +20 -16
- package/src/ir-to-client-js/source-map.ts +2 -1
- package/src/ir-to-client-js/utils.ts +34 -0
- package/src/jsx-to-ir.ts +737 -49
- package/src/opaque-local-accessor.ts +44 -0
- package/src/rich-type-refusal.ts +1 -1
- package/src/to-locale-date-lowering.ts +7 -4
- package/src/types.ts +51 -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
|
@@ -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
|
}
|
|
@@ -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(
|
|
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
|
-
|
|
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
|
-
|
|
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
|
}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
import type { ComponentIR, IRFragment, 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, isCommentScopedRoot, 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'
|
|
@@ -218,7 +218,7 @@ export function emitRegistrationAndHydration(
|
|
|
218
218
|
const isCommentScope = isCommentScopedRoot(_ir.root)
|
|
219
219
|
|
|
220
220
|
// Build ComponentDef object for hydrate()
|
|
221
|
-
const defParts: string[] = [`init:
|
|
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)
|