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