lwc 2.11.0 → 2.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/engine-dom/esm/es2017/engine-dom.js +309 -263
  2. package/dist/engine-dom/iife/es2017/engine-dom.js +309 -263
  3. package/dist/engine-dom/iife/es2017/engine-dom.min.js +1 -1
  4. package/dist/engine-dom/iife/es2017/engine-dom_debug.js +264 -126
  5. package/dist/engine-dom/iife/es5/engine-dom.js +1104 -1047
  6. package/dist/engine-dom/iife/es5/engine-dom.min.js +1 -1
  7. package/dist/engine-dom/iife/es5/engine-dom_debug.js +391 -181
  8. package/dist/engine-dom/umd/es2017/engine-dom.js +309 -263
  9. package/dist/engine-dom/umd/es2017/engine-dom.min.js +1 -1
  10. package/dist/engine-dom/umd/es2017/engine-dom_debug.js +264 -126
  11. package/dist/engine-dom/umd/es5/engine-dom.js +1104 -1047
  12. package/dist/engine-dom/umd/es5/engine-dom.min.js +1 -1
  13. package/dist/engine-dom/umd/es5/engine-dom_debug.js +391 -181
  14. package/dist/engine-server/commonjs/es2017/engine-server.js +14 -11
  15. package/dist/engine-server/commonjs/es2017/engine-server.min.js +1 -1
  16. package/dist/engine-server/esm/es2017/engine-server.js +14 -11
  17. package/dist/synthetic-shadow/esm/es2017/synthetic-shadow.js +3 -3
  18. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.js +3 -3
  19. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow_debug.js +3 -3
  20. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.js +3 -3
  21. package/dist/synthetic-shadow/iife/es5/synthetic-shadow_debug.js +3 -3
  22. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.js +3 -3
  23. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow_debug.js +3 -3
  24. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.js +3 -3
  25. package/dist/synthetic-shadow/umd/es5/synthetic-shadow_debug.js +3 -3
  26. package/dist/wire-service/esm/es2017/wire-service.js +2 -2
  27. package/dist/wire-service/iife/es2017/wire-service.js +2 -2
  28. package/dist/wire-service/iife/es2017/wire-service_debug.js +2 -2
  29. package/dist/wire-service/iife/es5/wire-service.js +2 -2
  30. package/dist/wire-service/iife/es5/wire-service_debug.js +2 -2
  31. package/dist/wire-service/umd/es2017/wire-service.js +2 -2
  32. package/dist/wire-service/umd/es2017/wire-service_debug.js +2 -2
  33. package/dist/wire-service/umd/es5/wire-service.js +2 -2
  34. package/dist/wire-service/umd/es5/wire-service_debug.js +2 -2
  35. package/package.json +10 -10
