@verajs/renderer 0.1.3 → 0.1.5
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/README.md +42 -2
- package/dist/development/vera-renderer-hydrate.js +89 -6
- package/dist/development/vera-renderer-hydrate.js.map +1 -1
- package/dist/development/vera-renderer-profiler.js +87 -6
- package/dist/development/vera-renderer-profiler.js.map +1 -1
- package/dist/development/vera-renderer.js +87 -6
- package/dist/development/vera-renderer.js.map +1 -1
- package/dist/vera-renderer-hydrate.min.js +1 -1
- package/dist/vera-renderer-hydrate.min.js.map +1 -1
- package/dist/vera-renderer.min.js +1 -1
- package/dist/vera-renderer.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -429,8 +429,16 @@ class AttrPart {
|
|
|
429
429
|
const first = name[0];
|
|
430
430
|
let kind = first === '.' ? PROPERTY : first === '?' ? BOOLEAN : first === '@' ? EVENT : first === '&' ? REF : ATTR;
|
|
431
431
|
let realName = kind ? name.slice(1) : name;
|
|
432
|
-
/**
|
|
433
|
-
*
|
|
432
|
+
/**
|
|
433
|
+
* React muscle-memory, buildless: `onClick=${fn}` ≡ `@click=${fn}`. Strictly `on` + a capital —
|
|
434
|
+
* all-lowercase `onclick` stays a plain attribute (legal inline-handler HTML).
|
|
435
|
+
*
|
|
436
|
+
* `@verajs/spread` repeats these rules rather than importing them. Sharing them through
|
|
437
|
+
* `@verajs/shared-utils` was tried and reverted: the shared form has to return both the kind and
|
|
438
|
+
* the name, and the tuple it allocates cost this bundle 10 B. Principle #5 allows deliberate
|
|
439
|
+
* duplication where two things can legitimately diverge; here #7 decides it — weight is the
|
|
440
|
+
* product, and core and the renderer are the two packages where that is absolute.
|
|
441
|
+
*/
|
|
434
442
|
if (kind === ATTR && first === 'o' && name.charCodeAt(1) === 110 && name.charCodeAt(2) > 64 && name.charCodeAt(2) < 91) {
|
|
435
443
|
kind = EVENT;
|
|
436
444
|
realName = name.slice(2).toLowerCase();
|
|
@@ -473,7 +481,54 @@ class AttrPart {
|
|
|
473
481
|
this._element.setAttribute(this._name, value);
|
|
474
482
|
}
|
|
475
483
|
else if (kind === PROPERTY) {
|
|
476
|
-
this._element
|
|
484
|
+
const target = this._element;
|
|
485
|
+
const name = this._name;
|
|
486
|
+
target[name] = value;
|
|
487
|
+
/**
|
|
488
|
+
* Detection only, and deliberately not repair.
|
|
489
|
+
*
|
|
490
|
+
* A property set on a custom element that has not upgraded yet lands as an own property on
|
|
491
|
+
* the instance. When the definition arrives — lazily imported, code-split, or a module that
|
|
492
|
+
* simply had not run — `customElements.define` upgrades synchronously and the class's field
|
|
493
|
+
* initializers execute. At target ES2022 a field declaration is a `[[Define]]`, so
|
|
494
|
+
* `item?: T` emits `item;` and overwrites the bound value with `undefined`. Nothing throws;
|
|
495
|
+
* it reads as broken reactivity.
|
|
496
|
+
*
|
|
497
|
+
* Repairing it was tried and removed. Re-applying when the slot came back `undefined`
|
|
498
|
+
* covered `item?: T` but not `item = someDefault`, which overwrites with the default and
|
|
499
|
+
* never looks clobbered — so the repair was silently partial, and made the bug intermittent
|
|
500
|
+
* across two spellings of the same mistake. It also cost 74 B in every app while leaving
|
|
501
|
+
* `declare` mandatory anyway, because a property assigned imperatively is unrecoverable:
|
|
502
|
+
* the renderer never saw it, and by the time `init()` runs the value is already gone.
|
|
503
|
+
*
|
|
504
|
+
* So this is `true`-only and production pays nothing — no check, no message, no
|
|
505
|
+
* `whenDefined` subscription. Lit reached the same place from the other direction and
|
|
506
|
+
* throws (`lit.dev/msg/class-field-shadowing`); a warning suffices here because Vera has no
|
|
507
|
+
* prototype accessors to shadow permanently — the damage is one lost value, not a property
|
|
508
|
+
* that never updates again.
|
|
509
|
+
*/
|
|
510
|
+
if (true) {
|
|
511
|
+
const tag = this._element.localName;
|
|
512
|
+
if (tag.indexOf('-') > 0 && !customElements.get(tag)) {
|
|
513
|
+
customElements.whenDefined(tag).then(() => {
|
|
514
|
+
/**
|
|
515
|
+
* States what was observed rather than diagnosing it. A class field is the usual
|
|
516
|
+
* cause by a wide margin, but a component that assigns the property itself during
|
|
517
|
+
* upgrade produces the same observation, and that is a legitimate — if confusing —
|
|
518
|
+
* thing to do, since the renderer's dirty check will not re-apply the bound value on
|
|
519
|
+
* the next render either.
|
|
520
|
+
*/
|
|
521
|
+
if (target[name] !== value)
|
|
522
|
+
console.warn(`@verajs/renderer: the value bound by \`.${name}=\${…}\` on <${tag}> was replaced ` +
|
|
523
|
+
`while the element upgraded. A class field is the usual cause: at ES2022 ` +
|
|
524
|
+
`\`${name}?: …\` emits \`${name};\`, which runs during upgrade and overwrites ` +
|
|
525
|
+
`whatever was set beforehand — write it \`declare ${name}?: …\` instead, which ` +
|
|
526
|
+
`emits nothing. A plain field also wipes properties assigned imperatively, ` +
|
|
527
|
+
`which cannot be detected at all. Ignore this if the component replaced the ` +
|
|
528
|
+
`value on purpose.`);
|
|
529
|
+
});
|
|
530
|
+
}
|
|
531
|
+
}
|
|
477
532
|
}
|
|
478
533
|
else if (kind === BOOLEAN) {
|
|
479
534
|
if (!isFirst || value)
|
|
@@ -492,8 +547,23 @@ class AttrPart {
|
|
|
492
547
|
*/
|
|
493
548
|
if (typeof value === 'function')
|
|
494
549
|
value(this._element);
|
|
495
|
-
else if (typeof value === 'object')
|
|
496
|
-
|
|
550
|
+
else if (typeof value === 'object') {
|
|
551
|
+
/**
|
|
552
|
+
* A self-applying value: anything that knows what to do with an element applies itself.
|
|
553
|
+
* `@verajs/renderer/spread` is the first, and the whole protocol is this one property
|
|
554
|
+
* read — the implementation lives in that entry, so an app that never spreads pays for
|
|
555
|
+
* the check and nothing else. `_$…$` is exempt from property mangling, like `_$litType$`.
|
|
556
|
+
*
|
|
557
|
+
* Deliberately confined to the element position, which is rare. A protocol in the text,
|
|
558
|
+
* attribute or property commits would sit in the hot path every benchmark measures.
|
|
559
|
+
*/
|
|
560
|
+
const self = value;
|
|
561
|
+
/** The part is passed as the ownership key: one element can carry several spreads. */
|
|
562
|
+
if (self._$apply$)
|
|
563
|
+
self._$apply$(this._element, this);
|
|
564
|
+
else
|
|
565
|
+
self.value = this._element;
|
|
566
|
+
}
|
|
497
567
|
// any other value type at element position is consumed and ignored
|
|
498
568
|
}
|
|
499
569
|
}
|
|
@@ -634,14 +704,25 @@ class ChildPart {
|
|
|
634
704
|
}
|
|
635
705
|
_clear() {
|
|
636
706
|
const parent = this._start.parentNode;
|
|
707
|
+
const end = this._end;
|
|
637
708
|
/**
|
|
638
709
|
* When this part owns its parent's entire contents, one `textContent = ''` replaces removing
|
|
639
710
|
* every node individually. For a 1 000-row table body that is the difference between ~22 ms
|
|
640
711
|
* (lit-html's per-node teardown) and ~5 ms.
|
|
712
|
+
*
|
|
713
|
+
* A part owns the whole parent when nothing precedes its start AND nothing follows its end —
|
|
714
|
+
* `_end === null` (a root part, which runs to the end by definition) or `_end` is the last
|
|
715
|
+
* child. The second case is the common one and used to miss this path entirely: every list
|
|
716
|
+
* written as `<tbody>${rows}</tbody>` sits inside a template, and since 0.1.2 a nested part
|
|
717
|
+
* always owns an end marker, so `_end === null` alone never held for it.
|
|
718
|
+
*
|
|
719
|
+
* Re-appending both anchors in order restores the part's boundary exactly as it was.
|
|
641
720
|
*/
|
|
642
|
-
if (this._start.previousSibling === null &&
|
|
721
|
+
if (this._start.previousSibling === null && (end === null || end.nextSibling === null)) {
|
|
643
722
|
parent.textContent = '';
|
|
644
723
|
parent.appendChild(this._start);
|
|
724
|
+
if (end !== null)
|
|
725
|
+
parent.appendChild(end);
|
|
645
726
|
}
|
|
646
727
|
else {
|
|
647
728
|
let node = this._start.nextSibling;
|