lwc 2.11.0 → 2.11.4

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