@@ -120,7 +120,6 @@ var LWC = (function (exports) {
120
120
  setPrototypeOf = Object.setPrototypeOf;
121
121
  var isArray$1 = Array.isArray;
122
122
  var _Array$prototype = Array.prototype,
123
- ArrayFilter = _Array$prototype.filter,
124
123
  ArrayIndexOf = _Array$prototype.indexOf,
125
124
  ArrayJoin = _Array$prototype.join,
126
125
  ArrayMap = _Array$prototype.map,
@@ -360,9 +359,9 @@ var LWC = (function (exports) {
360
359
  */
361
360
  // Increment whenever the LWC template compiler changes
362
361
 
363
- var LWC_VERSION = "2.11.0";
362
+ var LWC_VERSION = "2.12.0";
364
363
  var LWC_VERSION_COMMENT_REGEX = /\/\*LWC compiler v([\d.]+)\*\/\s*}/;
365
- /** version: 2.11.0 */
364
+ /** version: 2.12.0 */
366
365
 
367
366
  /*
368
367
  * Copyright (c) 2018, salesforce.com, inc.
@@ -540,7 +539,7 @@ var LWC = (function (exports) {
540
539
  setFeatureFlag(name, value);
541
540
  }
542
541
  }
543
- /** version: 2.11.0 */
542
+ /** version: 2.12.0 */
544
543
 
545
544
  /* proxy-compat-disable */
546
545
 
@@ -6419,16 +6418,20 @@ var LWC = (function (exports) {
6419
6418
  * will prevent this function from being imported by userland code.
6420
6419
  */
6421
6420
 
6422
- function registerComponent(Ctor, _ref2) {
6421
+ function registerComponent( // We typically expect a LightningElementConstructor, but technically you can call this with anything
6422
+ Ctor, _ref2) {
6423
6423
  var tmpl = _ref2.tmpl;
6424
6424
 
6425
- if (process.env.NODE_ENV !== 'production') {
6426
- checkVersionMismatch(Ctor, 'component');
6427
- }
6425
+ if (isFunction$1(Ctor)) {
6426
+ if (process.env.NODE_ENV !== 'production') {
6427
+ checkVersionMismatch(Ctor, 'component');
6428
+ }
6428
6429
 
6429
- signedTemplateMap.set(Ctor, tmpl); // chaining this method as a way to wrap existing assignment of component constructor easily,
6430
+ signedTemplateMap.set(Ctor, tmpl);
6431
+ } // chaining this method as a way to wrap existing assignment of component constructor easily,
6430
6432
  // without too much transformation
6431
6433
 
6434
+
6432
6435
  return Ctor;
6433
6436
  }
6434
6437
 
@@ -6540,1353 +6543,1405 @@ var LWC = (function (exports) {
6540
6543
  }
6541
6544
  }
6542
6545
  /*
6543
- * Copyright (c) 2022, salesforce.com, inc.
6546
+ * Copyright (c) 2018, salesforce.com, inc.
6544
6547
  * All rights reserved.
6545
6548
  * SPDX-License-Identifier: MIT
6546
6549
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6547
6550
  */
6548
6551
 
6549
6552
 
6550
- function hydrate(vnode, node) {
6551
- switch (vnode.type) {
6552
- case 0
6553
- /* Text */
6554
- :
6555
- hydrateText(vnode, node);
6556
- break;
6553
+ var idx = 0;
6554
+ /** The internal slot used to associate different objects the engine manipulates with the VM */
6557
6555
 
6558
- case 1
6559
- /* Comment */
6560
- :
6561
- hydrateComment(vnode, node);
6562
- break;
6556
+ var ViewModelReflection = new WeakMap();
6563
6557
 
6564
- case 2
6565
- /* Element */
6566
- :
6567
- hydrateElement(vnode, node);
6568
- break;
6558
+ function callHook(cmp, fn) {
6559
+ var args = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
6560
+ return fn.apply(cmp, args);
6561
+ }
6569
6562
 
6570
- case 3
6571
- /* CustomElement */
6572
- :
6573
- hydrateCustomElement(vnode, node);
6574
- break;
6575
- }
6563
+ function setHook(cmp, prop, newValue) {
6564
+ cmp[prop] = newValue;
6576
6565
  }
6577
6566
 
6578
- function hydrateText(vnode, node) {
6579
- var _a;
6567
+ function getHook(cmp, prop) {
6568
+ return cmp[prop];
6569
+ }
6580
6570
 
6581
- if (process.env.NODE_ENV !== 'production') {
6582
- validateNodeType(vnode, node, 3
6583
- /* TEXT */
6584
- );
6585
- var nodeValue = getProperty$1(node, 'nodeValue');
6571
+ function rerenderVM(vm) {
6572
+ rehydrate(vm);
6573
+ }
6586
6574
 
6587
- if (nodeValue !== vnode.text && !(nodeValue === "\u200D" && vnode.text === '')) {
6588
- logWarn('Hydration mismatch: text values do not match, will recover from the difference', vnode.owner);
6589
- }
6590
- } // always set the text value to the one from the vnode.
6575
+ function connectRootElement(elm) {
6576
+ var vm = getAssociatedVM(elm);
6577
+ logGlobalOperationStart(7
6578
+ /* GlobalHydrate */
6579
+ , vm); // Usually means moving the element from one place to another, which is observable via
6580
+ // life-cycle hooks.
6591
6581
 
6582
+ if (vm.state === 1
6583
+ /* connected */
6584
+ ) {
6585
+ disconnectRootElement(elm);
6586
+ }
6592
6587
 
6593
- setText$1(node, (_a = vnode.text) !== null && _a !== void 0 ? _a : null);
6594
- vnode.elm = node;
6588
+ runConnectedCallback(vm);
6589
+ rehydrate(vm);
6590
+ logGlobalOperationEnd(7
6591
+ /* GlobalHydrate */
6592
+ , vm);
6595
6593
  }
6596
6594
 
6597
- function hydrateComment(vnode, node) {
6598
- var _a;
6599
-
6600
- if (process.env.NODE_ENV !== 'production') {
6601
- validateNodeType(vnode, node, 8
6602
- /* COMMENT */
6603
- );
6604
-
6605
- if (getProperty$1(node, 'nodeValue') !== vnode.text) {
6606
- logWarn('Hydration mismatch: comment values do not match, will recover from the difference', vnode.owner);
6607
- }
6608
- } // always set the text value to the one from the vnode.
6595
+ function disconnectRootElement(elm) {
6596
+ var vm = getAssociatedVM(elm);
6597
+ resetComponentStateWhenRemoved(vm);
6598
+ }
6609
6599
 
6600
+ function appendVM(vm) {
6601
+ rehydrate(vm);
6602
+ } // just in case the component comes back, with this we guarantee re-rendering it
6603
+ // while preventing any attempt to rehydration until after reinsertion.
6610
6604
 
6611
- setProperty$1(node, 'nodeValue', (_a = vnode.text) !== null && _a !== void 0 ? _a : null);
6612
- vnode.elm = node;
6613
- }
6614
6605
 
6615
- function hydrateElement(vnode, node) {
6616
- if (process.env.NODE_ENV !== 'production') {
6617
- validateNodeType(vnode, node, 1
6618
- /* ELEMENT */
6619
- );
6620
- validateElement(vnode, node);
6621
- }
6606
+ function resetComponentStateWhenRemoved(vm) {
6607
+ var state = vm.state;
6622
6608
 
6623
- var elm = node;
6624
- vnode.elm = elm;
6625
- var context = vnode.data.context;
6626
- var isDomManual = Boolean(!isUndefined$1(context) && !isUndefined$1(context.lwc) && context.lwc.dom === "manual"
6627
- /* Manual */
6628
- );
6609
+ if (state !== 2
6610
+ /* disconnected */
6611
+ ) {
6612
+ var oar = vm.oar,
6613
+ tro = vm.tro; // Making sure that any observing record will not trigger the rehydrated on this vm
6629
6614
 
6630
- if (isDomManual) {
6631
- // it may be that this element has lwc:inner-html, we need to diff and in case are the same,
6632
- // remove the innerHTML from props so it reuses the existing dom elements.
6633
- var props = vnode.data.props;
6615
+ tro.reset(); // Making sure that any observing accessor record will not trigger the setter to be reinvoked
6634
6616
 
6635
- if (!isUndefined$1(props) && !isUndefined$1(props.innerHTML)) {
6636
- if (getProperty$1(elm, 'innerHTML') === props.innerHTML) {
6637
- // Do a shallow clone since VNodeData may be shared across VNodes due to hoist optimization
6638
- vnode.data = Object.assign(Object.assign({}, vnode.data), {
6639
- props: cloneAndOmitKey(props, 'innerHTML')
6640
- });
6641
- } else {
6642
- logWarn("Mismatch hydrating element <".concat(getProperty$1(elm, 'tagName').toLowerCase(), ">: innerHTML values do not match for element, will recover from the difference"), vnode.owner);
6643
- }
6617
+ for (var key in oar) {
6618
+ oar[key].reset();
6644
6619
  }
6645
- }
6646
6620
 
6647
- patchElementPropsAndAttrs(vnode);
6621
+ runDisconnectedCallback(vm); // Spec: https://dom.spec.whatwg.org/#concept-node-remove (step 14-15)
6648
6622
 
6649
- if (!isDomManual) {
6650
- hydrateChildren(getChildNodes$1(vnode.elm), vnode.children, vnode.owner);
6623
+ runChildNodesDisconnectedCallback(vm);
6624
+ runLightChildNodesDisconnectedCallback(vm);
6651
6625
  }
6652
- }
6653
6626
 
6654
- function hydrateCustomElement(vnode, node) {
6655
6627
  if (process.env.NODE_ENV !== 'production') {
6656
- validateNodeType(vnode, node, 1
6657
- /* ELEMENT */
6658
- );
6659
- validateElement(vnode, node);
6628
+ removeActiveVM(vm);
6660
6629
  }
6630
+ } // this method is triggered by the diffing algo only when a vnode from the
6631
+ // old vnode.children is removed from the DOM.
6661
6632
 
6662
- var elm = node;
6663
- var sel = vnode.sel,
6664
- mode = vnode.mode,
6665
- ctor = vnode.ctor,
6666
- owner = vnode.owner;
6667
- var vm = createVM(elm, ctor, {
6668
- mode: mode,
6669
- owner: owner,
6670
- tagName: sel
6671
- });
6672
- vnode.elm = elm;
6673
- vnode.vm = vm;
6674
- allocateChildren(vnode, vm);
6675
- patchElementPropsAndAttrs(vnode); // Insert hook section:
6676
6633
 
6634
+ function removeVM(vm) {
6677
6635
  if (process.env.NODE_ENV !== 'production') {
6678
- assert.isTrue(vm.state === 0
6679
- /* created */
6680
- , "".concat(vm, " cannot be recycled."));
6636
+ assert.isTrue(vm.state === 1
6637
+ /* connected */
6638
+ || vm.state === 2
6639
+ /* disconnected */
6640
+ , "".concat(vm, " must have been connected."));
6681
6641
  }
6682
6642
 
6683
- runConnectedCallback(vm);
6643
+ resetComponentStateWhenRemoved(vm);
6644
+ }
6684
6645
 
6685
- if (vm.renderMode !== 0
6646
+ function getNearestShadowAncestor(vm) {
6647
+ var ancestor = vm.owner;
6648
+
6649
+ while (!isNull(ancestor) && ancestor.renderMode === 0
6686
6650
  /* Light */
6687
6651
  ) {
6688
- // VM is not rendering in Light DOM, we can proceed and hydrate the slotted content.
6689
- // Note: for Light DOM, this is handled while hydrating the VM
6690
- hydrateChildren(getChildNodes$1(vnode.elm), vnode.children, vm);
6652
+ ancestor = ancestor.owner;
6691
6653
  }
6692
6654
 
6693
- hydrateVM(vm);
6655
+ return ancestor;
6694
6656
  }
6695
6657
 
6696
- function hydrateChildren(elmChildren, children, vm) {
6658
+ function createVM(elm, ctor, options) {
6659
+ var mode = options.mode,
6660
+ owner = options.owner,
6661
+ tagName = options.tagName;
6662
+ var def = getComponentInternalDef(ctor);
6663
+ var vm = {
6664
+ elm: elm,
6665
+ def: def,
6666
+ idx: idx++,
6667
+ state: 0
6668
+ /* created */
6669
+ ,
6670
+ isScheduled: false,
6671
+ isDirty: true,
6672
+ tagName: tagName,
6673
+ mode: mode,
6674
+ owner: owner,
6675
+ children: EmptyArray,
6676
+ aChildren: EmptyArray,
6677
+ velements: EmptyArray,
6678
+ cmpProps: create(null),
6679
+ cmpFields: create(null),
6680
+ cmpSlots: create(null),
6681
+ oar: create(null),
6682
+ cmpTemplate: null,
6683
+ renderMode: def.renderMode,
6684
+ context: {
6685
+ stylesheetToken: undefined,
6686
+ hasTokenInClass: undefined,
6687
+ hasTokenInAttribute: undefined,
6688
+ hasScopedStyles: undefined,
6689
+ styleVNode: null,
6690
+ tplCache: EmptyObject,
6691
+ wiredConnecting: EmptyArray,
6692
+ wiredDisconnecting: EmptyArray
6693
+ },
6694
+ // Properties set right after VM creation.
6695
+ tro: null,
6696
+ shadowMode: null,
6697
+ // Properties set by the LightningElement constructor.
6698
+ component: null,
6699
+ shadowRoot: null,
6700
+ renderRoot: null,
6701
+ callHook: callHook,
6702
+ setHook: setHook,
6703
+ getHook: getHook
6704
+ };
6705
+ vm.shadowMode = computeShadowMode(vm);
6706
+ vm.tro = getTemplateReactiveObserver(vm);
6707
+
6697
6708
  if (process.env.NODE_ENV !== 'production') {
6698
- var filteredVNodes = ArrayFilter.call(children, function (vnode) {
6699
- return !!vnode;
6700
- });
6709
+ vm.toString = function () {
6710
+ return "[object:vm ".concat(def.name, " (").concat(vm.idx, ")]");
6711
+ };
6701
6712
 
6702
- if (elmChildren.length !== filteredVNodes.length) {
6703
- logError("Hydration mismatch: incorrect number of rendered nodes, expected ".concat(filteredVNodes.length, " but found ").concat(elmChildren.length, "."), vm);
6704
- throwHydrationError();
6713
+ if (runtimeFlags.ENABLE_FORCE_NATIVE_SHADOW_MODE_FOR_TEST) {
6714
+ vm.shadowMode = 0
6715
+ /* Native */
6716
+ ;
6705
6717
  }
6706
- }
6718
+ } // Create component instance associated to the vm and the element.
6707
6719
 
6708
- var childNodeIndex = 0;
6709
6720
 
6710
- for (var _i23 = 0; _i23 < children.length; _i23++) {
6711
- var childVnode = children[_i23];
6721
+ invokeComponentConstructor(vm, def.ctor); // Initializing the wire decorator per instance only when really needed
6712
6722
 
6713
- if (!isNull(childVnode)) {
6714
- var childNode = elmChildren[childNodeIndex];
6715
- hydrate(childVnode, childNode);
6716
- childNodeIndex++;
6717
- }
6723
+ if (hasWireAdapters(vm)) {
6724
+ installWireAdapters(vm);
6718
6725
  }
6719
- }
6720
-
6721
- function patchElementPropsAndAttrs(vnode) {
6722
- applyEventListeners(vnode);
6723
- patchProps(null, vnode);
6724
- }
6725
6726
 
6726
- function throwHydrationError() {
6727
- assert.fail('Server rendered elements do not match client side generated elements');
6727
+ return vm;
6728
6728
  }
6729
6729
 
6730
- function validateNodeType(vnode, node, nodeType) {
6731
- if (getProperty$1(node, 'nodeType') !== nodeType) {
6732
- logError('Hydration mismatch: incorrect node type received', vnode.owner);
6733
- assert.fail('Hydration mismatch: incorrect node type received.');
6734
- }
6735
- }
6730
+ function computeShadowMode(vm) {
6731
+ var def = vm.def;
6732
+ var shadowMode;
6736
6733
 
6737
- function validateElement(vnode, elm) {
6738
- if (vnode.sel.toLowerCase() !== getProperty$1(elm, 'tagName').toLowerCase()) {
6739
- logError("Hydration mismatch: expecting element with tag \"".concat(vnode.sel.toLowerCase(), "\" but found \"").concat(getProperty$1(elm, 'tagName').toLowerCase(), "\"."), vnode.owner);
6740
- throwHydrationError();
6741
- }
6734
+ if (isSyntheticShadowDefined$1) {
6735
+ if (def.renderMode === 0
6736
+ /* Light */
6737
+ ) {
6738
+ // ShadowMode.Native implies "not synthetic shadow" which is consistent with how
6739
+ // everything defaults to native when the synthetic shadow polyfill is unavailable.
6740
+ shadowMode = 0
6741
+ /* Native */
6742
+ ;
6743
+ } else if (isNativeShadowDefined$1) {
6744
+ // Not combined with above condition because @lwc/features only supports identifiers in
6745
+ // the if-condition.
6746
+ if (runtimeFlags.ENABLE_MIXED_SHADOW_MODE) {
6747
+ if (def.shadowSupportMode === "any"
6748
+ /* Any */
6749
+ ) {
6750
+ shadowMode = 0
6751
+ /* Native */
6752
+ ;
6753
+ } else {
6754
+ var shadowAncestor = getNearestShadowAncestor(vm);
6742
6755
 
6743
- var hasIncompatibleAttrs = validateAttrs(vnode, elm);
6744
- var hasIncompatibleClass = validateClassAttr(vnode, elm);
6745
- var hasIncompatibleStyle = validateStyleAttr(vnode, elm);
6746
- var isVNodeAndElementCompatible = hasIncompatibleAttrs && hasIncompatibleClass && hasIncompatibleStyle;
6747
-
6748
- if (!isVNodeAndElementCompatible) {
6749
- throwHydrationError();
6756
+ if (!isNull(shadowAncestor) && shadowAncestor.shadowMode === 0
6757
+ /* Native */
6758
+ ) {
6759
+ // Transitive support for native Shadow DOM. A component in native mode
6760
+ // transitively opts all of its descendants into native.
6761
+ shadowMode = 0
6762
+ /* Native */
6763
+ ;
6764
+ } else {
6765
+ // Synthetic if neither this component nor any of its ancestors are configured
6766
+ // to be native.
6767
+ shadowMode = 1
6768
+ /* Synthetic */
6769
+ ;
6770
+ }
6771
+ }
6772
+ } else {
6773
+ shadowMode = 1
6774
+ /* Synthetic */
6775
+ ;
6776
+ }
6777
+ } else {
6778
+ // Synthetic if there is no native Shadow DOM support.
6779
+ shadowMode = 1
6780
+ /* Synthetic */
6781
+ ;
6782
+ }
6783
+ } else {
6784
+ // Native if the synthetic shadow polyfill is unavailable.
6785
+ shadowMode = 0
6786
+ /* Native */
6787
+ ;
6750
6788
  }
6789
+
6790
+ return shadowMode;
6751
6791
  }
6752
6792
 
6753
- function validateAttrs(vnode, elm) {
6754
- var _vnode$data$attrs = vnode.data.attrs,
6755
- attrs = _vnode$data$attrs === void 0 ? {} : _vnode$data$attrs;
6756
- var nodesAreCompatible = true; // Validate attributes, though we could always recovery from those by running the update mods.
6757
- // Note: intentionally ONLY matching vnodes.attrs to elm.attrs, in case SSR is adding extra attributes.
6793
+ function assertIsVM(obj) {
6794
+ if (isNull(obj) || !isObject(obj) || !('renderRoot' in obj)) {
6795
+ throw new TypeError("".concat(obj, " is not a VM."));
6796
+ }
6797
+ }
6758
6798
 
6759
- for (var _i24 = 0, _Object$entries = Object.entries(attrs); _i24 < _Object$entries.length; _i24++) {
6760
- var _Object$entries$_i = _slicedToArray(_Object$entries[_i24], 2),
6761
- attrName = _Object$entries$_i[0],
6762
- attrValue = _Object$entries$_i[1];
6799
+ function associateVM(obj, vm) {
6800
+ ViewModelReflection.set(obj, vm);
6801
+ }
6763
6802
 
6764
- var elmAttrValue = getAttribute$1(elm, attrName);
6803
+ function getAssociatedVM(obj) {
6804
+ var vm = ViewModelReflection.get(obj);
6765
6805
 
6766
- if (String(attrValue) !== elmAttrValue) {
6767
- logError("Mismatch hydrating element <".concat(getProperty$1(elm, 'tagName').toLowerCase(), ">: attribute \"").concat(attrName, "\" has different values, expected \"").concat(attrValue, "\" but found \"").concat(elmAttrValue, "\""), vnode.owner);
6768
- nodesAreCompatible = false;
6769
- }
6806
+ if (process.env.NODE_ENV !== 'production') {
6807
+ assertIsVM(vm);
6770
6808
  }
6771
6809
 
6772
- return nodesAreCompatible;
6810
+ return vm;
6773
6811
  }
6774
6812
 
6775
- function validateClassAttr(vnode, elm) {
6776
- var _vnode$data = vnode.data,
6777
- className = _vnode$data.className,
6778
- classMap = _vnode$data.classMap;
6779
- var nodesAreCompatible = true;
6780
- var vnodeClassName;
6813
+ function getAssociatedVMIfPresent(obj) {
6814
+ var maybeVm = ViewModelReflection.get(obj);
6781
6815
 
6782
- if (!isUndefined$1(className) && String(className) !== getProperty$1(elm, 'className')) {
6783
- // className is used when class is bound to an expr.
6784
- nodesAreCompatible = false;
6785
- vnodeClassName = className;
6786
- } else if (!isUndefined$1(classMap)) {
6787
- // classMap is used when class is set to static value.
6788
- var classList = getClassList$1(elm);
6789
- var computedClassName = ''; // all classes from the vnode should be in the element.classList
6816
+ if (process.env.NODE_ENV !== 'production') {
6817
+ if (!isUndefined$1(maybeVm)) {
6818
+ assertIsVM(maybeVm);
6819
+ }
6820
+ }
6790
6821
 
6791
- for (var name in classMap) {
6792
- computedClassName += ' ' + name;
6822
+ return maybeVm;
6823
+ }
6793
6824
 
6794
- if (!classList.contains(name)) {
6795
- nodesAreCompatible = false;
6796
- }
6797
- }
6825
+ function rehydrate(vm) {
6826
+ if (isTrue(vm.isDirty)) {
6827
+ var children = renderComponent(vm);
6828
+ patchShadowRoot(vm, children);
6829
+ }
6830
+ }
6798
6831
 
6799
- vnodeClassName = computedClassName.trim();
6832
+ function patchShadowRoot(vm, newCh) {
6833
+ var renderRoot = vm.renderRoot,
6834
+ oldCh = vm.children; // caching the new children collection
6800
6835
 
6801
- if (classList.length > keys(classMap).length) {
6802
- nodesAreCompatible = false;
6836
+ vm.children = newCh;
6837
+
6838
+ if (newCh.length > 0 || oldCh.length > 0) {
6839
+ // patch function mutates vnodes by adding the element reference,
6840
+ // however, if patching fails it contains partial changes.
6841
+ if (oldCh !== newCh) {
6842
+ runWithBoundaryProtection(vm, vm, function () {
6843
+ // pre
6844
+ logOperationStart(2
6845
+ /* Patch */
6846
+ , vm);
6847
+ }, function () {
6848
+ // job
6849
+ patchChildren(oldCh, newCh, renderRoot);
6850
+ }, function () {
6851
+ // post
6852
+ logOperationEnd(2
6853
+ /* Patch */
6854
+ , vm);
6855
+ });
6803
6856
  }
6804
6857
  }
6805
6858
 
6806
- if (!nodesAreCompatible) {
6807
- logError("Mismatch hydrating element <".concat(getProperty$1(elm, 'tagName').toLowerCase(), ">: attribute \"class\" has different values, expected \"").concat(vnodeClassName, "\" but found \"").concat(getProperty$1(elm, 'className'), "\""), vnode.owner);
6859
+ if (vm.state === 1
6860
+ /* connected */
6861
+ ) {
6862
+ // If the element is connected, that means connectedCallback was already issued, and
6863
+ // any successive rendering should finish with the call to renderedCallback, otherwise
6864
+ // the connectedCallback will take care of calling it in the right order at the end of
6865
+ // the current rehydration process.
6866
+ runRenderedCallback(vm);
6808
6867
  }
6809
-
6810
- return nodesAreCompatible;
6811
6868
  }
6812
6869
 
6813
- function validateStyleAttr(vnode, elm) {
6814
- var _vnode$data2 = vnode.data,
6815
- style = _vnode$data2.style,
6816
- styleDecls = _vnode$data2.styleDecls;
6817
- var elmStyle = getAttribute$1(elm, 'style') || '';
6818
- var vnodeStyle;
6819
- var nodesAreCompatible = true;
6870
+ function runRenderedCallback(vm) {
6871
+ var renderedCallback = vm.def.renderedCallback;
6820
6872
 
6821
- if (!isUndefined$1(style) && style !== elmStyle) {
6822
- nodesAreCompatible = false;
6823
- vnodeStyle = style;
6824
- } else if (!isUndefined$1(styleDecls)) {
6825
- var parsedVnodeStyle = parseStyleText(elmStyle);
6826
- var expectedStyle = []; // styleMap is used when style is set to static value.
6873
+ if (isTrue(ssr$1)) {
6874
+ return;
6875
+ }
6827
6876
 
6828
- for (var _i25 = 0, n = styleDecls.length; _i25 < n; _i25++) {
6829
- var _styleDecls$_i2 = _slicedToArray(styleDecls[_i25], 3),
6830
- prop = _styleDecls$_i2[0],
6831
- value = _styleDecls$_i2[1],
6832
- important = _styleDecls$_i2[2];
6877
+ var rendered = Services.rendered;
6833
6878
 
6834
- expectedStyle.push("".concat(prop, ": ").concat(value + (important ? ' important!' : '')));
6835
- var parsedPropValue = parsedVnodeStyle[prop];
6879
+ if (rendered) {
6880
+ invokeServiceHook(vm, rendered);
6881
+ }
6836
6882
 
6837
- if (isUndefined$1(parsedPropValue)) {
6838
- nodesAreCompatible = false;
6839
- } else if (!parsedPropValue.startsWith(value)) {
6840
- nodesAreCompatible = false;
6841
- } else if (important && !parsedPropValue.endsWith('!important')) {
6842
- nodesAreCompatible = false;
6843
- }
6844
- }
6883
+ if (!isUndefined$1(renderedCallback)) {
6884
+ logOperationStart(4
6885
+ /* RenderedCallback */
6886
+ , vm);
6887
+ invokeComponentCallback(vm, renderedCallback);
6888
+ logOperationEnd(4
6889
+ /* RenderedCallback */
6890
+ , vm);
6891
+ }
6892
+ }
6845
6893
 
6846
- if (keys(parsedVnodeStyle).length > styleDecls.length) {
6847
- nodesAreCompatible = false;
6848
- }
6894
+ var rehydrateQueue = [];
6849
6895
 
6850
- vnodeStyle = ArrayJoin.call(expectedStyle, ';');
6851
- }
6896
+ function flushRehydrationQueue() {
6897
+ logGlobalOperationStart(8
6898
+ /* GlobalRehydrate */
6899
+ );
6852
6900
 
6853
- if (!nodesAreCompatible) {
6854
- // style is used when class is bound to an expr.
6855
- logError("Mismatch hydrating element <".concat(getProperty$1(elm, 'tagName').toLowerCase(), ">: attribute \"style\" has different values, expected \"").concat(vnodeStyle, "\" but found \"").concat(elmStyle, "\"."), vnode.owner);
6901
+ if (process.env.NODE_ENV !== 'production') {
6902
+ assert.invariant(rehydrateQueue.length, "If rehydrateQueue was scheduled, it is because there must be at least one VM on this pending queue instead of ".concat(rehydrateQueue, "."));
6856
6903
  }
6857
6904
 
6858
- return nodesAreCompatible;
6859
- }
6860
- /*
6861
- * Copyright (c) 2018, salesforce.com, inc.
6862
- * All rights reserved.
6863
- * SPDX-License-Identifier: MIT
6864
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6865
- */
6905
+ var vms = rehydrateQueue.sort(function (a, b) {
6906
+ return a.idx - b.idx;
6907
+ });
6908
+ rehydrateQueue = []; // reset to a new queue
6866
6909
 
6910
+ for (var _i23 = 0, _len8 = vms.length; _i23 < _len8; _i23 += 1) {
6911
+ var vm = vms[_i23];
6867
6912
 
6868
- var idx = 0;
6869
- /** The internal slot used to associate different objects the engine manipulates with the VM */
6913
+ try {
6914
+ rehydrate(vm);
6915
+ } catch (error) {
6916
+ if (_i23 + 1 < _len8) {
6917
+ // pieces of the queue are still pending to be rehydrated, those should have priority
6918
+ if (rehydrateQueue.length === 0) {
6919
+ addCallbackToNextTick(flushRehydrationQueue);
6920
+ }
6870
6921
 
6871
- var ViewModelReflection = new WeakMap();
6922
+ ArrayUnshift.apply(rehydrateQueue, ArraySlice.call(vms, _i23 + 1));
6923
+ } // we need to end the measure before throwing.
6872
6924
 
6873
- function callHook(cmp, fn) {
6874
- var args = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
6875
- return fn.apply(cmp, args);
6876
- }
6877
6925
 
6878
- function setHook(cmp, prop, newValue) {
6879
- cmp[prop] = newValue;
6880
- }
6926
+ logGlobalOperationEnd(8
6927
+ /* GlobalRehydrate */
6928
+ ); // re-throwing the original error will break the current tick, but since the next tick is
6929
+ // already scheduled, it should continue patching the rest.
6881
6930
 
6882
- function getHook(cmp, prop) {
6883
- return cmp[prop];
6884
- }
6931
+ throw error; // eslint-disable-line no-unsafe-finally
6932
+ }
6933
+ }
6885
6934
 
6886
- function rerenderVM(vm) {
6887
- rehydrate(vm);
6935
+ logGlobalOperationEnd(8
6936
+ /* GlobalRehydrate */
6937
+ );
6888
6938
  }
6889
6939
 
6890
- function connectRootElement(elm) {
6891
- var vm = getAssociatedVM(elm);
6892
- logGlobalOperationStart(7
6893
- /* GlobalHydrate */
6894
- , vm); // Usually means moving the element from one place to another, which is observable via
6895
- // life-cycle hooks.
6940
+ function runConnectedCallback(vm) {
6941
+ var state = vm.state;
6896
6942
 
6897
- if (vm.state === 1
6943
+ if (state === 1
6898
6944
  /* connected */
6899
6945
  ) {
6900
- disconnectRootElement(elm);
6946
+ return; // nothing to do since it was already connected
6901
6947
  }
6902
6948
 
6903
- runConnectedCallback(vm);
6904
- rehydrate(vm);
6905
- logGlobalOperationEnd(7
6906
- /* GlobalHydrate */
6907
- , vm);
6908
- }
6949
+ vm.state = 1
6950
+ /* connected */
6951
+ ; // reporting connection
6909
6952
 
6910
- function hydrateRootElement(elm) {
6911
- var vm = getAssociatedVM(elm);
6912
- runConnectedCallback(vm);
6913
- hydrateVM(vm);
6914
- }
6953
+ var connected = Services.connected;
6915
6954
 
6916
- function disconnectRootElement(elm) {
6917
- var vm = getAssociatedVM(elm);
6918
- resetComponentStateWhenRemoved(vm);
6955
+ if (connected) {
6956
+ invokeServiceHook(vm, connected);
6957
+ }
6958
+
6959
+ if (hasWireAdapters(vm)) {
6960
+ connectWireAdapters(vm);
6961
+ }
6962
+
6963
+ var connectedCallback = vm.def.connectedCallback;
6964
+
6965
+ if (!isUndefined$1(connectedCallback)) {
6966
+ logOperationStart(3
6967
+ /* ConnectedCallback */
6968
+ , vm);
6969
+ invokeComponentCallback(vm, connectedCallback);
6970
+ logOperationEnd(3
6971
+ /* ConnectedCallback */
6972
+ , vm);
6973
+ }
6919
6974
  }
6920
6975
 
6921
- function appendVM(vm) {
6922
- rehydrate(vm);
6976
+ function hasWireAdapters(vm) {
6977
+ return getOwnPropertyNames$1(vm.def.wire).length > 0;
6923
6978
  }
6924
6979
 
6925
- function hydrateVM(vm) {
6926
- if (isTrue(vm.isDirty)) {
6927
- // manually diffing/patching here.
6928
- // This routine is:
6929
- // patchShadowRoot(vm, children);
6930
- // -> addVnodes.
6931
- var children = renderComponent(vm);
6932
- vm.children = children;
6933
- var vmChildren = vm.renderMode === 0
6934
- /* Light */
6935
- ? getChildNodes$1(vm.elm) : getChildNodes$1(vm.elm.shadowRoot);
6936
- hydrateChildren(vmChildren, children, vm);
6937
- runRenderedCallback(vm);
6980
+ function runDisconnectedCallback(vm) {
6981
+ if (process.env.NODE_ENV !== 'production') {
6982
+ assert.isTrue(vm.state !== 2
6983
+ /* disconnected */
6984
+ , "".concat(vm, " must be inserted."));
6938
6985
  }
6939
- } // just in case the component comes back, with this we guarantee re-rendering it
6940
- // while preventing any attempt to rehydration until after reinsertion.
6941
6986
 
6987
+ if (isFalse(vm.isDirty)) {
6988
+ // this guarantees that if the component is reused/reinserted,
6989
+ // it will be re-rendered because we are disconnecting the reactivity
6990
+ // linking, so mutations are not automatically reflected on the state
6991
+ // of disconnected components.
6992
+ vm.isDirty = true;
6993
+ }
6942
6994
 
6943
- function resetComponentStateWhenRemoved(vm) {
6944
- var state = vm.state;
6945
-
6946
- if (state !== 2
6995
+ vm.state = 2
6947
6996
  /* disconnected */
6948
- ) {
6949
- var oar = vm.oar,
6950
- tro = vm.tro; // Making sure that any observing record will not trigger the rehydrated on this vm
6951
-
6952
- tro.reset(); // Making sure that any observing accessor record will not trigger the setter to be reinvoked
6997
+ ; // reporting disconnection
6953
6998
 
6954
- for (var key in oar) {
6955
- oar[key].reset();
6956
- }
6999
+ var disconnected = Services.disconnected;
6957
7000
 
6958
- runDisconnectedCallback(vm); // Spec: https://dom.spec.whatwg.org/#concept-node-remove (step 14-15)
7001
+ if (disconnected) {
7002
+ invokeServiceHook(vm, disconnected);
7003
+ }
6959
7004
 
6960
- runChildNodesDisconnectedCallback(vm);
6961
- runLightChildNodesDisconnectedCallback(vm);
7005
+ if (hasWireAdapters(vm)) {
7006
+ disconnectWireAdapters(vm);
6962
7007
  }
6963
7008
 
6964
- if (process.env.NODE_ENV !== 'production') {
6965
- removeActiveVM(vm);
7009
+ var disconnectedCallback = vm.def.disconnectedCallback;
7010
+
7011
+ if (!isUndefined$1(disconnectedCallback)) {
7012
+ logOperationStart(5
7013
+ /* DisconnectedCallback */
7014
+ , vm);
7015
+ invokeComponentCallback(vm, disconnectedCallback);
7016
+ logOperationEnd(5
7017
+ /* DisconnectedCallback */
7018
+ , vm);
6966
7019
  }
6967
- } // this method is triggered by the diffing algo only when a vnode from the
6968
- // old vnode.children is removed from the DOM.
7020
+ }
6969
7021
 
7022
+ function runChildNodesDisconnectedCallback(vm) {
7023
+ var vCustomElementCollection = vm.velements; // Reporting disconnection for every child in inverse order since they are
7024
+ // inserted in reserved order.
6970
7025
 
6971
- function removeVM(vm) {
6972
- if (process.env.NODE_ENV !== 'production') {
6973
- assert.isTrue(vm.state === 1
6974
- /* connected */
6975
- || vm.state === 2
6976
- /* disconnected */
6977
- , "".concat(vm, " must have been connected."));
7026
+ for (var _i24 = vCustomElementCollection.length - 1; _i24 >= 0; _i24 -= 1) {
7027
+ var elm = vCustomElementCollection[_i24].elm; // There are two cases where the element could be undefined:
7028
+ // * when there is an error during the construction phase, and an error
7029
+ // boundary picks it, there is a possibility that the VCustomElement
7030
+ // is not properly initialized, and therefore is should be ignored.
7031
+ // * when slotted custom element is not used by the element where it is
7032
+ // slotted into it, as a result, the custom element was never
7033
+ // initialized.
7034
+
7035
+ if (!isUndefined$1(elm)) {
7036
+ var childVM = getAssociatedVMIfPresent(elm); // The VM associated with the element might be associated undefined
7037
+ // in the case where the VM failed in the middle of its creation,
7038
+ // eg: constructor throwing before invoking super().
7039
+
7040
+ if (!isUndefined$1(childVM)) {
7041
+ resetComponentStateWhenRemoved(childVM);
7042
+ }
7043
+ }
6978
7044
  }
7045
+ }
6979
7046
 
6980
- resetComponentStateWhenRemoved(vm);
7047
+ function runLightChildNodesDisconnectedCallback(vm) {
7048
+ var adoptedChildren = vm.aChildren;
7049
+ recursivelyDisconnectChildren(adoptedChildren);
6981
7050
  }
7051
+ /**
7052
+ * The recursion doesn't need to be a complete traversal of the vnode graph,
7053
+ * instead it can be partial, when a custom element vnode is found, we don't
7054
+ * need to continue into its children because by attempting to disconnect the
7055
+ * custom element itself will trigger the removal of anything slotted or anything
7056
+ * defined on its shadow.
7057
+ */
6982
7058
 
6983
- function getNearestShadowAncestor(vm) {
6984
- var ancestor = vm.owner;
6985
7059
 
6986
- while (!isNull(ancestor) && ancestor.renderMode === 0
6987
- /* Light */
6988
- ) {
6989
- ancestor = ancestor.owner;
7060
+ function recursivelyDisconnectChildren(vnodes) {
7061
+ for (var _i25 = 0, _len9 = vnodes.length; _i25 < _len9; _i25 += 1) {
7062
+ var vnode = vnodes[_i25];
7063
+
7064
+ if (!isNull(vnode) && !isUndefined$1(vnode.elm)) {
7065
+ switch (vnode.type) {
7066
+ case 2
7067
+ /* Element */
7068
+ :
7069
+ recursivelyDisconnectChildren(vnode.children);
7070
+ break;
7071
+
7072
+ case 3
7073
+ /* CustomElement */
7074
+ :
7075
+ {
7076
+ var vm = getAssociatedVM(vnode.elm);
7077
+ resetComponentStateWhenRemoved(vm);
7078
+ break;
7079
+ }
7080
+ }
7081
+ }
6990
7082
  }
7083
+ } // This is a super optimized mechanism to remove the content of the root node (shadow root
7084
+ // for shadow DOM components and the root element itself for light DOM) without having to go
7085
+ // into snabbdom. Especially useful when the reset is a consequence of an error, in which case the
7086
+ // children VNodes might not be representing the current state of the DOM.
6991
7087
 
6992
- return ancestor;
6993
- }
6994
7088
 
6995
- function createVM(elm, ctor, options) {
6996
- var mode = options.mode,
6997
- owner = options.owner,
6998
- tagName = options.tagName;
6999
- var def = getComponentInternalDef(ctor);
7000
- var vm = {
7001
- elm: elm,
7002
- def: def,
7003
- idx: idx++,
7004
- state: 0
7005
- /* created */
7006
- ,
7007
- isScheduled: false,
7008
- isDirty: true,
7009
- tagName: tagName,
7010
- mode: mode,
7011
- owner: owner,
7012
- children: EmptyArray,
7013
- aChildren: EmptyArray,
7014
- velements: EmptyArray,
7015
- cmpProps: create(null),
7016
- cmpFields: create(null),
7017
- cmpSlots: create(null),
7018
- oar: create(null),
7019
- cmpTemplate: null,
7020
- renderMode: def.renderMode,
7021
- context: {
7022
- stylesheetToken: undefined,
7023
- hasTokenInClass: undefined,
7024
- hasTokenInAttribute: undefined,
7025
- hasScopedStyles: undefined,
7026
- styleVNode: null,
7027
- tplCache: EmptyObject,
7028
- wiredConnecting: EmptyArray,
7029
- wiredDisconnecting: EmptyArray
7030
- },
7031
- // Properties set right after VM creation.
7032
- tro: null,
7033
- shadowMode: null,
7034
- // Properties set by the LightningElement constructor.
7035
- component: null,
7036
- shadowRoot: null,
7037
- renderRoot: null,
7038
- callHook: callHook,
7039
- setHook: setHook,
7040
- getHook: getHook
7041
- };
7042
- vm.shadowMode = computeShadowMode(vm);
7043
- vm.tro = getTemplateReactiveObserver(vm);
7089
+ function resetComponentRoot(vm) {
7090
+ var children = vm.children,
7091
+ renderRoot = vm.renderRoot;
7044
7092
 
7045
- if (process.env.NODE_ENV !== 'production') {
7046
- vm.toString = function () {
7047
- return "[object:vm ".concat(def.name, " (").concat(vm.idx, ")]");
7048
- };
7093
+ for (var _i26 = 0, _len10 = children.length; _i26 < _len10; _i26++) {
7094
+ var child = children[_i26];
7049
7095
 
7050
- if (runtimeFlags.ENABLE_FORCE_NATIVE_SHADOW_MODE_FOR_TEST) {
7051
- vm.shadowMode = 0
7052
- /* Native */
7053
- ;
7096
+ if (!isNull(child) && !isUndefined$1(child.elm)) {
7097
+ remove$1(child.elm, renderRoot);
7054
7098
  }
7055
- } // Create component instance associated to the vm and the element.
7099
+ }
7056
7100
 
7101
+ vm.children = EmptyArray;
7102
+ runChildNodesDisconnectedCallback(vm);
7103
+ vm.velements = EmptyArray;
7104
+ }
7057
7105
 
7058
- invokeComponentConstructor(vm, def.ctor); // Initializing the wire decorator per instance only when really needed
7106
+ function scheduleRehydration(vm) {
7107
+ if (isTrue(ssr$1) || isTrue(vm.isScheduled)) {
7108
+ return;
7109
+ }
7059
7110
 
7060
- if (hasWireAdapters(vm)) {
7061
- installWireAdapters(vm);
7111
+ vm.isScheduled = true;
7112
+
7113
+ if (rehydrateQueue.length === 0) {
7114
+ addCallbackToNextTick(flushRehydrationQueue);
7062
7115
  }
7063
7116
 
7064
- return vm;
7117
+ ArrayPush$1.call(rehydrateQueue, vm);
7065
7118
  }
7066
7119
 
7067
- function computeShadowMode(vm) {
7068
- var def = vm.def;
7069
- var shadowMode;
7120
+ function getErrorBoundaryVM(vm) {
7121
+ var currentVm = vm;
7070
7122
 
7071
- if (isSyntheticShadowDefined$1) {
7072
- if (def.renderMode === 0
7073
- /* Light */
7074
- ) {
7075
- // ShadowMode.Native implies "not synthetic shadow" which is consistent with how
7076
- // everything defaults to native when the synthetic shadow polyfill is unavailable.
7077
- shadowMode = 0
7078
- /* Native */
7079
- ;
7080
- } else if (isNativeShadowDefined$1) {
7081
- // Not combined with above condition because @lwc/features only supports identifiers in
7082
- // the if-condition.
7083
- if (runtimeFlags.ENABLE_MIXED_SHADOW_MODE) {
7084
- if (def.shadowSupportMode === "any"
7085
- /* Any */
7086
- ) {
7087
- shadowMode = 0
7088
- /* Native */
7089
- ;
7090
- } else {
7091
- var shadowAncestor = getNearestShadowAncestor(vm);
7092
-
7093
- if (!isNull(shadowAncestor) && shadowAncestor.shadowMode === 0
7094
- /* Native */
7095
- ) {
7096
- // Transitive support for native Shadow DOM. A component in native mode
7097
- // transitively opts all of its descendants into native.
7098
- shadowMode = 0
7099
- /* Native */
7100
- ;
7101
- } else {
7102
- // Synthetic if neither this component nor any of its ancestors are configured
7103
- // to be native.
7104
- shadowMode = 1
7105
- /* Synthetic */
7106
- ;
7107
- }
7108
- }
7109
- } else {
7110
- shadowMode = 1
7111
- /* Synthetic */
7112
- ;
7113
- }
7114
- } else {
7115
- // Synthetic if there is no native Shadow DOM support.
7116
- shadowMode = 1
7117
- /* Synthetic */
7118
- ;
7123
+ while (!isNull(currentVm)) {
7124
+ if (!isUndefined$1(currentVm.def.errorCallback)) {
7125
+ return currentVm;
7119
7126
  }
7120
- } else {
7121
- // Native if the synthetic shadow polyfill is unavailable.
7122
- shadowMode = 0
7123
- /* Native */
7124
- ;
7125
- }
7126
-
7127
- return shadowMode;
7128
- }
7129
7127
 
7130
- function assertIsVM(obj) {
7131
- if (isNull(obj) || !isObject(obj) || !('renderRoot' in obj)) {
7132
- throw new TypeError("".concat(obj, " is not a VM."));
7128
+ currentVm = currentVm.owner;
7133
7129
  }
7134
7130
  }
7135
7131
 
7136
- function associateVM(obj, vm) {
7137
- ViewModelReflection.set(obj, vm);
7138
- }
7132
+ function runWithBoundaryProtection(vm, owner, pre, job, post) {
7133
+ var error;
7134
+ pre();
7139
7135
 
7140
- function getAssociatedVM(obj) {
7141
- var vm = ViewModelReflection.get(obj);
7136
+ try {
7137
+ job();
7138
+ } catch (e) {
7139
+ error = Object(e);
7140
+ } finally {
7141
+ post();
7142
7142
 
7143
- if (process.env.NODE_ENV !== 'production') {
7144
- assertIsVM(vm);
7145
- }
7143
+ if (!isUndefined$1(error)) {
7144
+ addErrorComponentStack(vm, error);
7145
+ var errorBoundaryVm = isNull(owner) ? undefined : getErrorBoundaryVM(owner);
7146
7146
 
7147
- return vm;
7148
- }
7147
+ if (isUndefined$1(errorBoundaryVm)) {
7148
+ throw error; // eslint-disable-line no-unsafe-finally
7149
+ }
7149
7150
 
7150
- function getAssociatedVMIfPresent(obj) {
7151
- var maybeVm = ViewModelReflection.get(obj);
7151
+ resetComponentRoot(vm); // remove offenders
7152
7152
 
7153
- if (process.env.NODE_ENV !== 'production') {
7154
- if (!isUndefined$1(maybeVm)) {
7155
- assertIsVM(maybeVm);
7153
+ logOperationStart(6
7154
+ /* ErrorCallback */
7155
+ , vm); // error boundaries must have an ErrorCallback
7156
+
7157
+ var errorCallback = errorBoundaryVm.def.errorCallback;
7158
+ invokeComponentCallback(errorBoundaryVm, errorCallback, [error, error.wcStack]);
7159
+ logOperationEnd(6
7160
+ /* ErrorCallback */
7161
+ , vm);
7156
7162
  }
7157
7163
  }
7158
-
7159
- return maybeVm;
7160
7164
  }
7161
7165
 
7162
- function rehydrate(vm) {
7163
- if (isTrue(vm.isDirty)) {
7164
- var children = renderComponent(vm);
7165
- patchShadowRoot(vm, children);
7166
+ function forceRehydration(vm) {
7167
+ // if we must reset the shadowRoot content and render the template
7168
+ // from scratch on an active instance, the way to force the reset
7169
+ // is by replacing the value of old template, which is used during
7170
+ // to determine if the template has changed or not during the rendering
7171
+ // process. If the template returned by render() is different from the
7172
+ // previous stored template, the styles will be reset, along with the
7173
+ // content of the shadowRoot, this way we can guarantee that all children
7174
+ // elements will be throw away, and new instances will be created.
7175
+ vm.cmpTemplate = function () {
7176
+ return [];
7177
+ };
7178
+
7179
+ if (isFalse(vm.isDirty)) {
7180
+ // forcing the vm to rehydrate in the next tick
7181
+ markComponentAsDirty(vm);
7182
+ scheduleRehydration(vm);
7166
7183
  }
7167
7184
  }
7185
+ /*
7186
+ * Copyright (c) 2018, salesforce.com, inc.
7187
+ * All rights reserved.
7188
+ * SPDX-License-Identifier: MIT
7189
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7190
+ */
7168
7191
 
7169
- function patchShadowRoot(vm, newCh) {
7170
- var renderRoot = vm.renderRoot,
7171
- oldCh = vm.children; // caching the new children collection
7172
-
7173
- vm.children = newCh;
7174
7192
 
7175
- if (newCh.length > 0 || oldCh.length > 0) {
7176
- // patch function mutates vnodes by adding the element reference,
7177
- // however, if patching fails it contains partial changes.
7178
- if (oldCh !== newCh) {
7179
- runWithBoundaryProtection(vm, vm, function () {
7180
- // pre
7181
- logOperationStart(2
7182
- /* Patch */
7183
- , vm);
7184
- }, function () {
7185
- // job
7186
- patchChildren(oldCh, newCh, renderRoot);
7187
- }, function () {
7188
- // post
7189
- logOperationEnd(2
7190
- /* Patch */
7191
- , vm);
7192
- });
7193
- }
7194
- }
7193
+ var DeprecatedWiredElementHost = '$$DeprecatedWiredElementHostKey$$';
7194
+ var DeprecatedWiredParamsMeta = '$$DeprecatedWiredParamsMetaKey$$';
7195
+ var WireMetaMap = new Map();
7195
7196
 
7196
- if (vm.state === 1
7197
- /* connected */
7198
- ) {
7199
- // If the element is connected, that means connectedCallback was already issued, and
7200
- // any successive rendering should finish with the call to renderedCallback, otherwise
7201
- // the connectedCallback will take care of calling it in the right order at the end of
7202
- // the current rehydration process.
7203
- runRenderedCallback(vm);
7204
- }
7205
- }
7197
+ var WireContextRegistrationEvent = /*#__PURE__*/function (_CustomEvent) {
7198
+ _inherits(WireContextRegistrationEvent, _CustomEvent);
7206
7199
 
7207
- function runRenderedCallback(vm) {
7208
- var renderedCallback = vm.def.renderedCallback;
7200
+ var _super6 = _createSuper(WireContextRegistrationEvent);
7209
7201
 
7210
- if (isTrue(ssr$1)) {
7211
- return;
7212
- }
7202
+ function WireContextRegistrationEvent(adapterToken, _ref3) {
7203
+ var _this5;
7213
7204
 
7214
- var rendered = Services.rendered;
7205
+ var setNewContext = _ref3.setNewContext,
7206
+ setDisconnectedCallback = _ref3.setDisconnectedCallback;
7215
7207
 
7216
- if (rendered) {
7217
- invokeServiceHook(vm, rendered);
7218
- }
7208
+ _classCallCheck(this, WireContextRegistrationEvent);
7219
7209
 
7220
- if (!isUndefined$1(renderedCallback)) {
7221
- logOperationStart(4
7222
- /* RenderedCallback */
7223
- , vm);
7224
- invokeComponentCallback(vm, renderedCallback);
7225
- logOperationEnd(4
7226
- /* RenderedCallback */
7227
- , vm);
7210
+ _this5 = _super6.call(this, adapterToken, {
7211
+ bubbles: true,
7212
+ composed: true
7213
+ });
7214
+ defineProperties(_assertThisInitialized(_this5), {
7215
+ setNewContext: {
7216
+ value: setNewContext
7217
+ },
7218
+ setDisconnectedCallback: {
7219
+ value: setDisconnectedCallback
7220
+ }
7221
+ });
7222
+ return _this5;
7228
7223
  }
7229
- }
7230
7224
 
7231
- var rehydrateQueue = [];
7225
+ return _createClass(WireContextRegistrationEvent);
7226
+ }( /*#__PURE__*/_wrapNativeSuper(CustomEvent));
7232
7227
 
7233
- function flushRehydrationQueue() {
7234
- logGlobalOperationStart(8
7235
- /* GlobalRehydrate */
7236
- );
7228
+ function createFieldDataCallback(vm, name) {
7229
+ var cmpFields = vm.cmpFields;
7230
+ return function (value) {
7231
+ if (value !== vm.cmpFields[name]) {
7232
+ // storing the value in the underlying storage
7233
+ cmpFields[name] = value;
7234
+ componentValueMutated(vm, name);
7235
+ }
7236
+ };
7237
+ }
7237
7238
 
7238
- if (process.env.NODE_ENV !== 'production') {
7239
- assert.invariant(rehydrateQueue.length, "If rehydrateQueue was scheduled, it is because there must be at least one VM on this pending queue instead of ".concat(rehydrateQueue, "."));
7240
- }
7239
+ function createMethodDataCallback(vm, method) {
7240
+ return function (value) {
7241
+ // dispatching new value into the wired method
7242
+ runWithBoundaryProtection(vm, vm.owner, noop, function () {
7243
+ // job
7244
+ method.call(vm.component, value);
7245
+ }, noop);
7246
+ };
7247
+ }
7241
7248
 
7242
- var vms = rehydrateQueue.sort(function (a, b) {
7243
- return a.idx - b.idx;
7244
- });
7245
- rehydrateQueue = []; // reset to a new queue
7249
+ function createConfigWatcher(component, configCallback, callbackWhenConfigIsReady) {
7250
+ var hasPendingConfig = false; // creating the reactive observer for reactive params when needed
7246
7251
 
7247
- for (var _i26 = 0, _len8 = vms.length; _i26 < _len8; _i26 += 1) {
7248
- var vm = vms[_i26];
7252
+ var ro = new ReactiveObserver(function () {
7253
+ if (hasPendingConfig === false) {
7254
+ hasPendingConfig = true; // collect new config in the micro-task
7249
7255
 
7250
- try {
7251
- rehydrate(vm);
7252
- } catch (error) {
7253
- if (_i26 + 1 < _len8) {
7254
- // pieces of the queue are still pending to be rehydrated, those should have priority
7255
- if (rehydrateQueue.length === 0) {
7256
- addCallbackToNextTick(flushRehydrationQueue);
7257
- }
7256
+ Promise.resolve().then(function () {
7257
+ hasPendingConfig = false; // resetting current reactive params
7258
7258
 
7259
- ArrayUnshift.apply(rehydrateQueue, ArraySlice.call(vms, _i26 + 1));
7260
- } // we need to end the measure before throwing.
7259
+ ro.reset(); // dispatching a new config due to a change in the configuration
7261
7260
 
7261
+ computeConfigAndUpdate();
7262
+ });
7263
+ }
7264
+ });
7262
7265
 
7263
- logGlobalOperationEnd(8
7264
- /* GlobalRehydrate */
7265
- ); // re-throwing the original error will break the current tick, but since the next tick is
7266
- // already scheduled, it should continue patching the rest.
7266
+ var computeConfigAndUpdate = function computeConfigAndUpdate() {
7267
+ var config;
7268
+ ro.observe(function () {
7269
+ return config = configCallback(component);
7270
+ }); // eslint-disable-next-line lwc-internal/no-invalid-todo
7271
+ // TODO: dev-mode validation of config based on the adapter.configSchema
7272
+ // @ts-ignore it is assigned in the observe() callback
7267
7273
 
7268
- throw error; // eslint-disable-line no-unsafe-finally
7269
- }
7270
- }
7274
+ callbackWhenConfigIsReady(config);
7275
+ };
7271
7276
 
7272
- logGlobalOperationEnd(8
7273
- /* GlobalRehydrate */
7274
- );
7277
+ return {
7278
+ computeConfigAndUpdate: computeConfigAndUpdate,
7279
+ ro: ro
7280
+ };
7275
7281
  }
7276
7282
 
7277
- function runConnectedCallback(vm) {
7278
- var state = vm.state;
7283
+ function createContextWatcher(vm, wireDef, callbackWhenContextIsReady) {
7284
+ var adapter = wireDef.adapter;
7285
+ var adapterContextToken = getAdapterToken(adapter);
7279
7286
 
7280
- if (state === 1
7281
- /* connected */
7282
- ) {
7283
- return; // nothing to do since it was already connected
7287
+ if (isUndefined$1(adapterContextToken)) {
7288
+ return; // no provider found, nothing to be done
7284
7289
  }
7285
7290
 
7286
- vm.state = 1
7287
- /* connected */
7288
- ; // reporting connection
7289
-
7290
- var connected = Services.connected;
7291
-
7292
- if (connected) {
7293
- invokeServiceHook(vm, connected);
7294
- }
7291
+ var elm = vm.elm,
7292
+ _vm$context = vm.context,
7293
+ wiredConnecting = _vm$context.wiredConnecting,
7294
+ wiredDisconnecting = _vm$context.wiredDisconnecting; // waiting for the component to be connected to formally request the context via the token
7295
7295
 
7296
- if (hasWireAdapters(vm)) {
7297
- connectWireAdapters(vm);
7298
- }
7296
+ ArrayPush$1.call(wiredConnecting, function () {
7297
+ // This event is responsible for connecting the host element with another
7298
+ // element in the composed path that is providing contextual data. The provider
7299
+ // must be listening for a special dom event with the name corresponding to the value of
7300
+ // `adapterContextToken`, which will remain secret and internal to this file only to
7301
+ // guarantee that the linkage can be forged.
7302
+ var contextRegistrationEvent = new WireContextRegistrationEvent(adapterContextToken, {
7303
+ setNewContext: function setNewContext(newContext) {
7304
+ // eslint-disable-next-line lwc-internal/no-invalid-todo
7305
+ // TODO: dev-mode validation of config based on the adapter.contextSchema
7306
+ callbackWhenContextIsReady(newContext);
7307
+ },
7308
+ setDisconnectedCallback: function setDisconnectedCallback(disconnectCallback) {
7309
+ // adds this callback into the disconnect bucket so it gets disconnected from parent
7310
+ // the the element hosting the wire is disconnected
7311
+ ArrayPush$1.call(wiredDisconnecting, disconnectCallback);
7312
+ }
7313
+ });
7314
+ dispatchEvent$1(elm, contextRegistrationEvent);
7315
+ });
7316
+ }
7299
7317
 
7300
- var connectedCallback = vm.def.connectedCallback;
7318
+ function createConnector(vm, name, wireDef) {
7319
+ var method = wireDef.method,
7320
+ adapter = wireDef.adapter,
7321
+ configCallback = wireDef.configCallback,
7322
+ dynamic = wireDef.dynamic;
7323
+ var dataCallback = isUndefined$1(method) ? createFieldDataCallback(vm, name) : createMethodDataCallback(vm, method);
7324
+ var context;
7325
+ var connector; // Workaround to pass the component element associated to this wire adapter instance.
7301
7326
 
7302
- if (!isUndefined$1(connectedCallback)) {
7303
- logOperationStart(3
7304
- /* ConnectedCallback */
7305
- , vm);
7306
- invokeComponentCallback(vm, connectedCallback);
7307
- logOperationEnd(3
7308
- /* ConnectedCallback */
7309
- , vm);
7310
- }
7311
- }
7327
+ defineProperty(dataCallback, DeprecatedWiredElementHost, {
7328
+ value: vm.elm
7329
+ });
7330
+ defineProperty(dataCallback, DeprecatedWiredParamsMeta, {
7331
+ value: dynamic
7332
+ });
7333
+ runWithBoundaryProtection(vm, vm, noop, function () {
7334
+ // job
7335
+ connector = new adapter(dataCallback);
7336
+ }, noop);
7312
7337
 
7313
- function hasWireAdapters(vm) {
7314
- return getOwnPropertyNames$1(vm.def.wire).length > 0;
7315
- }
7338
+ var updateConnectorConfig = function updateConnectorConfig(config) {
7339
+ // every time the config is recomputed due to tracking,
7340
+ // this callback will be invoked with the new computed config
7341
+ runWithBoundaryProtection(vm, vm, noop, function () {
7342
+ // job
7343
+ connector.update(config, context);
7344
+ }, noop);
7345
+ }; // Computes the current wire config and calls the update method on the wire adapter.
7346
+ // If it has params, we will need to observe changes in the next tick.
7316
7347
 
7317
- function runDisconnectedCallback(vm) {
7318
- if (process.env.NODE_ENV !== 'production') {
7319
- assert.isTrue(vm.state !== 2
7320
- /* disconnected */
7321
- , "".concat(vm, " must be inserted."));
7322
- }
7323
7348
 
7324
- if (isFalse(vm.isDirty)) {
7325
- // this guarantees that if the component is reused/reinserted,
7326
- // it will be re-rendered because we are disconnecting the reactivity
7327
- // linking, so mutations are not automatically reflected on the state
7328
- // of disconnected components.
7329
- vm.isDirty = true;
7330
- }
7349
+ var _createConfigWatcher = createConfigWatcher(vm.component, configCallback, updateConnectorConfig),
7350
+ computeConfigAndUpdate = _createConfigWatcher.computeConfigAndUpdate,
7351
+ ro = _createConfigWatcher.ro; // if the adapter needs contextualization, we need to watch for new context and push it alongside the config
7331
7352
 
7332
- vm.state = 2
7333
- /* disconnected */
7334
- ; // reporting disconnection
7335
7353
 
7336
- var disconnected = Services.disconnected;
7354
+ if (!isUndefined$1(adapter.contextSchema)) {
7355
+ createContextWatcher(vm, wireDef, function (newContext) {
7356
+ // every time the context is pushed into this component,
7357
+ // this callback will be invoked with the new computed context
7358
+ if (context !== newContext) {
7359
+ context = newContext; // Note: when new context arrives, the config will be recomputed and pushed along side the new
7360
+ // context, this is to preserve the identity characteristics, config should not have identity
7361
+ // (ever), while context can have identity
7337
7362
 
7338
- if (disconnected) {
7339
- invokeServiceHook(vm, disconnected);
7363
+ if (vm.state === 1
7364
+ /* connected */
7365
+ ) {
7366
+ computeConfigAndUpdate();
7367
+ }
7368
+ }
7369
+ });
7340
7370
  }
7341
7371
 
7342
- if (hasWireAdapters(vm)) {
7343
- disconnectWireAdapters(vm);
7344
- }
7372
+ return {
7373
+ // @ts-ignore the boundary protection executes sync, connector is always defined
7374
+ connector: connector,
7375
+ computeConfigAndUpdate: computeConfigAndUpdate,
7376
+ resetConfigWatcher: function resetConfigWatcher() {
7377
+ return ro.reset();
7378
+ }
7379
+ };
7380
+ }
7345
7381
 
7346
- var disconnectedCallback = vm.def.disconnectedCallback;
7382
+ var AdapterToTokenMap = new Map();
7347
7383
 
7348
- if (!isUndefined$1(disconnectedCallback)) {
7349
- logOperationStart(5
7350
- /* DisconnectedCallback */
7351
- , vm);
7352
- invokeComponentCallback(vm, disconnectedCallback);
7353
- logOperationEnd(5
7354
- /* DisconnectedCallback */
7355
- , vm);
7356
- }
7384
+ function getAdapterToken(adapter) {
7385
+ return AdapterToTokenMap.get(adapter);
7357
7386
  }
7358
7387
 
7359
- function runChildNodesDisconnectedCallback(vm) {
7360
- var vCustomElementCollection = vm.velements; // Reporting disconnection for every child in inverse order since they are
7361
- // inserted in reserved order.
7388
+ function setAdapterToken(adapter, token) {
7389
+ AdapterToTokenMap.set(adapter, token);
7390
+ }
7362
7391
 
7363
- for (var _i27 = vCustomElementCollection.length - 1; _i27 >= 0; _i27 -= 1) {
7364
- var elm = vCustomElementCollection[_i27].elm; // There are two cases where the element could be undefined:
7365
- // * when there is an error during the construction phase, and an error
7366
- // boundary picks it, there is a possibility that the VCustomElement
7367
- // is not properly initialized, and therefore is should be ignored.
7368
- // * when slotted custom element is not used by the element where it is
7369
- // slotted into it, as a result, the custom element was never
7370
- // initialized.
7392
+ function storeWiredMethodMeta(descriptor, adapter, configCallback, dynamic) {
7393
+ // support for callable adapters
7394
+ if (adapter.adapter) {
7395
+ adapter = adapter.adapter;
7396
+ }
7371
7397
 
7372
- if (!isUndefined$1(elm)) {
7373
- var childVM = getAssociatedVMIfPresent(elm); // The VM associated with the element might be associated undefined
7374
- // in the case where the VM failed in the middle of its creation,
7375
- // eg: constructor throwing before invoking super().
7398
+ var method = descriptor.value;
7399
+ var def = {
7400
+ adapter: adapter,
7401
+ method: method,
7402
+ configCallback: configCallback,
7403
+ dynamic: dynamic
7404
+ };
7405
+ WireMetaMap.set(descriptor, def);
7406
+ }
7376
7407
 
7377
- if (!isUndefined$1(childVM)) {
7378
- resetComponentStateWhenRemoved(childVM);
7379
- }
7380
- }
7408
+ function storeWiredFieldMeta(descriptor, adapter, configCallback, dynamic) {
7409
+ // support for callable adapters
7410
+ if (adapter.adapter) {
7411
+ adapter = adapter.adapter;
7381
7412
  }
7382
- }
7383
7413
 
7384
- function runLightChildNodesDisconnectedCallback(vm) {
7385
- var adoptedChildren = vm.aChildren;
7386
- recursivelyDisconnectChildren(adoptedChildren);
7414
+ var def = {
7415
+ adapter: adapter,
7416
+ configCallback: configCallback,
7417
+ dynamic: dynamic
7418
+ };
7419
+ WireMetaMap.set(descriptor, def);
7387
7420
  }
7388
- /**
7389
- * The recursion doesn't need to be a complete traversal of the vnode graph,
7390
- * instead it can be partial, when a custom element vnode is found, we don't
7391
- * need to continue into its children because by attempting to disconnect the
7392
- * custom element itself will trigger the removal of anything slotted or anything
7393
- * defined on its shadow.
7394
- */
7395
-
7396
7421
 
7397
- function recursivelyDisconnectChildren(vnodes) {
7398
- for (var _i28 = 0, _len9 = vnodes.length; _i28 < _len9; _i28 += 1) {
7399
- var vnode = vnodes[_i28];
7422
+ function installWireAdapters(vm) {
7423
+ var context = vm.context,
7424
+ wire = vm.def.wire;
7425
+ var wiredConnecting = context.wiredConnecting = [];
7426
+ var wiredDisconnecting = context.wiredDisconnecting = [];
7400
7427
 
7401
- if (!isNull(vnode) && !isUndefined$1(vnode.elm)) {
7402
- switch (vnode.type) {
7403
- case 2
7404
- /* Element */
7405
- :
7406
- recursivelyDisconnectChildren(vnode.children);
7407
- break;
7428
+ for (var fieldNameOrMethod in wire) {
7429
+ var descriptor = wire[fieldNameOrMethod];
7430
+ var wireDef = WireMetaMap.get(descriptor);
7408
7431
 
7409
- case 3
7410
- /* CustomElement */
7411
- :
7412
- {
7413
- var vm = getAssociatedVM(vnode.elm);
7414
- resetComponentStateWhenRemoved(vm);
7415
- break;
7416
- }
7417
- }
7432
+ if (process.env.NODE_ENV !== 'production') {
7433
+ assert.invariant(wireDef, "Internal Error: invalid wire definition found.");
7418
7434
  }
7419
- }
7420
- } // This is a super optimized mechanism to remove the content of the root node (shadow root
7421
- // for shadow DOM components and the root element itself for light DOM) without having to go
7422
- // into snabbdom. Especially useful when the reset is a consequence of an error, in which case the
7423
- // children VNodes might not be representing the current state of the DOM.
7424
7435
 
7436
+ if (!isUndefined$1(wireDef)) {
7437
+ (function () {
7438
+ var _createConnector = createConnector(vm, fieldNameOrMethod, wireDef),
7439
+ connector = _createConnector.connector,
7440
+ computeConfigAndUpdate = _createConnector.computeConfigAndUpdate,
7441
+ resetConfigWatcher = _createConnector.resetConfigWatcher;
7425
7442
 
7426
- function resetComponentRoot(vm) {
7427
- var children = vm.children,
7428
- renderRoot = vm.renderRoot;
7443
+ var hasDynamicParams = wireDef.dynamic.length > 0;
7444
+ ArrayPush$1.call(wiredConnecting, function () {
7445
+ connector.connect();
7429
7446
 
7430
- for (var _i29 = 0, _len10 = children.length; _i29 < _len10; _i29++) {
7431
- var child = children[_i29];
7447
+ if (!runtimeFlags.ENABLE_WIRE_SYNC_EMIT) {
7448
+ if (hasDynamicParams) {
7449
+ Promise.resolve().then(computeConfigAndUpdate);
7450
+ return;
7451
+ }
7452
+ }
7432
7453
 
7433
- if (!isNull(child) && !isUndefined$1(child.elm)) {
7434
- remove$1(child.elm, renderRoot);
7454
+ computeConfigAndUpdate();
7455
+ });
7456
+ ArrayPush$1.call(wiredDisconnecting, function () {
7457
+ connector.disconnect();
7458
+ resetConfigWatcher();
7459
+ });
7460
+ })();
7435
7461
  }
7436
7462
  }
7437
-
7438
- vm.children = EmptyArray;
7439
- runChildNodesDisconnectedCallback(vm);
7440
- vm.velements = EmptyArray;
7441
7463
  }
7442
7464
 
7443
- function scheduleRehydration(vm) {
7444
- if (isTrue(ssr$1) || isTrue(vm.isScheduled)) {
7445
- return;
7446
- }
7447
-
7448
- vm.isScheduled = true;
7465
+ function connectWireAdapters(vm) {
7466
+ var wiredConnecting = vm.context.wiredConnecting;
7449
7467
 
7450
- if (rehydrateQueue.length === 0) {
7451
- addCallbackToNextTick(flushRehydrationQueue);
7468
+ for (var _i27 = 0, _len11 = wiredConnecting.length; _i27 < _len11; _i27 += 1) {
7469
+ wiredConnecting[_i27]();
7452
7470
  }
7453
-
7454
- ArrayPush$1.call(rehydrateQueue, vm);
7455
7471
  }
7456
7472
 
7457
- function getErrorBoundaryVM(vm) {
7458
- var currentVm = vm;
7459
-
7460
- while (!isNull(currentVm)) {
7461
- if (!isUndefined$1(currentVm.def.errorCallback)) {
7462
- return currentVm;
7473
+ function disconnectWireAdapters(vm) {
7474
+ var wiredDisconnecting = vm.context.wiredDisconnecting;
7475
+ runWithBoundaryProtection(vm, vm, noop, function () {
7476
+ // job
7477
+ for (var _i28 = 0, _len12 = wiredDisconnecting.length; _i28 < _len12; _i28 += 1) {
7478
+ wiredDisconnecting[_i28]();
7463
7479
  }
7464
-
7465
- currentVm = currentVm.owner;
7466
- }
7480
+ }, noop);
7467
7481
  }
7482
+ /*
7483
+ * Copyright (c) 2018, salesforce.com, inc.
7484
+ * All rights reserved.
7485
+ * SPDX-License-Identifier: MIT
7486
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7487
+ */
7488
+ // this is lwc internal implementation
7468
7489
 
7469
- function runWithBoundaryProtection(vm, owner, pre, job, post) {
7470
- var error;
7471
- pre();
7472
7490
 
7473
- try {
7474
- job();
7475
- } catch (e) {
7476
- error = Object(e);
7477
- } finally {
7478
- post();
7491
+ function createContextProvider(adapter) {
7492
+ var adapterContextToken = getAdapterToken(adapter);
7479
7493
 
7480
- if (!isUndefined$1(error)) {
7481
- addErrorComponentStack(vm, error);
7482
- var errorBoundaryVm = isNull(owner) ? undefined : getErrorBoundaryVM(owner);
7494
+ if (!isUndefined$1(adapterContextToken)) {
7495
+ throw new Error("Adapter already has a context provider.");
7496
+ }
7483
7497
 
7484
- if (isUndefined$1(errorBoundaryVm)) {
7485
- throw error; // eslint-disable-line no-unsafe-finally
7486
- }
7498
+ adapterContextToken = guid();
7499
+ setAdapterToken(adapter, adapterContextToken);
7500
+ var providers = new WeakSet();
7501
+ return function (elm, options) {
7502
+ if (providers.has(elm)) {
7503
+ throw new Error("Adapter was already installed on ".concat(elm, "."));
7504
+ }
7487
7505
 
7488
- resetComponentRoot(vm); // remove offenders
7506
+ providers.add(elm);
7507
+ var consumerConnectedCallback = options.consumerConnectedCallback,
7508
+ consumerDisconnectedCallback = options.consumerDisconnectedCallback;
7509
+ elm.addEventListener(adapterContextToken, function (evt) {
7510
+ var setNewContext = evt.setNewContext,
7511
+ setDisconnectedCallback = evt.setDisconnectedCallback;
7512
+ var consumer = {
7513
+ provide: function provide(newContext) {
7514
+ setNewContext(newContext);
7515
+ }
7516
+ };
7489
7517
 
7490
- logOperationStart(6
7491
- /* ErrorCallback */
7492
- , vm); // error boundaries must have an ErrorCallback
7518
+ var disconnectCallback = function disconnectCallback() {
7519
+ if (!isUndefined$1(consumerDisconnectedCallback)) {
7520
+ consumerDisconnectedCallback(consumer);
7521
+ }
7522
+ };
7493
7523
 
7494
- var errorCallback = errorBoundaryVm.def.errorCallback;
7495
- invokeComponentCallback(errorBoundaryVm, errorCallback, [error, error.wcStack]);
7496
- logOperationEnd(6
7497
- /* ErrorCallback */
7498
- , vm);
7499
- }
7500
- }
7524
+ setDisconnectedCallback(disconnectCallback);
7525
+ consumerConnectedCallback(consumer);
7526
+ evt.stopImmediatePropagation();
7527
+ });
7528
+ };
7501
7529
  }
7530
+ /*
7531
+ * Copyright (c) 2018, salesforce.com, inc.
7532
+ * All rights reserved.
7533
+ * SPDX-License-Identifier: MIT
7534
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7535
+ */
7502
7536
 
7503
- function forceRehydration(vm) {
7504
- // if we must reset the shadowRoot content and render the template
7505
- // from scratch on an active instance, the way to force the reset
7506
- // is by replacing the value of old template, which is used during
7507
- // to determine if the template has changed or not during the rendering
7508
- // process. If the template returned by render() is different from the
7509
- // previous stored template, the styles will be reset, along with the
7510
- // content of the shadowRoot, this way we can guarantee that all children
7511
- // elements will be throw away, and new instances will be created.
7512
- vm.cmpTemplate = function () {
7513
- return [];
7514
- };
7537
+ /**
7538
+ * EXPERIMENTAL: This function allows you to create a reactive readonly
7539
+ * membrane around any object value. This API is subject to change or
7540
+ * being removed.
7541
+ */
7515
7542
 
7516
- if (isFalse(vm.isDirty)) {
7517
- // forcing the vm to rehydrate in the next tick
7518
- markComponentAsDirty(vm);
7519
- scheduleRehydration(vm);
7543
+
7544
+ function readonly(obj) {
7545
+ if (process.env.NODE_ENV !== 'production') {
7546
+ // TODO [#1292]: Remove the readonly decorator
7547
+ if (arguments.length !== 1) {
7548
+ assert.fail('@readonly cannot be used as a decorator just yet, use it as a function with one argument to produce a readonly version of the provided value.');
7549
+ }
7520
7550
  }
7551
+
7552
+ return reactiveMembrane.getReadOnlyProxy(obj);
7521
7553
  }
7522
7554
  /*
7523
- * Copyright (c) 2018, salesforce.com, inc.
7555
+ * Copyright (c) 2022, salesforce.com, inc.
7524
7556
  * All rights reserved.
7525
7557
  * SPDX-License-Identifier: MIT
7526
7558
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7527
7559
  */
7560
+ // flag indicating if the hydration recovered from the DOM mismatch
7528
7561
 
7529
7562
 
7530
- var DeprecatedWiredElementHost = '$$DeprecatedWiredElementHostKey$$';
7531
- var DeprecatedWiredParamsMeta = '$$DeprecatedWiredParamsMetaKey$$';
7532
- var WireMetaMap = new Map();
7563
+ var hasMismatch = false;
7533
7564
 
7534
- var WireContextRegistrationEvent = /*#__PURE__*/function (_CustomEvent) {
7535
- _inherits(WireContextRegistrationEvent, _CustomEvent);
7565
+ function hydrateRoot(vm) {
7566
+ hasMismatch = false;
7567
+ runConnectedCallback(vm);
7568
+ hydrateVM(vm);
7536
7569
 
7537
- var _super6 = _createSuper(WireContextRegistrationEvent);
7570
+ if (hasMismatch) {
7571
+ logError('Hydration completed with errors.', vm);
7572
+ }
7573
+ }
7538
7574
 
7539
- function WireContextRegistrationEvent(adapterToken, _ref3) {
7540
- var _this5;
7575
+ function hydrateVM(vm) {
7576
+ var children = renderComponent(vm);
7577
+ vm.children = children;
7578
+ var parentNode = vm.renderRoot;
7579
+ hydrateChildren(getFirstChild$1(parentNode), children, parentNode, vm);
7580
+ runRenderedCallback(vm);
7581
+ }
7541
7582
 
7542
- var setNewContext = _ref3.setNewContext,
7543
- setDisconnectedCallback = _ref3.setDisconnectedCallback;
7583
+ function hydrateNode(node, vnode) {
7584
+ var hydratedNode;
7544
7585
 
7545
- _classCallCheck(this, WireContextRegistrationEvent);
7586
+ switch (vnode.type) {
7587
+ case 0
7588
+ /* Text */
7589
+ :
7590
+ hydratedNode = hydrateText(node, vnode);
7591
+ break;
7546
7592
 
7547
- _this5 = _super6.call(this, adapterToken, {
7548
- bubbles: true,
7549
- composed: true
7550
- });
7551
- defineProperties(_assertThisInitialized(_this5), {
7552
- setNewContext: {
7553
- value: setNewContext
7554
- },
7555
- setDisconnectedCallback: {
7556
- value: setDisconnectedCallback
7557
- }
7558
- });
7559
- return _this5;
7593
+ case 1
7594
+ /* Comment */
7595
+ :
7596
+ hydratedNode = hydrateComment(node, vnode);
7597
+ break;
7598
+
7599
+ case 2
7600
+ /* Element */
7601
+ :
7602
+ hydratedNode = hydrateElement(node, vnode);
7603
+ break;
7604
+
7605
+ case 3
7606
+ /* CustomElement */
7607
+ :
7608
+ hydratedNode = hydrateCustomElement(node, vnode);
7609
+ break;
7560
7610
  }
7561
7611
 
7562
- return _createClass(WireContextRegistrationEvent);
7563
- }( /*#__PURE__*/_wrapNativeSuper(CustomEvent));
7612
+ return nextSibling$1(hydratedNode);
7613
+ }
7564
7614
 
7565
- function createFieldDataCallback(vm, name) {
7566
- var cmpFields = vm.cmpFields;
7567
- return function (value) {
7568
- if (value !== vm.cmpFields[name]) {
7569
- // storing the value in the underlying storage
7570
- cmpFields[name] = value;
7571
- componentValueMutated(vm, name);
7615
+ function hydrateText(node, vnode) {
7616
+ var _a;
7617
+
7618
+ if (!hasCorrectNodeType(vnode, node, 3
7619
+ /* TEXT */
7620
+ )) {
7621
+ return handleMismatch(node, vnode);
7622
+ }
7623
+
7624
+ if (process.env.NODE_ENV !== 'production') {
7625
+ var nodeValue = getProperty$1(node, 'nodeValue');
7626
+
7627
+ if (nodeValue !== vnode.text && !(nodeValue === "\u200D" && vnode.text === '')) {
7628
+ logWarn('Hydration mismatch: text values do not match, will recover from the difference', vnode.owner);
7572
7629
  }
7573
- };
7574
- }
7630
+ }
7575
7631
 
7576
- function createMethodDataCallback(vm, method) {
7577
- return function (value) {
7578
- // dispatching new value into the wired method
7579
- runWithBoundaryProtection(vm, vm.owner, noop, function () {
7580
- // job
7581
- method.call(vm.component, value);
7582
- }, noop);
7583
- };
7632
+ setText$1(node, (_a = vnode.text) !== null && _a !== void 0 ? _a : null);
7633
+ vnode.elm = node;
7634
+ return node;
7584
7635
  }
7585
7636
 
7586
- function createConfigWatcher(component, configCallback, callbackWhenConfigIsReady) {
7587
- var hasPendingConfig = false; // creating the reactive observer for reactive params when needed
7588
-
7589
- var ro = new ReactiveObserver(function () {
7590
- if (hasPendingConfig === false) {
7591
- hasPendingConfig = true; // collect new config in the micro-task
7637
+ function hydrateComment(node, vnode) {
7638
+ var _a;
7592
7639
 
7593
- Promise.resolve().then(function () {
7594
- hasPendingConfig = false; // resetting current reactive params
7640
+ if (!hasCorrectNodeType(vnode, node, 8
7641
+ /* COMMENT */
7642
+ )) {
7643
+ return handleMismatch(node, vnode);
7644
+ }
7595
7645
 
7596
- ro.reset(); // dispatching a new config due to a change in the configuration
7646
+ if (process.env.NODE_ENV !== 'production') {
7647
+ var nodeValue = getProperty$1(node, 'nodeValue');
7597
7648
 
7598
- computeConfigAndUpdate();
7599
- });
7649
+ if (nodeValue !== vnode.text) {
7650
+ logWarn('Hydration mismatch: comment values do not match, will recover from the difference', vnode.owner);
7600
7651
  }
7601
- });
7652
+ }
7602
7653
 
7603
- var computeConfigAndUpdate = function computeConfigAndUpdate() {
7604
- var config;
7605
- ro.observe(function () {
7606
- return config = configCallback(component);
7607
- }); // eslint-disable-next-line lwc-internal/no-invalid-todo
7608
- // TODO: dev-mode validation of config based on the adapter.configSchema
7609
- // @ts-ignore it is assigned in the observe() callback
7654
+ setProperty$1(node, 'nodeValue', (_a = vnode.text) !== null && _a !== void 0 ? _a : null);
7655
+ vnode.elm = node;
7656
+ return node;
7657
+ }
7610
7658
 
7611
- callbackWhenConfigIsReady(config);
7612
- };
7659
+ function hydrateElement(elm, vnode) {
7660
+ if (!hasCorrectNodeType(vnode, elm, 1
7661
+ /* ELEMENT */
7662
+ ) || !isMatchingElement(vnode, elm)) {
7663
+ return handleMismatch(elm, vnode);
7664
+ }
7613
7665
 
7614
- return {
7615
- computeConfigAndUpdate: computeConfigAndUpdate,
7616
- ro: ro
7617
- };
7618
- }
7666
+ vnode.elm = elm;
7667
+ var context = vnode.data.context;
7668
+ var isDomManual = Boolean(!isUndefined$1(context) && !isUndefined$1(context.lwc) && context.lwc.dom === "manual"
7669
+ /* Manual */
7670
+ );
7619
7671
 
7620
- function createContextWatcher(vm, wireDef, callbackWhenContextIsReady) {
7621
- var adapter = wireDef.adapter;
7622
- var adapterContextToken = getAdapterToken(adapter);
7672
+ if (isDomManual) {
7673
+ // it may be that this element has lwc:inner-html, we need to diff and in case are the same,
7674
+ // remove the innerHTML from props so it reuses the existing dom elements.
7675
+ var props = vnode.data.props;
7623
7676
 
7624
- if (isUndefined$1(adapterContextToken)) {
7625
- return; // no provider found, nothing to be done
7677
+ if (!isUndefined$1(props) && !isUndefined$1(props.innerHTML)) {
7678
+ if (getProperty$1(elm, 'innerHTML') === props.innerHTML) {
7679
+ // Do a shallow clone since VNodeData may be shared across VNodes due to hoist optimization
7680
+ vnode.data = Object.assign(Object.assign({}, vnode.data), {
7681
+ props: cloneAndOmitKey(props, 'innerHTML')
7682
+ });
7683
+ } else {
7684
+ if (process.env.NODE_ENV !== 'production') {
7685
+ logWarn("Mismatch hydrating element <".concat(getProperty$1(elm, 'tagName').toLowerCase(), ">: innerHTML values do not match for element, will recover from the difference"), vnode.owner);
7686
+ }
7687
+ }
7688
+ }
7626
7689
  }
7627
7690
 
7628
- var elm = vm.elm,
7629
- _vm$context = vm.context,
7630
- wiredConnecting = _vm$context.wiredConnecting,
7631
- wiredDisconnecting = _vm$context.wiredDisconnecting; // waiting for the component to be connected to formally request the context via the token
7691
+ patchElementPropsAndAttrs(vnode);
7632
7692
 
7633
- ArrayPush$1.call(wiredConnecting, function () {
7634
- // This event is responsible for connecting the host element with another
7635
- // element in the composed path that is providing contextual data. The provider
7636
- // must be listening for a special dom event with the name corresponding to the value of
7637
- // `adapterContextToken`, which will remain secret and internal to this file only to
7638
- // guarantee that the linkage can be forged.
7639
- var contextRegistrationEvent = new WireContextRegistrationEvent(adapterContextToken, {
7640
- setNewContext: function setNewContext(newContext) {
7641
- // eslint-disable-next-line lwc-internal/no-invalid-todo
7642
- // TODO: dev-mode validation of config based on the adapter.contextSchema
7643
- callbackWhenContextIsReady(newContext);
7644
- },
7645
- setDisconnectedCallback: function setDisconnectedCallback(disconnectCallback) {
7646
- // adds this callback into the disconnect bucket so it gets disconnected from parent
7647
- // the the element hosting the wire is disconnected
7648
- ArrayPush$1.call(wiredDisconnecting, disconnectCallback);
7649
- }
7650
- });
7651
- dispatchEvent$1(elm, contextRegistrationEvent);
7652
- });
7693
+ if (!isDomManual) {
7694
+ hydrateChildren(getFirstChild$1(elm), vnode.children, elm, vnode.owner);
7695
+ }
7696
+
7697
+ return elm;
7653
7698
  }
7654
7699
 
7655
- function createConnector(vm, name, wireDef) {
7656
- var method = wireDef.method,
7657
- adapter = wireDef.adapter,
7658
- configCallback = wireDef.configCallback,
7659
- dynamic = wireDef.dynamic;
7660
- var dataCallback = isUndefined$1(method) ? createFieldDataCallback(vm, name) : createMethodDataCallback(vm, method);
7661
- var context;
7662
- var connector; // Workaround to pass the component element associated to this wire adapter instance.
7700
+ function hydrateCustomElement(elm, vnode) {
7701
+ if (!hasCorrectNodeType(vnode, elm, 1
7702
+ /* ELEMENT */
7703
+ ) || !isMatchingElement(vnode, elm)) {
7704
+ return handleMismatch(elm, vnode);
7705
+ }
7663
7706
 
7664
- defineProperty(dataCallback, DeprecatedWiredElementHost, {
7665
- value: vm.elm
7666
- });
7667
- defineProperty(dataCallback, DeprecatedWiredParamsMeta, {
7668
- value: dynamic
7707
+ var sel = vnode.sel,
7708
+ mode = vnode.mode,
7709
+ ctor = vnode.ctor,
7710
+ owner = vnode.owner;
7711
+ var vm = createVM(elm, ctor, {
7712
+ mode: mode,
7713
+ owner: owner,
7714
+ tagName: sel
7669
7715
  });
7670
- runWithBoundaryProtection(vm, vm, noop, function () {
7671
- // job
7672
- connector = new adapter(dataCallback);
7673
- }, noop);
7716
+ vnode.elm = elm;
7717
+ vnode.vm = vm;
7718
+ allocateChildren(vnode, vm);
7719
+ patchElementPropsAndAttrs(vnode); // Insert hook section:
7674
7720
 
7675
- var updateConnectorConfig = function updateConnectorConfig(config) {
7676
- // every time the config is recomputed due to tracking,
7677
- // this callback will be invoked with the new computed config
7678
- runWithBoundaryProtection(vm, vm, noop, function () {
7679
- // job
7680
- connector.update(config, context);
7681
- }, noop);
7682
- }; // Computes the current wire config and calls the update method on the wire adapter.
7683
- // If it has params, we will need to observe changes in the next tick.
7721
+ if (process.env.NODE_ENV !== 'production') {
7722
+ assert.isTrue(vm.state === 0
7723
+ /* created */
7724
+ , "".concat(vm, " cannot be recycled."));
7725
+ }
7684
7726
 
7727
+ runConnectedCallback(vm);
7685
7728
 
7686
- var _createConfigWatcher = createConfigWatcher(vm.component, configCallback, updateConnectorConfig),
7687
- computeConfigAndUpdate = _createConfigWatcher.computeConfigAndUpdate,
7688
- ro = _createConfigWatcher.ro; // if the adapter needs contextualization, we need to watch for new context and push it alongside the config
7729
+ if (vm.renderMode !== 0
7730
+ /* Light */
7731
+ ) {
7732
+ // VM is not rendering in Light DOM, we can proceed and hydrate the slotted content.
7733
+ // Note: for Light DOM, this is handled while hydrating the VM
7734
+ hydrateChildren(getFirstChild$1(elm), vnode.children, elm, vm);
7735
+ }
7689
7736
 
7737
+ hydrateVM(vm);
7738
+ return elm;
7739
+ }
7690
7740
 
7691
- if (!isUndefined$1(adapter.contextSchema)) {
7692
- createContextWatcher(vm, wireDef, function (newContext) {
7693
- // every time the context is pushed into this component,
7694
- // this callback will be invoked with the new computed context
7695
- if (context !== newContext) {
7696
- context = newContext; // Note: when new context arrives, the config will be recomputed and pushed along side the new
7697
- // context, this is to preserve the identity characteristics, config should not have identity
7698
- // (ever), while context can have identity
7741
+ function hydrateChildren(node, children, parentNode, owner) {
7742
+ var hasWarned = false;
7743
+ var nextNode = node;
7744
+ var anchor = null;
7745
+
7746
+ for (var _i29 = 0; _i29 < children.length; _i29++) {
7747
+ var childVnode = children[_i29];
7748
+
7749
+ if (!isNull(childVnode)) {
7750
+ if (nextNode) {
7751
+ nextNode = hydrateNode(nextNode, childVnode);
7752
+ anchor = childVnode.elm;
7753
+ } else {
7754
+ hasMismatch = true;
7699
7755
 
7700
- if (vm.state === 1
7701
- /* connected */
7702
- ) {
7703
- computeConfigAndUpdate();
7756
+ if (process.env.NODE_ENV !== 'production') {
7757
+ if (!hasWarned) {
7758
+ hasWarned = true;
7759
+ logError("Hydration mismatch: incorrect number of rendered nodes. Client produced more nodes than the server.", owner);
7760
+ }
7704
7761
  }
7762
+
7763
+ mount(childVnode, parentNode, anchor);
7764
+ anchor = childVnode.elm;
7705
7765
  }
7706
- });
7766
+ }
7707
7767
  }
7708
7768
 
7709
- return {
7710
- // @ts-ignore the boundary protection executes sync, connector is always defined
7711
- connector: connector,
7712
- computeConfigAndUpdate: computeConfigAndUpdate,
7713
- resetConfigWatcher: function resetConfigWatcher() {
7714
- return ro.reset();
7769
+ if (nextNode) {
7770
+ hasMismatch = true;
7771
+
7772
+ if (process.env.NODE_ENV !== 'production') {
7773
+ if (!hasWarned) {
7774
+ logError("Hydration mismatch: incorrect number of rendered nodes. Server rendered more nodes than the client.", owner);
7775
+ }
7715
7776
  }
7716
- };
7777
+
7778
+ do {
7779
+ var current = nextNode;
7780
+ nextNode = nextSibling$1(nextNode);
7781
+ removeNode(current, parentNode);
7782
+ } while (nextNode);
7783
+ }
7717
7784
  }
7718
7785
 
7719
- var AdapterToTokenMap = new Map();
7786
+ function handleMismatch(node, vnode, msg) {
7787
+ hasMismatch = true;
7720
7788
 
7721
- function getAdapterToken(adapter) {
7722
- return AdapterToTokenMap.get(adapter);
7789
+ if (!isUndefined$1(msg)) {
7790
+ if (process.env.NODE_ENV !== 'production') {
7791
+ logError(msg, vnode.owner);
7792
+ }
7793
+ }
7794
+
7795
+ var parentNode = getProperty$1(node, 'parentNode');
7796
+ mount(vnode, parentNode, node);
7797
+ removeNode(node, parentNode);
7798
+ return vnode.elm;
7723
7799
  }
7724
7800
 
7725
- function setAdapterToken(adapter, token) {
7726
- AdapterToTokenMap.set(adapter, token);
7801
+ function patchElementPropsAndAttrs(vnode) {
7802
+ applyEventListeners(vnode);
7803
+ patchProps(null, vnode);
7727
7804
  }
7728
7805
 
7729
- function storeWiredMethodMeta(descriptor, adapter, configCallback, dynamic) {
7730
- // support for callable adapters
7731
- if (adapter.adapter) {
7732
- adapter = adapter.adapter;
7806
+ function hasCorrectNodeType(vnode, node, nodeType) {
7807
+ if (getProperty$1(node, 'nodeType') !== nodeType) {
7808
+ if (process.env.NODE_ENV !== 'production') {
7809
+ logError('Hydration mismatch: incorrect node type received', vnode.owner);
7810
+ }
7811
+
7812
+ return false;
7733
7813
  }
7734
7814
 
7735
- var method = descriptor.value;
7736
- var def = {
7737
- adapter: adapter,
7738
- method: method,
7739
- configCallback: configCallback,
7740
- dynamic: dynamic
7741
- };
7742
- WireMetaMap.set(descriptor, def);
7815
+ return true;
7743
7816
  }
7744
7817
 
7745
- function storeWiredFieldMeta(descriptor, adapter, configCallback, dynamic) {
7746
- // support for callable adapters
7747
- if (adapter.adapter) {
7748
- adapter = adapter.adapter;
7818
+ function isMatchingElement(vnode, elm) {
7819
+ if (vnode.sel.toLowerCase() !== getProperty$1(elm, 'tagName').toLowerCase()) {
7820
+ if (process.env.NODE_ENV !== 'production') {
7821
+ logError("Hydration mismatch: expecting element with tag \"".concat(vnode.sel.toLowerCase(), "\" but found \"").concat(getProperty$1(elm, 'tagName').toLowerCase(), "\"."), vnode.owner);
7822
+ }
7823
+
7824
+ return false;
7749
7825
  }
7750
7826
 
7751
- var def = {
7752
- adapter: adapter,
7753
- configCallback: configCallback,
7754
- dynamic: dynamic
7755
- };
7756
- WireMetaMap.set(descriptor, def);
7827
+ var hasIncompatibleAttrs = validateAttrs(vnode, elm);
7828
+ var hasIncompatibleClass = validateClassAttr(vnode, elm);
7829
+ var hasIncompatibleStyle = validateStyleAttr(vnode, elm);
7830
+ return hasIncompatibleAttrs && hasIncompatibleClass && hasIncompatibleStyle;
7757
7831
  }
7758
7832
 
7759
- function installWireAdapters(vm) {
7760
- var context = vm.context,
7761
- wire = vm.def.wire;
7762
- var wiredConnecting = context.wiredConnecting = [];
7763
- var wiredDisconnecting = context.wiredDisconnecting = [];
7764
-
7765
- for (var fieldNameOrMethod in wire) {
7766
- var descriptor = wire[fieldNameOrMethod];
7767
- var wireDef = WireMetaMap.get(descriptor);
7768
-
7769
- if (process.env.NODE_ENV !== 'production') {
7770
- assert.invariant(wireDef, "Internal Error: invalid wire definition found.");
7771
- }
7833
+ function validateAttrs(vnode, elm) {
7834
+ var _vnode$data$attrs = vnode.data.attrs,
7835
+ attrs = _vnode$data$attrs === void 0 ? {} : _vnode$data$attrs;
7836
+ var nodesAreCompatible = true; // Validate attributes, though we could always recovery from those by running the update mods.
7837
+ // Note: intentionally ONLY matching vnodes.attrs to elm.attrs, in case SSR is adding extra attributes.
7772
7838
 
7773
- if (!isUndefined$1(wireDef)) {
7774
- (function () {
7775
- var _createConnector = createConnector(vm, fieldNameOrMethod, wireDef),
7776
- connector = _createConnector.connector,
7777
- computeConfigAndUpdate = _createConnector.computeConfigAndUpdate,
7778
- resetConfigWatcher = _createConnector.resetConfigWatcher;
7839
+ for (var _i30 = 0, _Object$entries = Object.entries(attrs); _i30 < _Object$entries.length; _i30++) {
7840
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i30], 2),
7841
+ attrName = _Object$entries$_i[0],
7842
+ attrValue = _Object$entries$_i[1];
7779
7843
 
7780
- var hasDynamicParams = wireDef.dynamic.length > 0;
7781
- ArrayPush$1.call(wiredConnecting, function () {
7782
- connector.connect();
7844
+ var elmAttrValue = getAttribute$1(elm, attrName);
7783
7845
 
7784
- if (!runtimeFlags.ENABLE_WIRE_SYNC_EMIT) {
7785
- if (hasDynamicParams) {
7786
- Promise.resolve().then(computeConfigAndUpdate);
7787
- return;
7788
- }
7789
- }
7846
+ if (String(attrValue) !== elmAttrValue) {
7847
+ if (process.env.NODE_ENV !== 'production') {
7848
+ logError("Mismatch hydrating element <".concat(getProperty$1(elm, 'tagName').toLowerCase(), ">: attribute \"").concat(attrName, "\" has different values, expected \"").concat(attrValue, "\" but found \"").concat(elmAttrValue, "\""), vnode.owner);
7849
+ }
7790
7850
 
7791
- computeConfigAndUpdate();
7792
- });
7793
- ArrayPush$1.call(wiredDisconnecting, function () {
7794
- connector.disconnect();
7795
- resetConfigWatcher();
7796
- });
7797
- })();
7851
+ nodesAreCompatible = false;
7798
7852
  }
7799
7853
  }
7854
+
7855
+ return nodesAreCompatible;
7800
7856
  }
7801
7857
 
7802
- function connectWireAdapters(vm) {
7803
- var wiredConnecting = vm.context.wiredConnecting;
7858
+ function validateClassAttr(vnode, elm) {
7859
+ var _vnode$data = vnode.data,
7860
+ className = _vnode$data.className,
7861
+ classMap = _vnode$data.classMap;
7862
+ var nodesAreCompatible = true;
7863
+ var vnodeClassName;
7804
7864
 
7805
- for (var _i30 = 0, _len11 = wiredConnecting.length; _i30 < _len11; _i30 += 1) {
7806
- wiredConnecting[_i30]();
7807
- }
7808
- }
7865
+ if (!isUndefined$1(className) && String(className) !== getProperty$1(elm, 'className')) {
7866
+ // className is used when class is bound to an expr.
7867
+ nodesAreCompatible = false;
7868
+ vnodeClassName = className;
7869
+ } else if (!isUndefined$1(classMap)) {
7870
+ // classMap is used when class is set to static value.
7871
+ var classList = getClassList$1(elm);
7872
+ var computedClassName = ''; // all classes from the vnode should be in the element.classList
7809
7873
 
7810
- function disconnectWireAdapters(vm) {
7811
- var wiredDisconnecting = vm.context.wiredDisconnecting;
7812
- runWithBoundaryProtection(vm, vm, noop, function () {
7813
- // job
7814
- for (var _i31 = 0, _len12 = wiredDisconnecting.length; _i31 < _len12; _i31 += 1) {
7815
- wiredDisconnecting[_i31]();
7816
- }
7817
- }, noop);
7818
- }
7819
- /*
7820
- * Copyright (c) 2018, salesforce.com, inc.
7821
- * All rights reserved.
7822
- * SPDX-License-Identifier: MIT
7823
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7824
- */
7825
- // this is lwc internal implementation
7874
+ for (var name in classMap) {
7875
+ computedClassName += ' ' + name;
7826
7876
 
7877
+ if (!classList.contains(name)) {
7878
+ nodesAreCompatible = false;
7879
+ }
7880
+ }
7827
7881
 
7828
- function createContextProvider(adapter) {
7829
- var adapterContextToken = getAdapterToken(adapter);
7882
+ vnodeClassName = computedClassName.trim();
7830
7883
 
7831
- if (!isUndefined$1(adapterContextToken)) {
7832
- throw new Error("Adapter already has a context provider.");
7884
+ if (classList.length > keys(classMap).length) {
7885
+ nodesAreCompatible = false;
7886
+ }
7833
7887
  }
7834
7888
 
7835
- adapterContextToken = guid();
7836
- setAdapterToken(adapter, adapterContextToken);
7837
- var providers = new WeakSet();
7838
- return function (elm, options) {
7839
- if (providers.has(elm)) {
7840
- throw new Error("Adapter was already installed on ".concat(elm, "."));
7889
+ if (!nodesAreCompatible) {
7890
+ if (process.env.NODE_ENV !== 'production') {
7891
+ logError("Mismatch hydrating element <".concat(getProperty$1(elm, 'tagName').toLowerCase(), ">: attribute \"class\" has different values, expected \"").concat(vnodeClassName, "\" but found \"").concat(getProperty$1(elm, 'className'), "\""), vnode.owner);
7841
7892
  }
7893
+ }
7842
7894
 
7843
- providers.add(elm);
7844
- var consumerConnectedCallback = options.consumerConnectedCallback,
7845
- consumerDisconnectedCallback = options.consumerDisconnectedCallback;
7846
- elm.addEventListener(adapterContextToken, function (evt) {
7847
- var setNewContext = evt.setNewContext,
7848
- setDisconnectedCallback = evt.setDisconnectedCallback;
7849
- var consumer = {
7850
- provide: function provide(newContext) {
7851
- setNewContext(newContext);
7852
- }
7853
- };
7895
+ return nodesAreCompatible;
7896
+ }
7854
7897
 
7855
- var disconnectCallback = function disconnectCallback() {
7856
- if (!isUndefined$1(consumerDisconnectedCallback)) {
7857
- consumerDisconnectedCallback(consumer);
7858
- }
7859
- };
7898
+ function validateStyleAttr(vnode, elm) {
7899
+ var _vnode$data2 = vnode.data,
7900
+ style = _vnode$data2.style,
7901
+ styleDecls = _vnode$data2.styleDecls;
7902
+ var elmStyle = getAttribute$1(elm, 'style') || '';
7903
+ var vnodeStyle;
7904
+ var nodesAreCompatible = true;
7860
7905
 
7861
- setDisconnectedCallback(disconnectCallback);
7862
- consumerConnectedCallback(consumer);
7863
- evt.stopImmediatePropagation();
7864
- });
7865
- };
7866
- }
7867
- /*
7868
- * Copyright (c) 2018, salesforce.com, inc.
7869
- * All rights reserved.
7870
- * SPDX-License-Identifier: MIT
7871
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7872
- */
7906
+ if (!isUndefined$1(style) && style !== elmStyle) {
7907
+ nodesAreCompatible = false;
7908
+ vnodeStyle = style;
7909
+ } else if (!isUndefined$1(styleDecls)) {
7910
+ var parsedVnodeStyle = parseStyleText(elmStyle);
7911
+ var expectedStyle = []; // styleMap is used when style is set to static value.
7873
7912
 
7874
- /**
7875
- * EXPERIMENTAL: This function allows you to create a reactive readonly
7876
- * membrane around any object value. This API is subject to change or
7877
- * being removed.
7878
- */
7913
+ for (var _i31 = 0, n = styleDecls.length; _i31 < n; _i31++) {
7914
+ var _styleDecls$_i2 = _slicedToArray(styleDecls[_i31], 3),
7915
+ prop = _styleDecls$_i2[0],
7916
+ value = _styleDecls$_i2[1],
7917
+ important = _styleDecls$_i2[2];
7879
7918
 
7919
+ expectedStyle.push("".concat(prop, ": ").concat(value + (important ? ' important!' : '')));
7920
+ var parsedPropValue = parsedVnodeStyle[prop];
7880
7921
 
7881
- function readonly(obj) {
7882
- if (process.env.NODE_ENV !== 'production') {
7883
- // TODO [#1292]: Remove the readonly decorator
7884
- if (arguments.length !== 1) {
7885
- assert.fail('@readonly cannot be used as a decorator just yet, use it as a function with one argument to produce a readonly version of the provided value.');
7922
+ if (isUndefined$1(parsedPropValue)) {
7923
+ nodesAreCompatible = false;
7924
+ } else if (!parsedPropValue.startsWith(value)) {
7925
+ nodesAreCompatible = false;
7926
+ } else if (important && !parsedPropValue.endsWith('!important')) {
7927
+ nodesAreCompatible = false;
7928
+ }
7886
7929
  }
7930
+
7931
+ if (keys(parsedVnodeStyle).length > styleDecls.length) {
7932
+ nodesAreCompatible = false;
7933
+ }
7934
+
7935
+ vnodeStyle = ArrayJoin.call(expectedStyle, ';');
7887
7936
  }
7888
7937
 
7889
- return reactiveMembrane.getReadOnlyProxy(obj);
7938
+ if (!nodesAreCompatible) {
7939
+ if (process.env.NODE_ENV !== 'production') {
7940
+ logError("Mismatch hydrating element <".concat(getProperty$1(elm, 'tagName').toLowerCase(), ">: attribute \"style\" has different values, expected \"").concat(vnodeStyle, "\" but found \"").concat(elmStyle, "\"."), vnode.owner);
7941
+ }
7942
+ }
7943
+
7944
+ return nodesAreCompatible;
7890
7945
  }
7891
7946
  /*
7892
7947
  * Copyright (c) 2018, salesforce.com, inc.
@@ -7903,7 +7958,7 @@ var LWC = (function (exports) {
7903
7958
  hooksAreSet = true;
7904
7959
  setSanitizeHtmlContentHook(hooks.sanitizeHtmlContent);
7905
7960
  }
7906
- /* version: 2.11.0 */
7961
+ /* version: 2.12.0 */
7907
7962
 
7908
7963
  /*
7909
7964
  * Copyright (c) 2018, salesforce.com, inc.
@@ -8318,7 +8373,7 @@ var LWC = (function (exports) {
8318
8373
  }
8319
8374
 
8320
8375
  function createVMWithProps(element, Ctor, props) {
8321
- createVM(element, Ctor, {
8376
+ var vm = createVM(element, Ctor, {
8322
8377
  mode: 'open',
8323
8378
  owner: null,
8324
8379
  tagName: element.tagName.toLowerCase()
@@ -8331,6 +8386,8 @@ var LWC = (function (exports) {
8331
8386
 
8332
8387
  element[key] = value;
8333
8388
  }
8389
+
8390
+ return vm;
8334
8391
  }
8335
8392
 
8336
8393
  function hydrateComponent(element, Ctor) {
@@ -8358,8 +8415,8 @@ var LWC = (function (exports) {
8358
8415
  // Let the renderer know we are hydrating, so it does not replace the existing shadowRoot
8359
8416
  // and uses the same algo to create the stylesheets as in SSR.
8360
8417
  setIsHydrating(true);
8361
- createVMWithProps(element, Ctor, props);
8362
- hydrateRootElement(element); // set it back since now we finished hydration.
8418
+ var vm = createVMWithProps(element, Ctor, props);
8419
+ hydrateRoot(vm); // set it back since now we finished hydration.
8363
8420
 
8364
8421
  setIsHydrating(false);
8365
8422
  } catch (e) {
@@ -8681,7 +8738,7 @@ var LWC = (function (exports) {
8681
8738
  });
8682
8739
  freeze(LightningElement);
8683
8740
  seal(LightningElement.prototype);
8684
- /* version: 2.11.0 */
8741
+ /* version: 2.12.0 */
8685
8742
 
8686
8743
  exports.LightningElement = LightningElement;
8687
8744
  exports.__unstable__ProfilerControl = profilerControl;