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