@verajs/renderer 0.2.0 → 0.2.1
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 +94 -6
- package/dist/development/vera-renderer-hydrate.js +185 -50
- package/dist/development/vera-renderer-hydrate.js.map +1 -1
- package/dist/development/vera-renderer-profiler.js +185 -50
- package/dist/development/vera-renderer-profiler.js.map +1 -1
- package/dist/development/vera-renderer-spread.d.ts +32 -42
- package/dist/development/vera-renderer-spread.d.ts.map +1 -1
- package/dist/development/vera-renderer-spread.js +140 -6
- package/dist/development/vera-renderer-spread.js.map +1 -1
- package/dist/development/vera-renderer-tag.js +107 -5
- package/dist/development/vera-renderer-tag.js.map +1 -1
- package/dist/development/vera-renderer.js +185 -50
- 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-spread.min.js +1 -1
- package/dist/vera-renderer-spread.min.js.map +1 -1
- package/dist/vera-renderer-tag.min.js +1 -1
- package/dist/vera-renderer-tag.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
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @verajs/renderer
|
|
2
2
|
|
|
3
|
-
The DOM renderer for VeraJS — <!--size:renderer.gzip-->4.
|
|
3
|
+
The DOM renderer for VeraJS — <!--size:renderer.gzip-->4.58 KB<!--/size:renderer.gzip--> gzipped,
|
|
4
4
|
no dependencies, no build step required.
|
|
5
5
|
|
|
6
6
|
Tagged templates parse once and clone; every render after the first walks only the value slots, so
|
|
@@ -283,6 +283,13 @@ Native `<slot>` needs a shadow root. This entry teaches the renderer to distribu
|
|
|
283
283
|
component's own children into the `<slot name="…">` positions of its template, so **one component
|
|
284
284
|
works in both modes** — users write `<div slot="title">` exactly as they would against shadow DOM.
|
|
285
285
|
|
|
286
|
+
**Wire it at your app entry, before anything renders.** A template resolves this once, at
|
|
287
|
+
construction, and is interned per call site for the life of the page — so wiring `slots` after a
|
|
288
|
+
component has already rendered does not reach that component, and it keeps showing its fallback
|
|
289
|
+
content while the children the host was given sit beside it as stray markup. Development names it
|
|
290
|
+
when it happens, but the rule is cheaper than the diagnostic: wire it in the same call as the
|
|
291
|
+
renderer, `wire([renderer, slots])`.
|
|
292
|
+
|
|
286
293
|
Given this markup:
|
|
287
294
|
|
|
288
295
|
```html
|
|
@@ -649,6 +656,70 @@ Keys are strings carrying sigils, so TypeScript cannot check them against the el
|
|
|
649
656
|
That is a genuine step down from written bindings, and the trade for names that are not known until
|
|
650
657
|
runtime.
|
|
651
658
|
|
|
659
|
+
### `props()` — a typed bag of property bindings
|
|
660
|
+
|
|
661
|
+
For the common case where every key is a **property**, `props()` removes both the sigils and the
|
|
662
|
+
typing gap:
|
|
663
|
+
|
|
664
|
+
```js
|
|
665
|
+
import { props } from '@verajs/renderer/spread';
|
|
666
|
+
|
|
667
|
+
html`<calendar-day ${props({ date, events })}></calendar-day>`
|
|
668
|
+
```
|
|
669
|
+
|
|
670
|
+
```jsx
|
|
671
|
+
<calendar-day {...props({ date, events })}></calendar-day>
|
|
672
|
+
<calendar-day date={date} events={events} /> // JSX only: bare props ARE props on a component tag
|
|
673
|
+
```
|
|
674
|
+
|
|
675
|
+
One function, both surfaces — JSX compiles `{...x}` to `spread(x)`, and `spread()` recognises an
|
|
676
|
+
already-branded result, so the two spellings are literally the same call. In JSX the bag is
|
|
677
|
+
optional altogether: on a dash-named tag a bare prop compiles to the `.name` binding directly
|
|
678
|
+
(`@verajs/jsx`'s README has the two attribute carve-outs), so `props()` is the template's
|
|
679
|
+
spelling and the bag for names not known until runtime. It exists because an
|
|
680
|
+
attribute is always a string: an array, a `Date` or a store can only reach a custom element as a
|
|
681
|
+
property — and while vera's JSX accepts the sigil spelling `.date={d}`, TSX's type-checker refuses
|
|
682
|
+
it (TS1003), so the bag is the typed path.
|
|
683
|
+
|
|
684
|
+
Three rules, each earned:
|
|
685
|
+
|
|
686
|
+
- **Keys are property names, never sigils** — `props({ date })` binds `.date`. Events and boolean
|
|
687
|
+
attributes keep their own spellings (`@click`/`onClick`, `?disabled`); this bag is properties
|
|
688
|
+
only, by definition.
|
|
689
|
+
- **Prefer keys spelled conditionally over bags that change shape**:
|
|
690
|
+
`props({ date: loaded ? date : null })` — key present from the first render — over
|
|
691
|
+
`props(loaded ? { date } : {})`. Both work (a key that appears later on a component is adopted
|
|
692
|
+
live, and one that disappears restores what the element held), but a stable shape means values
|
|
693
|
+
update in place, the same reason templates prefer `?hidden` over swapped subtrees.
|
|
694
|
+
- **A type argument makes the bag checked**: `props<CalendarDay>({ dat })` is a compile error
|
|
695
|
+
naming the misspelling — the checking that sigil-keyed spread genuinely cannot have.
|
|
696
|
+
|
|
697
|
+
### How a component receives them
|
|
698
|
+
|
|
699
|
+
Nothing to declare on the other side — no `static properties`, no props argument. A component that
|
|
700
|
+
calls `init()` finds every bound property on `this`, **reactively**: reading `this.date` in a
|
|
701
|
+
render tracks it, the parent's next commit re-renders, and a store or `ref()` passed through stays
|
|
702
|
+
live because it arrives by identity. The full reception contract — including what happens when the
|
|
703
|
+
component's module loads *after* the parent rendered — is documented with `init()` in
|
|
704
|
+
`@verajs/core`'s README; this package's half is the delivery:
|
|
705
|
+
|
|
706
|
+
- **A property is not an attribute.** `date="…"` is an attribute — always a string, visible in
|
|
707
|
+
markup. `.date=${…}`/`props({ date })` is a property — any value, by identity, invisible to
|
|
708
|
+
`getAttribute`. Components receive **properties**; attributes are for CSS hooks and static
|
|
709
|
+
markup.
|
|
710
|
+
- **Delivery survives lazy definition.** A property bound before the element's module runs would
|
|
711
|
+
otherwise be destroyed by the class's field initializers at upgrade (at ES2022,
|
|
712
|
+
`item?: T` emits a real `item;` that runs during upgrade). The renderer records what nothing
|
|
713
|
+
received yet, and `init()` re-applies it — so a bound value outranks a class default, in both
|
|
714
|
+
field spellings. Elements that never call `init()` keep the development warning and the
|
|
715
|
+
`declare` advice instead.
|
|
716
|
+
- **Platform and foreign elements are untouched.** A property with an accessor anywhere —
|
|
717
|
+
`.title`, a Lit-style element, anything that already receives it — is delivered plainly and
|
|
718
|
+
never recorded.
|
|
719
|
+
- **SSR delivers, never serializes.** Under `@verajs/ssr`, a property bound on a rendered
|
|
720
|
+
component tag reaches that child's server render by identity — the markup never carries it, and
|
|
721
|
+
an unregistered tag passes through for the client to handle.
|
|
722
|
+
|
|
652
723
|
### Removing a key
|
|
653
724
|
|
|
654
725
|
A key that disappears between renders **restores what the element held before the binding existed**.
|
|
@@ -688,7 +759,7 @@ a pair of totals — the totals move with every change to this package and the d
|
|
|
688
759
|
which is the mistake this line already made once. `llms.txt` and this file disagreed about the figure
|
|
689
760
|
for a while, at 16 B and 8 B respectively, and both were wrong. Nothing regenerates it, so it is
|
|
690
761
|
dated; re-measure the same way if it matters.
|
|
691
|
-
The entry itself is **<!--size:spread.gzip-->1.
|
|
762
|
+
The entry itself is **<!--size:spread.gzip-->1.60 KB<!--/size:spread.gzip-->** gzipped, and only apps
|
|
692
763
|
that import it pay for that.
|
|
693
764
|
|
|
694
765
|
Runtime is at parity with writing the bindings out: both do one comparison per binding per render,
|
|
@@ -730,7 +801,17 @@ each other in the same corner, and the second one's teardown would stop profilin
|
|
|
730
801
|
which kept repainting a frozen report.
|
|
731
802
|
|
|
732
803
|
Full API: `startProfiling()`, `stopProfiling()`, `getReport()`, `isProfiling()`, `profile(fn)`,
|
|
733
|
-
`formatReport(report)`, `showProfiler(options?)`.
|
|
804
|
+
`formatReport(report)`, `showProfiler(options?)`. The first four are `profile()` unrolled, for a
|
|
805
|
+
session that does not fit one callback — a long-running tab, a REPL:
|
|
806
|
+
|
|
807
|
+
```js
|
|
808
|
+
import { startProfiling, stopProfiling, getReport, isProfiling, formatReport } from '@verajs/renderer/profiler';
|
|
809
|
+
|
|
810
|
+
startProfiling();
|
|
811
|
+
// … interact with the app for as long as you like …
|
|
812
|
+
if (isProfiling()) console.log(formatReport(getReport())); // read mid-flight without stopping
|
|
813
|
+
stopProfiling(); // freezes the report
|
|
814
|
+
```
|
|
734
815
|
|
|
735
816
|
This costs production nothing, and there is nothing to strip: the instrumentation sits behind a
|
|
736
817
|
`__DEV__` constant the build folds to `false`, so `vera-renderer.min.js` is byte-identical whether
|
|
@@ -830,7 +911,7 @@ life of three defects.
|
|
|
830
911
|
writing tests for it.
|
|
831
912
|
- HTML only. There is no `svg`/`mathml` equivalent yet.
|
|
832
913
|
|
|
833
|
-
<!--size:tag.gzip-->
|
|
914
|
+
<!--size:tag.gzip-->2.20 KB<!--/size:tag.gzip--> gzipped, which includes `/spread` — the factory
|
|
834
915
|
needs it to apply props whose names it cannot know. Additive, like `/spread` and unlike the other
|
|
835
916
|
entries: it inlines no renderer internals, so it is safe alongside any of them.
|
|
836
917
|
|
|
@@ -839,7 +920,14 @@ They are the table this entry uses to map React's names, and `@verajs/jsx` carri
|
|
|
839
920
|
deliberately — the two are build-time and runtime, and a shared package would be a dependency where
|
|
840
921
|
a test does the job. `tests/jsx-name-mapping.test.mjs` asserts the two agree on every key, and it can
|
|
841
922
|
only do that against the built artifact, which is why they are exported at all. Read them if you are
|
|
842
|
-
writing something that has to agree with both; do not build on them
|
|
923
|
+
writing something that has to agree with both; do not build on them:
|
|
924
|
+
|
|
925
|
+
```js
|
|
926
|
+
import { jsxName, BOOLEAN_ATTRIBUTES } from '@verajs/renderer/tag';
|
|
927
|
+
|
|
928
|
+
jsxName('className'); // 'class' — the runtime half of the React-name mapping
|
|
929
|
+
BOOLEAN_ATTRIBUTES.has('disabled'); // true — the names the tag entry toggles rather than assigns
|
|
930
|
+
```
|
|
843
931
|
|
|
844
932
|
## Extending it — `_$apply$` and `_$child$`
|
|
845
933
|
|
|
@@ -980,7 +1068,7 @@ Directives other renderers ship, and what replaces them here.
|
|
|
980
1068
|
| `ifDefined()` | built in — `null`/`undefined` remove an attribute |
|
|
981
1069
|
| `classMap()` / `styleMap()` | build the string: `class="base ${extra}"` |
|
|
982
1070
|
| `guard()` | reactivity already skips unchanged work |
|
|
983
|
-
| `until()`, `asyncReplace()` | render a loading state and re-render from an effect — or nine lines against [`_$child$`](#extending-it--
|
|
1071
|
+
| `until()`, `asyncReplace()` | render a loading state and re-render from an effect — or nine lines against [`_$child$`](#extending-it--_apply-and-_child) |
|
|
984
1072
|
| `unsafeHTML()` | `.innerHTML=${trusted}`, above |
|
|
985
1073
|
| `literal()` / `static-html` | [`/tag`](#verajsrenderertag) — and a tag doubles as a JSX component |
|
|
986
1074
|
| `live()` | [`!name`](#name--a-live-property) — a sigil, for the case that needs it |
|
|
@@ -800,6 +800,143 @@ const LIVE = 3;
|
|
|
800
800
|
const EVENT = 4; // @name
|
|
801
801
|
/** A binding that must never write — see the `__proto__` refusal in the constructor. */
|
|
802
802
|
const REFUSED = -1;
|
|
803
|
+
/** `.name` on a custom element nothing receives yet — records into `_$props$`, then becomes
|
|
804
|
+
* `PROPERTY`. A distinct kind keeps the steady-state property path free of any adoption check. */
|
|
805
|
+
const PROP_ADOPT = 6;
|
|
806
|
+
/**
|
|
807
|
+
* The `PROP_ADOPT` commit, kept OUT of `_commit` so that function's size — and the JIT layout of
|
|
808
|
+
* its hot `PROPERTY`/`ATTR` branches — is unchanged from before this feature. `_commit` carries one
|
|
809
|
+
* dispatch line; all of this lives here, off every part's steady state.
|
|
810
|
+
*
|
|
811
|
+
* One question decides everything: **after the write, does anything receive this property?** An
|
|
812
|
+
* accessor anywhere on the chain — the platform's own (`title`, `hidden`), a component's declared
|
|
813
|
+
* one, or the pair core's `init()` defines — means the write just landed in real hands: no record,
|
|
814
|
+
* and the part rejoins `PROPERTY` for good. The walk is one step when the write created an own data
|
|
815
|
+
* property (nobody consumed it) and stops at the first descriptor either way, and it is what keeps
|
|
816
|
+
* a platform property on a lazy tag out of the record — recording `.title` would end with the drain
|
|
817
|
+
* shadowing `HTMLElement.prototype.title` and breaking it.
|
|
818
|
+
*
|
|
819
|
+
* An unreceived write is recorded under the sigiled expando **`_$props$`**, because two arrival
|
|
820
|
+
* orders both need it: on a LAZY tag the value sits as a plain own property that the class's field
|
|
821
|
+
* initializers will overwrite at upgrade (the clobber the `PROPERTY` branch only *detects*), and on
|
|
822
|
+
* an EAGER one the value survives but is indistinguishable from the component's own fields by the
|
|
823
|
+
* time `init()` runs. The record answers both — core's `init()` drains it, re-applying values
|
|
824
|
+
* unconditionally, which repairs BOTH spellings of the clobber (`item;` and `item = default`): it
|
|
825
|
+
* never asks whether a clobber happened, it asserts a bound value outranks a class default, which
|
|
826
|
+
* is what props mean. Element-carried because `./spread.ts` writes the same properties from a
|
|
827
|
+
* separate bundle with no shared registry — the `_$`-sigiled member is the cross-bundle channel,
|
|
828
|
+
* and the recorder there is this one's deliberate twin.
|
|
829
|
+
*
|
|
830
|
+
* Returns the part's NEXT kind: `PROPERTY` once something receives the property or the element is
|
|
831
|
+
* upgraded (its record is final — `init()` drains it in the same tick) or has no realm; `REFUSED`
|
|
832
|
+
* for a getter with no setter, so the binding goes inert instead of the flipped plain write
|
|
833
|
+
* throwing on the next commit; `0` to stay adopting — a dash-named element that never upgrades and
|
|
834
|
+
* never receives keeps recording, so its record stays current rather than staling. The one
|
|
835
|
+
* retention this leaves: a defined non-vera element with a plain data property keeps its FIRST
|
|
836
|
+
* committed values in `_$props$` for its lifetime — bounded, one generation, and the part itself
|
|
837
|
+
* already retains the current generation in `_committed`.
|
|
838
|
+
*/
|
|
839
|
+
const commitAdopt = (element, name, value) => {
|
|
840
|
+
const el = element;
|
|
841
|
+
/**
|
|
842
|
+
* The walk comes BEFORE the write, because what the walk finds decides whether writing is even
|
|
843
|
+
* legal: a SETTER receives the value (and a setter that throws is the component's own error), a
|
|
844
|
+
* GETTER with no setter cannot — the old order assigned first, which in strict mode threw a raw
|
|
845
|
+
* TypeError out of the render for the eager spelling of exactly the case the drain refuses by
|
|
846
|
+
* name for the lazy one. Same contested state, one rule, both arrival orders — and the server's
|
|
847
|
+
* `deliverProperty` applies it too. The dev warning defers to `_$adopt$` where it exists: an
|
|
848
|
+
* initialized component's drain already speaks, and two voices for one binding is noise.
|
|
849
|
+
*/
|
|
850
|
+
let carrier = el;
|
|
851
|
+
while (carrier !== null) {
|
|
852
|
+
const desc = Object.getOwnPropertyDescriptor(carrier, name);
|
|
853
|
+
if (desc !== undefined) {
|
|
854
|
+
if (desc.set !== undefined) {
|
|
855
|
+
el[name] = value;
|
|
856
|
+
return PROPERTY;
|
|
857
|
+
}
|
|
858
|
+
if (desc.get !== undefined) {
|
|
859
|
+
/** An initialized component's receiver owns the refusal (and its channel); for anything
|
|
860
|
+
* else this is the only door, so it says so itself. Either way the binding goes INERT —
|
|
861
|
+
* flipping to `PROPERTY` would make the next commit's plain write throw. */
|
|
862
|
+
if (el._$adopt$ !== undefined)
|
|
863
|
+
el._$adopt$(name, value);
|
|
864
|
+
else if (true )
|
|
865
|
+
console.warn(`[vera] renderer: <${element.localName}> declares \`${name}\` as a getter with no ` +
|
|
866
|
+
`setter — the value bound by \`.${name}=\${…}\` cannot be delivered and the binding ` +
|
|
867
|
+
`is ignored. Add a setter, or stop binding it.`);
|
|
868
|
+
return REFUSED;
|
|
869
|
+
}
|
|
870
|
+
break; // a data property — an own field, or an inherited default: nothing receives it
|
|
871
|
+
}
|
|
872
|
+
carrier = Object.getPrototypeOf(carrier);
|
|
873
|
+
}
|
|
874
|
+
el[name] = value;
|
|
875
|
+
/**
|
|
876
|
+
* An initialized component receives LIVE: `init()` left `_$adopt$` on the element, and a key it
|
|
877
|
+
* has not adopted yet goes through that door — a record here would never be read again, because
|
|
878
|
+
* the drain already ran. This is how a hydrated child gets the props its parent commits after
|
|
879
|
+
* the child settled, and how a spread bag's conditional key arrives reactive on a live element.
|
|
880
|
+
*/
|
|
881
|
+
if (el._$adopt$ !== undefined) {
|
|
882
|
+
el._$adopt$(name, value);
|
|
883
|
+
return PROPERTY;
|
|
884
|
+
}
|
|
885
|
+
const record = (el._$props$ ??= {});
|
|
886
|
+
const firstRecording = !Object.hasOwn(record, name);
|
|
887
|
+
record[name] = value;
|
|
888
|
+
/**
|
|
889
|
+
* Upgrade is read off the PROTOTYPE, never off `el.constructor`: a spread bag's keys are runtime
|
|
890
|
+
* data, so a bag carrying a key named `constructor` writes an own property that shadows the real
|
|
891
|
+
* one, and a check that reads it would then misjudge every later commit. No property write can
|
|
892
|
+
* move an element's prototype — the one assignment that could, `__proto__`, both twins refuse.
|
|
893
|
+
* The realm comes from the element, as always.
|
|
894
|
+
*/
|
|
895
|
+
const win = element.ownerDocument.defaultView;
|
|
896
|
+
const upgraded = win === null || Object.getPrototypeOf(el) !== win.HTMLElement.prototype;
|
|
897
|
+
/**
|
|
898
|
+
* **The clobber detector, for the element the drain will never reach.** A component that calls
|
|
899
|
+
* `init()` has the record re-applied, so for it the pre-upgrade window is repaired; an element
|
|
900
|
+
* that never drains — a plain custom element with a class field — still loses the bound value to
|
|
901
|
+
* the field initializer at upgrade, exactly as before this feature, and still deserves the
|
|
902
|
+
* warning. Told apart by OWNERSHIP, not by value: after the definition arrives (and, for a
|
|
903
|
+
* connected element, `connectedCallback` and the drain have run synchronously inside `define()`),
|
|
904
|
+
* an own accessor means the drain took the property and there is nothing to report. Identity
|
|
905
|
+
* against the COMMITTED value would lie twice — a drained value reads back through the store's
|
|
906
|
+
* proxy, and a value superseded by a later pre-upgrade commit differs without anything being
|
|
907
|
+
* wrong — so the comparison is against the RECORD, which later recordings keep current, and the
|
|
908
|
+
* subscription is installed once per (element, property), on the first recording. The registry
|
|
909
|
+
* is the element's own realm's. Development only; production carries no check, no message, no
|
|
910
|
+
* `whenDefined` subscription.
|
|
911
|
+
*/
|
|
912
|
+
if (true && win !== null && !upgraded && firstRecording) {
|
|
913
|
+
const tag = element.localName;
|
|
914
|
+
win.customElements.whenDefined(tag).then(() => {
|
|
915
|
+
/** Ownership is asked of the whole CHAIN: the drain's own accessor, a class's prototype
|
|
916
|
+
* pair the value was handed to, or a get-only surface the drain refused by name — every
|
|
917
|
+
* one means the property has an owner and this closure has nothing left to report. */
|
|
918
|
+
let carrier = el;
|
|
919
|
+
let owned = false;
|
|
920
|
+
while (carrier !== null) {
|
|
921
|
+
const desc = Object.getOwnPropertyDescriptor(carrier, name);
|
|
922
|
+
if (desc !== undefined) {
|
|
923
|
+
owned = desc.get !== undefined || desc.set !== undefined;
|
|
924
|
+
break;
|
|
925
|
+
}
|
|
926
|
+
carrier = Object.getPrototypeOf(carrier);
|
|
927
|
+
}
|
|
928
|
+
if (!owned && el[name] !== record[name])
|
|
929
|
+
console.warn(`[vera] renderer: the value bound by \`.${name}=\${…}\` on <${tag}> was replaced ` +
|
|
930
|
+
`while the element upgraded. A class field is the usual cause: at ES2022 ` +
|
|
931
|
+
`\`${name}?: …\` emits \`${name};\`, which runs during upgrade and overwrites ` +
|
|
932
|
+
`whatever was set beforehand — write it \`declare ${name}?: …\` instead, which ` +
|
|
933
|
+
`emits nothing. A component that calls init() adopts bound properties automatically ` +
|
|
934
|
+
`and never sees this; this element did not. Ignore this if the component replaced ` +
|
|
935
|
+
`the value on purpose.`);
|
|
936
|
+
});
|
|
937
|
+
}
|
|
938
|
+
return upgraded ? PROPERTY : 0;
|
|
939
|
+
};
|
|
803
940
|
/**
|
|
804
941
|
* Calls an element ref, and survives one that throws.
|
|
805
942
|
*
|
|
@@ -890,6 +1027,19 @@ class AttrPart {
|
|
|
890
1027
|
kind = EVENT;
|
|
891
1028
|
realName = name.slice(2).toLowerCase();
|
|
892
1029
|
}
|
|
1030
|
+
/**
|
|
1031
|
+
* **A property write to a custom element starts as `PROP_ADOPT`**, a distinct kind so the
|
|
1032
|
+
* steady-state `PROPERTY` commit path stays byte-for-byte unchanged — zero added instruction
|
|
1033
|
+
* for every `.value=` on a built-in. Every dash-named element starts here, defined or not,
|
|
1034
|
+
* because the record has to exist for BOTH arrival orders: an eager component's first commit
|
|
1035
|
+
* lands after upgrade but before `init()` (one commit records, then the part flips), and a
|
|
1036
|
+
* lazy one's land before upgrade (the part records until the definition arrives). `commitAdopt`
|
|
1037
|
+
* decides which per commit and flips the part back to `PROPERTY` the moment something real
|
|
1038
|
+
* receives the property, so the window is one commit for a defined element and the pre-upgrade
|
|
1039
|
+
* stretch for a lazy one.
|
|
1040
|
+
*/
|
|
1041
|
+
if (kind === PROPERTY && element.localName.includes('-'))
|
|
1042
|
+
kind = PROP_ADOPT;
|
|
893
1043
|
this._kind = kind;
|
|
894
1044
|
this._name = realName;
|
|
895
1045
|
this._element = element;
|
|
@@ -1002,13 +1152,29 @@ class AttrPart {
|
|
|
1002
1152
|
if (kind === LIVE) {
|
|
1003
1153
|
this._committed = value;
|
|
1004
1154
|
/**
|
|
1005
|
-
* **Except while adopting.** Hydration reaches a DOM a person may
|
|
1006
|
-
* click that checked a radio happened before any handler existed
|
|
1007
|
-
* so re-asserting the server's choice here would throw the
|
|
1008
|
-
* ever put it back. Recorded, not written, exactly as
|
|
1009
|
-
* first state-driven render after that applies live
|
|
1155
|
+
* **Except while adopting — on a form control.** Hydration reaches a DOM a person may
|
|
1156
|
+
* already have used, and the click that checked a radio happened before any handler existed
|
|
1157
|
+
* to tell the store about it — so re-asserting the server's choice here would throw the
|
|
1158
|
+
* interaction away and nothing would ever put it back. Recorded, not written, exactly as
|
|
1159
|
+
* the other form properties are; the first state-driven render after that applies live
|
|
1160
|
+
* semantics normally.
|
|
1161
|
+
*
|
|
1162
|
+
* **A COMPONENT tag is the exception to the exception**: there is no user-editable carrier
|
|
1163
|
+
* behind `!prop` on a component — it is a property delivery spelled with `!` — and the
|
|
1164
|
+
* server DELIVERED it to the child's render, so yielding here dropped the one copy the
|
|
1165
|
+
* client would ever get and hydration regressed the child's content to its prop-less state.
|
|
1166
|
+
* Found by the hydration fixture on its first run. The write is unconditional and routes
|
|
1167
|
+
* through the element like any component prop: an accessor receives it, an initialized
|
|
1168
|
+
* component adopts it live.
|
|
1010
1169
|
*/
|
|
1011
|
-
if (
|
|
1170
|
+
if (true && adopting) {
|
|
1171
|
+
/** Routed through `commitAdopt`, not written raw: the child hydrated BEFORE this commit,
|
|
1172
|
+
* so only the adoption door re-runs its render. The part stays `LIVE` — the return is
|
|
1173
|
+
* deliberately dropped — so live semantics resume on the next state-driven render. */
|
|
1174
|
+
if (this._element.localName.includes('-'))
|
|
1175
|
+
commitAdopt(this._element, this._name, value);
|
|
1176
|
+
}
|
|
1177
|
+
else {
|
|
1012
1178
|
const liveTarget = this._element;
|
|
1013
1179
|
if (liveTarget[this._name] !== value)
|
|
1014
1180
|
liveTarget[this._name] = value;
|
|
@@ -1088,52 +1254,16 @@ class AttrPart {
|
|
|
1088
1254
|
this._committed = value;
|
|
1089
1255
|
return index + this._slots;
|
|
1090
1256
|
}
|
|
1091
|
-
target[name] = value;
|
|
1092
1257
|
/**
|
|
1093
|
-
*
|
|
1094
|
-
*
|
|
1095
|
-
*
|
|
1096
|
-
*
|
|
1097
|
-
*
|
|
1098
|
-
*
|
|
1099
|
-
*
|
|
1100
|
-
* it reads as broken reactivity.
|
|
1101
|
-
*
|
|
1102
|
-
* Repairing it was tried and removed. Re-applying when the slot came back `undefined`
|
|
1103
|
-
* covered `item?: T` but not `item = someDefault`, which overwrites with the default and
|
|
1104
|
-
* never looks clobbered — so the repair was silently partial, and made the bug intermittent
|
|
1105
|
-
* across two spellings of the same mistake. It also cost 74 B in every app while leaving
|
|
1106
|
-
* `declare` mandatory anyway, because a property assigned imperatively is unrecoverable:
|
|
1107
|
-
* the renderer never saw it, and by the time `init()` runs the value is already gone.
|
|
1108
|
-
*
|
|
1109
|
-
* So this is `true `-only and production pays nothing — no check, no message, no
|
|
1110
|
-
* `whenDefined` subscription. Lit reached the same place from the other direction and
|
|
1111
|
-
* throws (`lit.dev/msg/class-field-shadowing`); a warning suffices here because Vera has no
|
|
1112
|
-
* prototype accessors to shadow permanently — the damage is one lost value, not a property
|
|
1113
|
-
* that never updates again.
|
|
1258
|
+
* No un-upgraded custom element can be behind this write: a dash-named property part is
|
|
1259
|
+
* born `PROP_ADOPT` and only flips here once something receives the property, so the
|
|
1260
|
+
* pre-upgrade window — the clobber, its repair for components, and the `whenDefined`
|
|
1261
|
+
* detector for elements that never drain — lives entirely in `commitAdopt` above. History
|
|
1262
|
+
* worth keeping: an earlier repair was tried HERE and removed as silently partial (it
|
|
1263
|
+
* re-applied on `undefined`, so `item = someDefault` never looked clobbered); the record
|
|
1264
|
+
* the drain re-applies unconditionally is what answered that objection.
|
|
1114
1265
|
*/
|
|
1115
|
-
|
|
1116
|
-
const tag = this._element.localName;
|
|
1117
|
-
if (tag.indexOf('-') > 0 && !customElements.get(tag)) {
|
|
1118
|
-
customElements.whenDefined(tag).then(() => {
|
|
1119
|
-
/**
|
|
1120
|
-
* States what was observed rather than diagnosing it. A class field is the usual
|
|
1121
|
-
* cause by a wide margin, but a component that assigns the property itself during
|
|
1122
|
-
* upgrade produces the same observation, and that is a legitimate — if confusing —
|
|
1123
|
-
* thing to do, since the renderer's dirty check will not re-apply the bound value on
|
|
1124
|
-
* the next render either.
|
|
1125
|
-
*/
|
|
1126
|
-
if (target[name] !== value)
|
|
1127
|
-
console.warn(`[vera] renderer: the value bound by \`.${name}=\${…}\` on <${tag}> was replaced ` +
|
|
1128
|
-
`while the element upgraded. A class field is the usual cause: at ES2022 ` +
|
|
1129
|
-
`\`${name}?: …\` emits \`${name};\`, which runs during upgrade and overwrites ` +
|
|
1130
|
-
`whatever was set beforehand — write it \`declare ${name}?: …\` instead, which ` +
|
|
1131
|
-
`emits nothing. A plain field also wipes properties assigned imperatively, ` +
|
|
1132
|
-
`which cannot be detected at all. Ignore this if the component replaced the ` +
|
|
1133
|
-
`value on purpose.`);
|
|
1134
|
-
});
|
|
1135
|
-
}
|
|
1136
|
-
}
|
|
1266
|
+
target[name] = value;
|
|
1137
1267
|
}
|
|
1138
1268
|
else if (kind === BOOLEAN) {
|
|
1139
1269
|
/** Unconditional for the same reason: `<b hidden ?hidden=${false}>` must end up not hidden. */
|
|
@@ -1160,6 +1290,11 @@ class AttrPart {
|
|
|
1160
1290
|
this._element.addEventListener(this._name, this);
|
|
1161
1291
|
this._handler = value ?? null;
|
|
1162
1292
|
}
|
|
1293
|
+
else if (kind === PROP_ADOPT) {
|
|
1294
|
+
const next = commitAdopt(this._element, this._name, value);
|
|
1295
|
+
if (next !== 0)
|
|
1296
|
+
this._kind = next;
|
|
1297
|
+
}
|
|
1163
1298
|
else if (value != null) {
|
|
1164
1299
|
/**
|
|
1165
1300
|
* Element ref: `<input ${myRef} />`. A function is called with the element; an object gets
|