lwc 2.11.0 → 2.12.0

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