lwc 2.10.0 → 2.11.3

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