lwc 2.11.1 → 2.11.5

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